#include <iostream>
#include <string>
using namespace std;
class account
{
private:
string name;
string id;
double deposit;
public:
account();
account(string n, string i, double d);
void show() const;
void account_in();
void acocunt_out();
};
int main()
{
account account1("zhengyuxin", "041933011", 100);
account1.show();
account1.account_in();
account1.show();
account1.acocunt_out();
account1.show();
return 0;
}
account::account()
{
name = "none";
id = "none";
deposit = 0;
}
account::account(string n, string i, double d)
{
name = n;
id = i;
deposit = d;
}
void account::show() const
{
cout << "name: " << name << endl;
cout << "id: " << id << endl;
cout << "deposit: " << deposit << endl;
}
void account::account_in()
{
cout << "请输入存钱数:" << endl;
double x;
cin >> x;
deposit += x;
}
void account::acocunt_out()
{
cout << "请输入取钱数: " << endl;
double x;
cin >> x;
if (x > deposit)
cout << "错误" << endl;
else
deposit -=x;
}
来源:CSDN
作者:zl吉姆餐厅
链接:https://blog.csdn.net/qq_32631105/article/details/104479545