Thursday, 13 September 2012

bank program using c++


#include<iostream>
using namespace std;
#include<conio.h>
#include<string.h>
struct bankaccount
{
       char m_name[20];
       int m_accno;
       char m_type[10];
       double m_balance;
       char m_pswd[10];
};
void initial_val(bankaccount *p);
void deposit(bankaccount *q);
void withdraw(bankaccount *r);
void display(bankaccount *s);
void initial_val(bankaccount *p)
{
       cout<<"\n\nName of the depositer: ";
       cout<<"\n************************************\n";
       cin>>p->m_name;
       cout<<"\nAccount No. : ";
       cout<<"\n************************************\n";
       cin>>p->m_accno;
       cout<<"\nType of the account (saving/current): ";
       cout<<"\n************************************\n";
       cin>>p->m_type;
       cout<<"\nBalance amount in the account : Rs ";
       cout<<"\n************************************\n";
       cin>>p->m_balance;
       cout<<"\nPassword: ";
       cout<<"\n************************************\n";
       cin>>p->m_pswd;
}
void deposit(bankaccount *q)
{
       double m;
       cout<<"\nAmount to be deposited: Rs ";
       cout<<"\n************************************\n";
       cin>>m;
       q->m_balance=q->m_balance+m;
       cout<<"\nYour current balance is: Rs "<<q->m_balance;
       cout<<"\n\n";
}
void withdraw(bankaccount *r)
{
       double n;
       char a[10];
       cout<<"\nEnter password: ";
       cout<<"\n************************************\n";
       cin>>a;
       if(strcmp(r->m_pswd,a)==0)
       {
              cout<<"\nAmount to be withdrawn: Rs ";
              cout<<"\n************************************\n";


              cin>>n;
              if(r->m_balance<=n)
              {
                     cout<<"Balance amount is less ==> amount cannot be withdrawn\n";
                     cout<<"\n************************************\n";
              }
              else
              {
                     r->m_balance=r->m_balance-n;
                     cout<<"\nYour current balance is: Rs "<<r->m_balance;
                     cout<<"\n\n";
              }
       }
       else
       {
              cout<<"\nINVALID PASSWORD !!!\n";
              cout<<"\n************************************\n";
       }
}
void display(bankaccount *s)
{
       char b[10];
       cout<<"\nEnter password: ";
       cout<<"\n************************************\n";
       cin>>b;
       if(strcmp(s->m_pswd,b)==0)
       {
              cout<<"\n\n\nName of the depositer: "<<s->m_name;
              cout<<"\n\nBalance amount in the account : "<<s->m_balance;
              cout<<"\n\n";
       }
       else
       {
              cout<<"\nINVALID PASSWORD !!!\n";
              cout<<"\n************************************\n";
       }
}
void main()
{
       bankaccount b;
       int i,c;
       cout<<"\n* This is your bank account *\n";
       cout<<"\n************************************\n";
       cout<<"\n Enter details";
       cout<<"\n************************************\n";
       initial_val(&b);
       while(1)
       {
              cout<<"\n1. Deposit\n"<<"2.Withdraw\n"<<"3.Display\n"<<"4. Exit\n";
              cout<<"\n************************************\n";
              cout<<"\nEnter your choice: ";
              cin>>c;
              switch(c)
              {
              case 1:deposit(&b);
                     break;
              case 2:withdraw(&b);
                     break;
              case 3:display(&b);
                     break;
              case 4:exit(0);
              default:cout<<"\n**INVALID**";
              break;
       }
       }
       getch();
}

Wednesday, 12 September 2012

finding volume using function overloading


#include<iostream>
using namespace std;
#include<conio.h>
#define pi 3.142

