第十章对象和类编程题

时光毁灭记忆、已成空白 提交于 2020-02-24 23:27:35
#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;
}




易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!