发布网友 发布时间:2022-04-27 00:12
共2个回答
热心网友 时间:2022-06-21 05:21
#include <iostream>
#include <string>
using std::endl;
using std::cout;
using std::cin;
using std::string;
class bank
{
private:
string name; //账户名
int num; //账号
int money; //余额
public:
bank();
bank(string &na,int &nu,int mo);
bool in(int s);
bool out(int s);
void view()const;
};
bank::bank()
{
cout<<"现在要创建账户\n";
cout<<"输入账户名: ";
cin>>name;
cout<<"输入账号: ";
cin>>num;
cout<<"输入现有金额: ";
cin>>money;
}
bank::bank( string &na,int &nu,int mo )
{
name=na;
num=nu;
money=mo;
}
bool bank::in(int s)
{
cout<<"你确定要存"<<s<<"¥ ?(yes or no) :";
char ch;
while(cin>>ch && (ch=='y'||ch=='Y'))
{
while(cin.get()!='\n')
continue;
money=money+s;
return true;
}
cout<<"存款失败!";
return false;
}
bool bank::out(int s)
{
if(s>money)
{
cout<<"余额不足.";
return false;
}
else if(s>=2000)
{
cout<<"取款失败!取款必须小与2000!";
return false;
}
else
{
int t=money;
money=money-s;
cout<<"取款成功!\n";
return true;
}
}
void bank::view() const
{
cout<<"账户姓名: "<<name<<endl;
cout<<"账户账号: "<<num<<endl;
cout<<"金额:"<<money<<endl;
}
int main()
{
bank chang;
cout<<"输入您要进行的操作\n"
<<"1.取款\n"
<<"2.存款\n"
<<"3.查询余额\n";
int choice;
while(cin>>choice && (choice==1||choice==2||choice==3))
{
if(choice==1)
{
cout<<"您要取出多少钱???";
int mon;
cin>>mon;
cout<<"****取出前金额****\n";
chang.view();
chang.out(mon);
cout<<"****取出后金额****\n";
chang.view();
}
else if(choice==2)
{
cout<<"您要存入多少钱???";
int mon;
cin>>mon;
cout<<"****存入前金额****\n";
chang.view();
chang.in(mon);
cout<<"****出入后金额****\n";
chang.view();
}
else
chang.view();
cout<<"输入您要进行的操作\n"
<<"1.取款\n"
<<"2.存款\n";
}
cout<<"bye~~!\n";
return 0;
}
这样可以么?
热心网友 时间:2022-06-21 05:21
可找淘宝, 搜索"C++语言作业代做"