Answer to Question #182445 in C++ for P. Gokul

Question #182445

Develop a C++ programs on BANKING SYSTEM have Customer class with name, address and phoneno. Create derived class account class with data members like account number, name, deposit, withdraw amount and type of account. A customer can deposit and withdraw amount in his account. Develop a C++ program to display the details of a customer and the remaining balance amount. [Note: Use virtual function]


1
Expert's answer
2021-04-18T05:31:37-0400
#include <stdio.h>
using namespace std;


#define CREDIT	1
#define DEBIT	0
#define BAL_CHECK	3
#define NO_OF_CUST	5
struct Customer
{
	string Name;
	string Address;
	string PhoneNo;
	int AccountNo;		
	float Balance;	
};
struct Customer C[NO_OF_CUST];


class AccountInfo
{
	public:
		void AccountOp(int n, float a, int t)
		{
			float Bal;
			if(t==CREDIT) 
			{
				C[n].Balance = C[n].Balance + a;
			}
			if(t==DEBIT)			
			{
				if(a <=C[n].Balance)  C[n].Balance = C[n].Balance-a;
				else		cout<<"\nNot sufficient Balance";
			} 	 
		}
};
 
main(void)
{
	class AccountInfo A;
	int Flag=1,k=0,AN,n;
	float Cr,Db,Balance,Check;
	
	for(n=0;n<NO_OF_CUST;n++) A.AccountOp(n,0,CREDIT);
	while(Flag)
	{
		cout<<"\n\n\nPress 1 to add a new customer";
		cout<<"\nPress 2 to Credit";
		cout<<"\nPress 3 to Debit";
		cout<<"\nPress 4 to check Balance";
		cout<<"\nPress 0 to QUIT";		
		cout<<"\n\nEnter Choice (0 to 4): "; cin>>Flag;
		while(Flag<0 || Flag>4) {cout<<"\n\nEnter Choice (0 to 4): "; cin>>Flag;}
		if(Flag==1)
		{
			cout<<"\n\nEnter Name      : "; cin>>C[k].Name;
			cout<<"\nEnter Address   : "; cin>>C[k].Address;
			cout<<"\nEnter Phone No. : "; cin>>C[k].PhoneNo;
			C[k].AccountNo=k+1;
			cout<<"\nAccount No.     : "<<C[k].AccountNo;
			k=k+1;
			cout<<"\n\tCongratulations! New Customer added successfully.";
		}
		
		if(Flag==2)
		{
			cout<<"\n\nEnter Account No. : "; cin>>AN;
			cout<<"\nEnter Amount to be Credit: "; cin>>Cr;
			Check=0;
			for(n=0;n<k;n++)
			{
				if(AN == C[n].AccountNo) {Check=1; A.AccountOp(AN,Cr,CREDIT);}
			}
			if(Check==0) cout<<"\n\nAcoount No. "<<AN<<" could not be found.";
			if(Check==1) 
			{
				cout<<"\n\nAmount credit to your account successfully.";
				cout<<"\n\nUpdated Balance:";
				cout<<"\nCustomer Name: "<<C[AN].Name;
				cout<<"\nAccount No.  : "<<C[AN].AccountNo;
				cout<<"\nAddress      : "<<C[AN].Address;
				cout<<"\nPhone No.    : "<<C[AN].PhoneNo;
				cout<<"\nNew Balance  : "<<C[AN].Balance;
			}
		}
		if(Flag==3)
		{
			cout<<"\n\nEnter Account No. : "; cin>>AN;
			cout<<"\nEnter Amount to be Debit: "; cin>>Db;
			Check=0;
			for(n=0;n<k;n++)
			{
				if(AN == C[n].AccountNo) {Check=1; A.AccountOp(AN,Db,DEBIT);}
			}
			if(Check==0) cout<<"\n\nAcoount No. "<<AN<<" could not be found.";
			if(Check==1) 
			{
				cout<<"\n\nAmount debited from your account successfully.";
				cout<<"\n\nUpdated Balance:";
				cout<<"\nCustomer Name: "<<C[AN].Name;
				cout<<"\nAccount No.  : "<<C[AN].AccountNo;
				cout<<"\nAddress      : "<<C[AN].Address;
				cout<<"\nPhone No.    : "<<C[AN].PhoneNo;
				cout<<"\nNew Balance  : "<<C[AN].Balance;
			}
		}
		if(Flag==4)
		{
			cout<<"\n\nEnter Account No. : "; cin>>AN;
			Check=0;
			for(n=0;n<k;n++)
			{
				if(AN == C[n].AccountNo) Check=1; 
			}
			if(Check==0) cout<<"\n\nAcoount No. "<<AN<<" could not be found.";
			if(Check==1) 
			{
				cout<<"\n\nAmount Balance:";
				cout<<"\n\nUpdated Balance:";
				cout<<"\nCustomer Name: "<<C[AN].Name;
				cout<<"\nAccount No.  : "<<C[AN].AccountNo;
				cout<<"\nAddress      : "<<C[AN].Address;
				cout<<"\nPhone No.    : "<<C[AN].PhoneNo;
				cout<<"\nNew Balance  : "<<C[AN].Balance;
			}
		}
		
	}
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS