Thanx medievalelks problem done but only for single account.If I create two or more accounts,then function(details) in my code show the last entry.I know array should be used here but how?I dont want to use linked list.Here is my code for single account.
Code:
# include<iostream>
# include<string.h>
using namespace std;
int choice;
class bank{
private:
int age,balance,accountnumber,amount;
string name,occupation,address;
static int account;
public:
int accountno;
bank(){};
~bank(){};
void open();
void deposit();
void withdraw();
void details();
};
int bank::account=1000;
void bank::open()
{
cout<<"Enter name\n";
cin>>name;
cout<<"Enter age\n";
cin>>age;
cout<<"Enter occupation\n";
cin>>occupation;
cout<<"Enter address\n";
cin>>address;
do{
cout<<"Enter balance to start account\n";
cin>>balance;
}
while(balance<1000);
accountno=++account;
cout<<"ACCOUNT NUMBER:"<<accountno<<endl;
}
void bank::deposit()
{
cout<<"Enter account number\n";
cin>>accountnumber;
if (accountnumber==accountno)
{
cout<<"Enter amount of balance to deposit\n";
cin>>amount;
balance=balance+amount;
}
else
cout<<"Invalid account number\n";
}
void bank::withdraw()
{
cout<<"Enter account number\n";
cin>>accountnumber;
if (accountnumber==accountno)
{
cout<<"Enter amount of balance to withdraw\n";
cin>>amount;
balance=balance-amount;
}
else
cout<<"Invalid account number\n";
}
void bank::details()
{
cout<<"Enter account number\n";
cin>>accountnumber;
if (accountnumber==accountno)
{
cout<<"NAME:"<<name<<endl;
cout<<"AGE:"<<age<<endl;
cout<<"OCCUPATION:"<<occupation<<endl;
cout<<"ADDRESS:"<<address<<endl;
cout<<"BALANCE:"<<balance<<endl;
}
else
cout<<"Invalid account number\n";
}
int main()
{
bank b;
start:
system("cls");
cout<<"What do you want to do\n";
cout<<"1.To open account\n";
cout<<"2.To deposit balance in account\n";
cout<<"3.To withdraw balance in account\n";
cout<<"4.To see details of account\n";
cout<<"5.Exit\n";
cout<<"Your choice\n";
cin>>choice;
switch (choice){
case 1:{b.open();
system("pause");
break;
};
case 2:{b.deposit();
system("pause");
break;
};
case 3:{b.withdraw();
system("pause");
break;
};
case 4:{b.details();
system("pause");
break;
};
case 5:{exit(0);
system("pause");
break;
};
default:cout<<"Invalid input\n";
};
goto start;
system("pause");
return 0;
}