void vol(int);
void vol(float, float);
void vol(float);
void main()
{
int ch,s;
float r,h,rad;
do
{
cout<<"----MENU----\n";
cout<<"1. Cube\n";
cout<<"2. Sphere\n";
cout<<"3. Cylinder \n";
cout<<"4. Exit \n";
cout<<"------------\n";
cout<<"Make a choice: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter side of cube: ";
cin>>s;
vol(s);
break;
case 2:
cout<<"Enter radius of sphere: ";
cin>>r;
vol(r);
break;
case 3:
cout<<"Enter radius of cylinder: ";
cin>>rad;
cout<<"Enter height of cylinder: ";
cin>>h;
vol(rad,h);
break;
case 4:
exit(0);
default:
cout<<"Invalid Choice \n";
break;
}
}
while(ch!=4);
getch();
}
void vol(int s)
{
int v1;
v1=s*s*s;
cout<<"The volume of cube= "<<v1<<"\n\n";
}
void vol(float r)
{
float v2;
v2=(4.0/3.0)*pi*r*r*r;
cout<<"The volume of sphere= "<<v2<<"\n\n";
}
void vol(float rad,float h)
{
float v3;
v3=pi*rad*rad*h;
cout<<"The volume of cylinder= "<<v3<<"\n\n";
}

finding area using function overloading


#include<iostream>
using namespace std;
#include<conio.h>
#define pi 3.142

void area(int);
void area(float);
void area(float, float);

void main()
{
int ch,s;
float l,b,r;
do
{
cout<<"-----MENU----- \n";
cout<<"1. Square \n";
cout<<"2. Circle \n";
cout<<"3. Rectangle \n";
cout<<"4. Exit \n\n";

cout<<"Make a choice: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter side of Square: ";
cin>>s;
area(s);
break;
case 2:
cout<<"Enter radius of Circle: ";
cin>>r;
area(r);
break;
case 3:
cout<<"Enter length of Rectangle: ";
cin>>l;
cout<<"Enter breadth of Rectangle: ";
cin>>b;
area(l,b);
break;
case 4:
exit(0);
default:
cout<<"Invalid Choice \n";
break;
}
}
while(ch!=4);
getch();
}
void area(int s)
{
int area;
area=s*s;
cout<<"The Area of Square= "<<area<<"\n";
}
void area(float r)
{
float area;
area=pi*r*r;
cout<<"The Area of Circle= "<<area<<"\n";
}
void area(float l, float b)
{
float area;
area=l*b;
cout<<"The Area of Rectangle= "<<area<<"\n";
}

function overloading comparing 2 intergers


#include<iostream>
using namespace std;
#include<conio.h>

void max(int,int);
void max(float,float);
void main()
{
int a,b;
float c,d;
cout<<"Enter Integer1: ";
cin>>a;
cout<<"Enter Integer2: ";
cin>>b;
cout<<"Enter Float1 :";
cin>>c;
cout<<"Enter Float2: :";
cin>>d;
max(a,b);
max(c,d);
getch();
}
void max(int a,int b)
{
if(a>b)
{
cout<<"The Greater Integer= "<<a<<"\n";
}
else
{
cout<<"The Greater Integer= "<<b<<"\n";
}
}
void max(float c,float d)
{
if(c>d)
{
cout<<"The Greater Float= "<<c<<"\n";
}
else
{
cout<<"The Greater Float= "<<d<<"\n";
}
}

Sunday, 9 September 2012

lagrange's interpolation


#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,i,j,n;
float ans,s,x[10],y[10],prodfunc,sum;

printf("How many terms of x and y Entered: ");
scanf("%d",&n);

printf("Enter values of x:- \n");
for(i=0;i<n;i++)
{
scanf("%f",&x[i]);
}
printf("Enter values of y:- \n");
for(j=0;j<n;j++)
{
scanf("%f",&y[j]);
}
sum=0;
printf("Enter the value of x which is to be found: ");
scanf("%f",&ans);

for(i=0;i<n;i++)
{
prodfunc=1;
for(j=0;j<n;j++)
{
if(i!=j)
{
prodfunc=(prodfunc*(ans-x[j]))/(x[i]-x[j]);
}
}
sum=sum+(y[i]*prodfunc);
}
printf("For y(%f)= %f",ans,sum);
getch();
}

Wednesday, 5 September 2012

bank program


