Multiple
Constructors
#include
#include
class s
int a,b,c;
public:
s()
{
a=1;
b=2;
c=3;
}
s(int x,int y, int z)
{
a=x;
b=y;
c=z;
}
void print()
{
cout<""<
}
};
void main();
{
clrscr();
s k1,k2,k3;
sk4(7,8,9);
k1.print();
k2.print();
k3.print();
k4.print();
getch();
}
Output
1 2 3
1 2 3
7 8 9
Copy Constructor
#include
#include
class
k
{
float
m,n;
public:
k(float
x, float y)
m=x;
n=y;
}
k(k&obj)
{
m=obj.m;
n=obj.n;
}
void
display()
{
cout<<""<
}
};
void main()
{
clrscr();
k one(2.3,5.6);
k two(one);
k three(4.3,7.6);
k four(three);
one.display();
two.display();
three.display();
four.display();
getch();
}
Output
2.3 5.6
2.3 5.6
4.3 7.6
4.3 7.6
Bank Program
#include
#include
#include
class depositor
{
char deponame[30],actype[20];
int accno,dep;
double balance;
public:
depositor()
{
strcpy(deponame,’\0’)
balance=0;
}
void getdata()
{
cout<<"\t\t\tICICI Bank";
cout<<"\n======================================";
cout<<"\n Name of the depositor:
";
cin>>deponame;
cout<<"\n Account Number : ";
cin>>accno;
cout<<"\n Type of Account : ";
cin>>actype;
cout<<"\n Deposit amount : ";
cin>>dep;
balance=balance+dep;
}
void display()
{
cout<<"\n\t Balance Details:
";
cout<<"\n\t
==========================================";
cout<<"\n=========================================";
}
void withdraw()
{
double wdraw;
cout<<"\n\nEnter withdraw amount :
";
cin>>wdraw;
if(wdraw>balance)
{
cout<<"\n Not enough balance
………withdraw not possible";
}
else
{
balance=balance-wdraw;
}
}
};
void main()
{
depositor d1;
clrscr();
d1.getdata();
d1.display();
d1.withdraw();
d1.display();
getch();
}
Output
ICICI Bank
======================================================
Name of the depositor : Aruna
Account Number : 9457220012
Type of Account : Savings
Deposit Amount : 7000
Balance
Details
======================================================
Aruna 7000
======================================================
Enter
withdraw amount : 4000
Balance Details :
======================================================
Aruna 3000
======================================================
No comments:
Post a Comment