Define a class for a bank account that includes the following data member: Name of the depositor
Account Number
Type of Account
Balance Amount in the Account.
The class also contains the following member functions.
A constructor to assign initial values.
Deposit function to deposit some amount. It should accept the amount as parameter.
Withdraw function to withdraw an amount after checking the balance. It should accept the amount as
parameter.
Display function to display name and balance.
Answer :::
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class Bank
{
//Declaration of data members
public:
char name[20];
char account_type[20];
int account_number;
int balance;
//member functions of the class Bank
// initialize function to initialize data members
void initialize()
{
cout<<"\nEnter Account Holders Name:";
gets(name);
cout<<"\nEnter Account type:";
gets(account_type);
cout<<"\nEnter account number:";
cin>>account_number;
cout<<"\Enter balance to deposit:";
cin>>balance;
}
//deposit() function to deposit amount in account
void deposit()
{
int bal;
cout<<"\nEnter the amout to deposit:";
cin>>bal;
balance+=bal;
cout<<"\nAmount deposited successfuly\nYour New Balance:"<<balance;
}
//check() function to withdraw amount and check remaining balance
void check()
{
int bal;
cout<<"\nYour balance :"<<balance<<"\nEnter amount to withdraw:";
cin>>bal;
if(bal<=balance)
{
balance-=bal;
cout<<"\nRemaining Balance:"<<balance;
}
else
{
exit(0);
}
}
//display function to display user information
void display()
{
cout<<"\nName :";
puts(name);
cout<<"\nBalance :"<<balance;
}
};
void main()
{
int i;
clrscr();
//An array of objects of Bank class can be created to handle 10 customers and their data
//as Bank bk[10];
//Then run this array in loop to initialize and access it's data members
Bank bk;
bk.initialize();
cout<<"\n1. Your Information\n2. Deposit\n3. Withdraw\nEnter your choice\n";
cin>>i;
if(i==1)
{
bk.display();
}
else if(i==2)
{
bk.deposit();
}
else if(i==3)
{
bk.check();
}
getch();
}
good
ReplyDelete