#include<iostream>
using namespace std;
#include<conio.h>   
class vector
{
       char name[10],type[15];
       int ac_no;
       float amt;
public:
       void ival();
       void dep();
       void withd();
       void display();
};
void vector::ival()
{
       cout<<"enter name of the account holder :";
       cin>>name;
       cout<<"\nenter account number:";
       cin>>ac_no;
       cout<<"\nenter account type :";
       cin>>type;
       cout<<"\nenter balance :";
       cin>>amt;
      
}
void vector::dep()
{
       int j;
       cout<<"\nenter the amt to be deposited :";
       cin>>j;
       amt=amt+j;
}
void vector::withd()
{
       int s;
       cout<<"\nenter the amt to b withdrawn :";
       cin>>s;
       if(s>amt)
       {
              cout<<"\nmoney cant be withdrawn";
       }
       else
       {
              cout<<"\nmoney can be withdrawn";
              amt=amt-s;
              cout<<"\nbalance amt is :"<<amt;
             
       }
}
void vector::display()
{
       cout<<"name of the account holder :";
       cout<<name;
       cout<<"\n account number:";
       cout<<ac_no;
       cout<<"\n account type :";
       cout<<type;
       cout<<"\n balance :";
       cout<<amt;
}
void main()
{
       vector v;
       int k,m;
       do
       {
       cout<<"1. enter\n"<<"2. deposit\n"<<"3. withdrawal\n"<<"4. display\n";
       cin>>k;
       switch(k)
       {
       case 1:v.ival();
              break;
       case 2:v.dep();
              break;
       case 3:v.withd();
              break;
       case 4:v.display();
              break;
       default:cout<<"function does not exist";
              break;
       }
       cout<<"\npress 1 to continue";
       cin>>m;
       }
       while(m==1);
       getch();
}

sorting array using pointer


#include<iostream>
using std::cin;
using std::cout;
#include<conio.h>
void main()
{
            int *p,n,a[100],i,*j,t;
            cout<<"enter the no of elements: ";
            cin>>n;
            cout<<"\nenter the elements-\n";
            for(i=0;i<n;i++)
            {
                        cin>>a[i];
            }
            for(p=&a[0];p<=&a[n-1];p++)
            {
                        for(j=&a[0];j<=&a[n-1];j++)
                        {
                                    if(*p>*j)
                                    {
                                                t=*p;
                                                *p=*j;
                                                *j=t;
                                    }
                        }
            }
            cout<<"\nthe sorted elements are: ";
            for(p=&a[0];p<=&a[n-1];p++)
            {
                        cout<<*p<<" ";
            }
            getch();
}
           
Output:
enter the no of elements: 8

enter the elements-
-1 0 9 99 -45 5 6 3

the sorted elements are: 99 9 6 5 3 0 -1 -45

program to calculate the votes



//program to calculate the votes//
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
       int i,n,count[100],a=0,b=0,c=0,d=0,e=0,spoilt=0;
       cout<<"how many voters?";
       cin>>n;
       if(n<0)
       {
       cout<<"invalid";
       exit(0);
       }
       cout<<"the following is the list of the candidates\n";
       cout<<"1.CONGRESS.\n";
       cout<<"2.BJP.\n";
       cout<<"3.NCP.\n";
       cout<<"4.MGP.\n";
       cout<<"5.INDEPENDENT.\n";
       for(i=1;i<=n;i++)
       {
              cout<<"enter your vote, that is the respective no of ur candidate:";
              cin>>count[i];
              if (count[i]==1)
                     a++;
              else if(count[i]==2)
                     b++;
              else if(count[i]==3)
                     c++;
              else if(count[i]==4)
                     d++;
              else if(count[i]==5)
                     e++;
              else
                     spoilt++;

              cout<<"\n";
       }
        cout<<"the number of votes are:\n";
        cout<<"1.CONGRESS:"<<a<<"\n";
       cout<<"2.BJP:"<<b<<"\n";
       cout<<"3.NCP:"<<c<<"\n";
       cout<<"4.MGP:"<<d<<"\n";
       cout<<"5.INDEPENDENT:"<<e<<"\n";
       cout<<"spoilt ballot:"<<spoilt<<"\n";

       if(a>b && a>c && a>d && a>e)
              cout<<"the winner is: CONGERSS!!";
       else if(b>a && b>c && b>d && b>e)
              cout<<"the winner is:BJP!!";
       else if(c>a && c>b && c>d && c>e)
              cout<<"the winner is:NCP!!";
       else if(d>a && d>c && d>b && d>e)
              cout<<"the winner is:MGP!!";
       else if(e>a && e>c && e>d && e>b)
              cout<<"the winner is:INDEPENDENT!!";
else
cout<<"there is a tie";
getch();
}