銀行系統

#include
#include <string>


using namespace std;


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();




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)
{


}
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<<"餘額不足"<<endl;
else
{
balance = balance - a;
cout << "已取出" << a << "元" <<endl;
}
}


void Account::showme()
{
cout << "用戶賬號爲" << Account_name << endl;
cout << "開戶人姓名" << name <<endl;
cout << "賬戶餘額爲" << balance <<endl;
}


string Account::getId()
{
return Account_name;
}


void VIPAccount::getOutMoney(double a)
{
if(a >balance + tzsx -tzze)
cout<<"不可透支"<<endl;
else
balance = balance - a;


}


void VIPAccount::showme()
{
cout << "用戶賬號爲" << Account_name << endl;
cout << "開戶人姓名" << name <<endl;
cout << "賬戶餘額爲" << balance <<endl;
cout << "透支上限爲" << tzsx <<endl;
cout << "透支總額爲" << tzze <<endl;


}


class Bank
{
public:
Bank();
void append1();
void append2();
void del();
void query();
Account *account[100];
private:


int accNum;
double Balance;


};


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


accNum = 0;
}


void Bank::append1()
{
string str1,str2;


cout << "請輸入普通用戶賬號" << endl;
cin>>str1;
cout << "請輸入開戶人姓名" << endl;
cin>>str2;
Account *acc = new NormalAccount(str1,str2,0) ;
cout<<"增加普通賬戶成功"<<endl;


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) ;
cout<<"增加高級賬戶成功"<<endl;


account[accNum] = acc;
accNum++;
}


void Bank::del()
{
string n;
cout << "請輸入要註銷的用戶賬號" << endl;
cin>>n;


for(int i=0;i<100;i++)
{
if(account[i]->getId() != n)
cout<<"沒有這個賬號"<<endl;
if(account[i]->getId() == n)
{
delete account[i];
accNum--;


}


}
}


void Bank::query()
{
string n;
cout << "請輸入您要查詢的用戶賬號" << endl;
cin>>n;


for(int i=0;i<100;i++)
{
if(account[i]->getId() != n)
cout<<"沒有這個賬號"<<endl;
if(account[i]->getId() == n)
account[i]->showme();
}


}


int main()
{
Bank bank;


while(1)
{
cout << "1.增加賬戶" << endl;
cout << "2.刪除賬戶" <<endl;
cout << "3.查詢賬戶" <<endl;
cout << "4.取款和存款" <<endl;
cout << "5.退出系統" <<endl;


cout << "請選擇" <<endl;


int n;
cin>>n;
if(n == 1)
{
int n;
cout << "1.增加普通賬戶" << endl;
cout << "2.增加高級賬戶" << endl;
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<<"請輸入您要存取款的賬號"<<endl;
cin>>n;
for(int i=0;i<100;i++)
{
if(bank.account[i]->getId() != n)
cout<<"賬號輸入錯誤"<<endl;
if(bank.account[i]->getId() == n)
{
int choice;


cout<<"1.取款"<<endl;
cout<<"2.存款"<<endl;
cout<<"請選擇"<<endl;


cin>>choice;
if(choice == 1)
{
double jine;
cout<<"請輸入取款金額"<<endl;
cin >> jine;
bank.account[i]->getOutMoney(jine);
bank.account[i]->showme();


}
if(choice == 2)
{
double qkuan;
cout<<"請輸入存款金額"<<endl;
cin>>qkuan;
bank.account[i]->saving(qkuan);
bank.account[i]->showme();
}
}


}




}


if (n == 5)
return 0;
}


//return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章