# include <iostream.h>
# include <string.h>
class Account
{
 private:
  int ID;
  char * Name;
  double Balance;
 public:
  Account();
  Account(int,const char * ,double);
  void Saving();
  int Withdraw();
  void ShowMe();
  int getID();
 
};

class Bank
{
 private:
  Account * account[50];
  int maxID;
  int accNum;
 public:
  Bank();
  void Append();
  void Delete();
  void Query();
};

Account::Account()
{
 ID = 0;
 strcpy(Name," ");
 Balance = 0;
}

Account::Account(int id,const char * name,double balance)
{
 ID = id;
 Name = new char[50];
 strcpy(Name,name);
 Balance = balance;
}

void Account::Saving()
{
 double number;
 cout<<"Please input saving number:";
 cin>>number;
 Balance = Balance + number;
 cout<<"Now the balance of your account is "<<Balance<<endl;
 return;
}

int Account::Withdraw()
{
 double number;
 cout<<"Please input withdraw number:";
 cin>>number;
 if(Balance<number)
 {
  cout<<"Sorry,now the balance of your accout is less than "<<number<<"."<<"So you can not withdraw!"<<endl;
  return 0;
 }
 Balance = Balance - number;
 cout<<"Now the balance of your account is"<<Balance<<endl;
 return  1;

}

void Account::ShowMe()
{
 cout<<"Account ID:"<<ID<<endl;
 cout<<"Name:"<<Name<<endl;
 cout<<"Balance:"<<Balance<<endl;
 return;
}

int Accout::getID()
{
 return ID;
}

Bank::Bank()
{
 for(int i=0;i<50;i++)
 {
  account[i] = NULL;
 }
 maxID = 0;
 accNum = 0;
}

void Bank::Append()
{
 if(accNum == 50)
 {
  cout<<"Sorry,the bank is full,so can not add new account!"<<endl;
  return;
 }
 int id;
 char * name = new char[50];
 double balance;
 cout<<"Please input the name of the account:";
 cin>>name;
 id = maxID;
 balance = 0;
 Account * acc = new Account(id,name,balance);
 account[accNum] = acc;
 cout<<"Append successful!"<<endl<<endl;
 account[accNum]->ShowMe();
 maxID++;
 accNum++;
 return;
}

void Bank::Delete()
{
 int ID;
 cout<<"Please input the accout ID that you want to delete:";
 cin>>ID;
 int flag = 1;
 int i = 0;
 while((i<accNum)&&(flag))
 {
  if(ID == account[i]->getID())
  {
   //flag = 0 indicate had found the accountID
   flag = 0;
  }
  else
  {
   i++;
  }
 }
 if(flag)
 {
  cout<<"The account does not exists!"<<endl<<endl;
  return;  
 }
 for(int j=i;j<accNum;j++)
 {
  account[j] = account[j+1];
 }
 delete account[accNum-1];
 accNum--;
 cout<<"Delete successful!"<<endl<<endl;
 return;
}

void Bank::Query()
{
 int ID;
 cout<<"Please input the account ID that you want to query:";
 cin>>ID:
 int flag = 1;
 int i=0;
 while((i<accNum)&&(flag))
 {
  if(ID == account[i]->getID())
  {
   flag = 0;
  }
  else
  {
   i++;
  }
 }
 if(flag)
 {
  cout<<"The account does not exist!"<<endl<<endl;
  return;
 }
 account[i]->ShowMe()
 int choice = 0;
 while(choice!=3)
 {
  cout<<"   1:Save money"<<endl;
  cout<<"   2:Withdraw money"<<endl;
  cout<<"   3:Return"<<endl;
  cout<<"   Please input the choice:";
  cin>>choice;
  cout<<endl;
  switch(choice)
  {
   case 1:
    account[i]->Saving();
    break;
   case 2:
    account[i]->Withdraw();
    break;
   case 3:
    break;
  }
 }
 return;
}

void main()
{
 Bank bank;
 int choice = 0;
 cout<<"Welcome to bank system"<<endl;
 while(choice != 4)
 {
  cout<<"1: Add an account"<<endl;
  cout<<"2: Delete an account"<<endl;
  cout<<"3: Query an account"<<endl;
  cout<<"4: Exit"<<endl<<endl;
  cout<<"Please input your choice:";
  cout<<endl;
  cin>>choice;
  switch(choice)
  {
   case 1:
    bank.Append();
    break;
   case 2:
    bank.Delete();
    break;
   case 3:
    bank.Query()
    break;
   case 4:
    break;
  }
  cout<<endl;
 }
 return;
}

相关文章:

  • 2021-07-02
  • 2021-10-31
  • 2021-08-22
  • 2022-12-23
  • 2021-06-29
  • 2021-06-08
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2021-07-14
  • 2022-01-23
  • 2022-12-23
  • 2021-07-30
  • 2022-01-16
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案