Create a base class Account (Acc_Holder_Name, Acc_Holder_Contact_No). Derive a two classes as Saving_Account(S_Acc_No., Balance) and Current_Account( C_Acc_No., Balance) from Account. Write a C++ menu driven program to perform following functions : i. Accept the details for ‘n’ account holders. ii. Display the details of ‘n’ account holders by adding interest amount where interest rate for Saving account is 5% of balance and interest rate for Current account is 1.5% of balance.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
#include<float.h>
//declaring classes
class cur;
class save;
class acc
{
protected:
char name[10]; //name=holder name , no=phone no
int no;
public:
void accept()
{
cout<<"Enter account holder name: ";
cin>>name;
cout<<endl;
cout<<"Enter account holder phone no: ";
cin>>no;
cout<<endl;
}
};
class save: public acc // inherit class save
{
protected:
float sum;
int sno,bal; //sno= saving account no , bal=balance
public:
void check()
{
cout<<"Enter saving account no: ";
cin>>sno;
cout<<"Enter saving acc balance: ";
cin>>bal;
sum=0;
sum=bal*(5/100);
sum=sum+bal;
}
void dis()
{
cout<<"\nsaving Account Holder name: "<<name<<"\nsaving Account Holder ph no: "<<no<<endl;
// cout<<<<"\t\t\t"<<no<<endl;
cout<<name<<" total saving acc balance is: "<<sum<<endl;
}
};
class cur: public acc // inherit class cur
{
protected:
float pn,su;
int ano,balance,b;
public:
void ac()
{
cout<<"enter current Account no: ";
cin>>ano;
cout<<"enter balance: ";
cin>>b;
su=0;
su=b*(15/100);
su=su+b;
}
void display()
{
cout<<"\ncurrent Account Holder name:"<<name<<"\ncurrent Account Holder ph no:"<<no<<endl;
cout<<name<<"\n total current acc balance is:"<<su<<endl;
}
};
void main()
{
int n1,n2,i,j,ch;
do
{
cout<<"1.Accept values"<<"\n2.display"<<"\n3.Exit"<<"\nchoose one: ";
cin>>ch;
switch(ch)
{
case 1:cout<<"Enter how many saving account holders: ";
cin>>n1;
cout<<"Enter how many current account holders: ";
cin>>n2;
cur c1[20]; // create instance of class cur
save s1[20]; // create instance of class save
for( i=0;i<n1;i++)
{
c1[i].accept();
c1[i].ac();
}
for( j=0;j<n2;j++)
{
s1[j].accept();
s1[j].check();
}
break;
case 2:for( i=0;i<n1;i++)
c1[i].display();
for( j=0;j<n2;j++)
s1[j].dis();
break;
}
}while(ch!=3);
}
0 Comments