Google Search

Saturday, October 24, 2015

Defined a class to represent a bank account with data member : name of the depositor,account number,type of account,balance and member functions : deposit_amount and withdraw_amount. show name and balance.Write a program to test this

‪#‎include‬<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
class bank_account
{
char name_of_the_depositor[25];
int account_number;
char type_of_account[15];
int balance;
int count;
public:
void cnt(void){count=0;}
void deposit_amount(void);
void withdraw_amount(char name,char acc,int w);
};
void bank_account::deposit_amount(void)
{
cout<<"\nEnter the name of the depositor : ";
fflush(stdin);
gets(name_of_the_depositor);
//cin>>name_of_the_depositor;
cout<<"\n\nEnter the account number : ";
cin>>account_number;
cout<<"\n\nType of account : ";
cin>>type_of_account;
cout<<"\n\nDeposit amount : ";
cin>>balance;
count++;
cout<<"\n";
cout<<"\nCONGRATULATION..!!Informations are saved.\n";
cout<<"\n\n\nDatabase : ";
cout<<"\n----------\n";
for(int i=0;i<count;i++)
{
cout<<"\nName : ";
cout<<name_of_the_depositor;
cout<<"\n\nAccount number : ";
cout<<account_number;
cout<<"\n\nType of account : ";
cout<<type_of_account;
cout<<"\n\nDeposited amount : ";
cout<<balance;
cout<<"\n\n";
}
}
/*void bank_account::withdraw_amount(char name,char acc,int w)
{
int i;
for(i=0;i<count;i++)
{
if((name_of_the_depositor[i]==name)&&(account_number[i]==acc))
{
balance[i]=balance[i]-w;
cout<<"\n\nName of the depositor : "<<name_of_the_depositor[i];
cout<<"\n\nAfter withdrawal,now the balance is : "<<balance[i];
}
cout<<"\n\n";
}
}*/
int main()
{
bank_account b[50];
//b.cnt();
int ch,num,acc,w,i;
char name;
clrscr();
while(ch!=0)
{
cout<<"\n*====================BANK DATABASE===================*\n";
cout<<"\n Press 1 to deposit amount";
cout<<"\n Press 2 to withdraw amount";
cout<<"\n Press 0 to exit from menu";
cout<<"\n\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\n\nEnter the following datas to deposit amount :";
cout<<"\n---------------------------------------------\n";
for(i=0;i<50;i++)
b[i].deposit_amount();
break;
case 2: cout<<"\n\n\nEnter the name & account no. to withdraw amount : ";
cout<<"\n-------------------------------------------------\n";
cout<<"\nEnter name : ";
cin>>name;
cout<<"\n\nEnter account number : ";
cin>>acc;
cout<<"\n\nEnter the amount you want to withdraw : ";
cin>>w;
cout<<"\n\n";
b[i].withdraw_amount(name,acc,w);
break;
case 0: cout<<"\n Exit";
break;
default: cout<<"\n Sorry.......Invalid choice.Try again";
}
}
return 0;
}

No comments:

Post a Comment