您的位置:首页 > 其它

实现一个简单的银行储蓄系统,承担活期用户的存款和取款业务 (只是初步的写出)

2013-01-29 13:17 681 查看
1. 要求如下:

1) 实现描述银行的类Bank,记录系统中现有哪些储户(可用数组或vector实现),定义了生成储户的函数append,按照账户删除储户的函数的delete,按账号查询储户的函数query,并显示结果。

2) 定义储户基类Account,具有属性账号,存款人姓名和余额,操作saving、withdraw和showme。虚函数saving 存储业务,虚函数withdraw处理取款业务,虚showme函数显示储户所有信息。

3) 定义储户派生类普通储户NormalAccount,实现操作saving、withdraw和showme,函数withdraw处理取款业务时余额不足不予取并提示信息,函数showme显示普通储户的所有信息。

4) 定义储户派生类高级储户VIPAccount,包含普通账户的所有信息,同时包含透支上限,透支总额,函数withdraw处理取款业务时超过透支上限不予取并提示信息,函数showme显示高级储户的所有信息。

5) 编写main函数,测试上述所要求的各种功能,即可以根据菜单命令增加,删除,和查询储户,以及储户存款和取款操作:

ž 增加账户时可选择增加普通账户和高级账户,普通账户帐号格式为“N001”,高级账户帐号格式为“V001”;

ž 根据输入的帐号删除和查询账户;

ž 储户取款和存款时要求输入帐号,根据帐号来操作账户。

#include <iostream>
#include <string>

using namespace std;

class Account
{
public:
Account(string a,string b,double bal);
virtual void saving(double a);
virtual void withdrow(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 withdrow(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::withdrow(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::withdrow(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]->withdrow(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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