C++ program single inheritance using banking system - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Thursday, August 31, 2017

C++ program single inheritance using banking system

Write a C++ program to illustrate the single inheritance using banking system as an example.


Sample Output and Input:

Enter customer name: Ajai
Enter account No: 123
Enter account type: Savings
Choose your choice
1) Deposit
2) withdraw
3) display Balance
4) Display with full details
5) Exit
Enter your Choice: 1
Enter the amount to Deposit 500
Enter your Choice: 1
3
Balance:- 510
Enter your Choice: 5


Program:

#include<iostream.h>
class sav_acct
class account
{
char cust_name[20];
int acc_no;
char acc_type[20];
public:
int get_accinfo()
{
cout<<"\n\nEnter customer name:-";
cin>>cust_name;
cout<<"\n\nEnter Account no:-";
cin>>acc_no;
cout<<"\n\nEnter Account type:-";
cin>>acc_type;
return 0;
}
int display_accinfo()
{
cout<<"\n\nCustomer Name:-"<<cust_name;
cout<<"\n\nAccount Number:-"<<acc_no;
cout<<"\n\nAccount Type:-"<<acc_type;
return 0;
}
};
class sav_acct:public account
{
static float savbal;
public:
int disp_savbal()
{
cout<<"\nBalance:-"<<savbal;
return 0;
}
int deposit_savbal()
{
float deposit,interest;
cout<<"\n Enter the amount to Deposit:-";
cin>>deposit;
savbal=savbal+deposit;
interest=(savbal*2)/100;
savbal=savbal+interest;
return 0;
}
void withdraw_savbal()
{
float withdraw;
cout<<"\nBalance:-"<<savbal;
cout<<"\nEnter amount to be withdrawn:-";
cin>>withdraw;
savbal-=withdraw;
if(withdraw>savbal)
{
cout<<"\n\nYou have to take permission for Bank overdraft Facility\n";
savbal+=withdraw;
}
else
cout<<"\nAfter withdrawl your Balance reveals:"<<savbal;
}
};
float sav_acct::savbal;
int main()
{
sav_acct s1;
int choice;
s1.get_accinfo();
while(1)
{
cout<<"\nchoose your choice\n";
cout<<"\n1)Deposit\n";
cout<<"\n2)Withdraw\n";
cout<<"\n3)Display Balance\n";
cout<<"\n4)Display with full details\n";
cout<<"\n5)Exit\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1:s1.deposit_savbal();
break;
case 2:s1.withdraw_savbal();
break;
case 3:s1.disp_savbal();
break;
case 4:s1.display_accinfo();
s1.disp_savbal();
break;
case 5:return(0);
default:cout<<"\n\nEntered choice is invalid";
}
}
return 0;

}

No comments:

Post a Comment