程序实践 -银行系统

#include
#include
#include
using namespace std;
void aaa()
{
   cout<< "*****************中国志伟银行欢迎您******************"<      cout<   cout << "                1.增加账户" << endl;
  cout << "                2.删除账户" <   cout << "                3.查询账户" <   cout << "                4.取款和存款" <   cout << "                5.退出系统" <   cout << "****************************************************"< }
class Account
{
public:
 Account(string a,string b,double bal);
 virtual void saving(double a);
 virtual void getOutMoney(double a);
 virtual void showme();
 string getId();
 Account *next;
private:
 string Account_name;
 string name;
 double balance ;
};
class NormalAccount:public Account
{
public:
 NormalAccount(string a,string b,double bal):Account(a,b,bal){}
private:
 string Account_name;
 string name;
 double balance ;
};
class VIPAccount:public Account
{
public:
 VIPAccount(string a,string b,double bal,double d,double e):Account(a,b,bal),tzsx(d),tzze(e)
 {
 Account_name=a;
 name=b;
 balance=bal;
 tzsx=d;
 tzze=e;

 }
 void getOutMoney(double a);
 void showme();
private:
 string Account_name;
 string name;
 double balance ;
 double tzsx;
 double tzze;
};
Account::Account(string a,string b,double bal)
{
 Account_name = a;
 name = b;
 balance = bal;
}
void Account::saving(double a)
{
 balance = balance + a;
}
void Account::getOutMoney(double a)
{
 if(a > balance)
  cout<<"余额不足"<  else
 {
  balance = balance - a;
  cout << "已取出" << a << "元" <  }
}
void Account::showme()
{
 cout << "用户账号为" << Account_name << endl;
 cout << "开户人姓名" << name <  cout << "账户余额为" << balance < }
string Account::getId()
{
 return Account_name;
}
void VIPAccount::getOutMoney(double a)
{
 if(a >balance + tzsx -tzze)
  cout<<"不可透支"<  else
  balance = balance - a;
}
void VIPAccount::showme()
{
 cout << "用户账号为" << Account_name << endl;
 cout << "开户人姓名" << name <  cout << "账户余额为" << balance <  cout << "透支上限为" << tzsx <  cout << "透支总额为" << tzze < }
class Bank
{
public:
 Bank();
 void append1();
 void append2();
 void del();
 void query();
 void delaccount();
 void addaccountlist(Account *stu);
 Account *account[100];
 Account *plist;
private:

 int accNum;
 double Balance;
};
Bank::Bank()
{
 for(int i = 0;i < 100 ; i++ )
 {
  account[i] = NULL;
 }

 accNum = 0;
 plist=NULL;

}
void Bank::append1()
{
 string str1,str2;
 cout << "请输入普通用户账号" << endl;
 cin>>str1;
 cout << "请输入开户人姓名" << endl;
 cin>>str2;
 Account *acc = new NormalAccount(str1,str2,0) ;
 system("cls"); //调用DOS清屏命令
 aaa();
 cout<<"增加普通账户成功"<   account[accNum] = acc;
 accNum++;

}
void Bank::append2()
{
 string str1,str2;
 cout << "请输入高级用户账号" << endl;
 cin>>str1;
 cout << "请输入开户人姓名" << endl;
 cin>>str2;
 Account *acc = new VIPAccount(str1,str2,0,5000,0) ;
 system("cls"); //调用DOS清屏命令
 aaa();
 cout<<"增加高级账户成功"<  account[accNum] = acc;
 accNum++;

}

void Bank::del()
{
 string n;
 cout << "请输入要注销的用户账号" << endl;
 cin>>n;

 for(int i=0;i<100;i++)
 {
  if(account[i]==NULL)
  {
   continue;
  }
  if(account[i]->getId() != n)
   cout<<"没有这个账号"<   if(account[i]->getId() == n)
  {
   account[i]=NULL;
   system("cls"); //调用DOS清屏命令
   aaa();
   cout<<"账户已经删除"<    accNum--;
  }
 }
}
void Bank::query()
{
 string n;
 cout << "请输入您要查询的用户账号" << endl;
 cin>>n;

 for(int i=0;i<100;i++)
 {
  if(i==99)
   cout<<"没有这个账号"<   if(account[i]==NULL)
  {
   continue;
  }

  if(account[i]->getId() == n)
   account[i]->showme();
 }

}
void Bank::addaccountlist(Account *acc)
{
   Account *p;
 if(plist==NULL)
 {
  plist =acc;
  acc->next=NULL;
 }
 else
 {
  p = plist;
  while(p)
  {
   if(p->next==NULL)
   {
    p->next =acc;
    acc->next =NULL;

   }
   p= p->next;

  }

 }
}

int main()
{
 Bank bank;
 aaa();
 while(1)
 {
  int n;
  cin>>n;
  if(n == 1)
  {


   int n;
   cout<< "*****************************************************"<    cout<    cout << "                 1.增加普通账户" << endl;
   cout << "                 2.增加高级账户" << endl;
   cout << "****************************************************"<    cout << "                 请输入指令:" << endl;
   cin>>n;
   if(n == 1)
    bank.append1();
   if(n == 2)
    bank.append2();
  }

  if (n == 2)
  {
   bank.del();
  }

  if (n == 3)
  {
   bank.query();
  }

  if (n == 4)
  {

   string n;
   cout<<"请输入您要存取款的账号"<    cin>>n;
   for(int i=0;i<100;i++)
   {
    if(bank.account[i]->getId() != n)
     cout<<"账号输入错误"<     if(bank.account[i]->getId() == n)
    {
     int choice;

     cout<<"1.取款"<      cout<<"2.存款"<      cout<<"请选择"<

     cin>>choice;
     if(choice == 1)
     {
      double jine;
      cout<<"请输入取款金额"<       cin >> jine;
      bank.account[i]->getOutMoney(jine);
      bank.account[i]->showme();
      break;

     }
     if(choice == 2)

     {
      double qkuan;
      cout<<"请输入存款金额"<       cin>>qkuan;
      bank.account[i]->saving(qkuan);
      bank.account[i]->showme();
       break;

     }
    }

   }


  }

  if (n == 5)
   return 0;
 }

 //return 0;
}

 

你可能感兴趣的:(程序实践 -银行系统)