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

Program Algorithm:
Step 1: Include the Header file.
Step 2: Create a forward declaration of a class.
Step 3: Create a new class that has certain member functions and methods.
Step 4: Create the class earlier defined in step 2 and Create it inherit from the class in step 2 using the resolution: operator
Step 5: Now create an object of the sun class and Create it call some methods you defined in step 2.

Program Code:
#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;
}

Sample Inputs and Outputs:
Enter customer name: Raja
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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: