敲代码的第十六天:创建子类账户第三版(上)(c++)

#include<iostream>
using namespace std;
class Bank {
protected:
    const string id;
    string password;
    double balance;
public:
    Bank(const string Id, string Password, double Balance) :id(Id) {
        password = Password;
        balance = Balance;
    }
    string GetId() {
        return id;
    }
    string GetPassword() {
        return id;
    }
    double GetBalance() {
        return balance;
    }

};
class SaveBank :public Bank {
protected:
    string name;
    string address;
    double minimum_balance;
    float annual_interest_rate;
public:
    SaveBank(const string Id, string Password, double Balance, string Name, string Address, double Minimum_balance, float Annual_interest_rate):Bank(Id,Password,Balance) {
        name = Name;
        address = Address;
        minimum_balance = Minimum_balance;
        annual_interest_rate = Annual_interest_rate;

    }
    string GetName() { return name; }
    string GetAddress() { return address; }
    double Get_minimum_balance() { return minimum_balance; }
    float Get_annual_interest_rate() { return annual_interest_rate; }
    double cunkuan(double money) {//存款
        balance += money;
        return balance;
    }
    double qukuan(double money) {//取款
        if (money <= (balance - minimum_balance)) {
            balance -= money;
            return balance;
        }
        else{
            cerr << "余额不足!请重新选择操作!" << endl;
        }
    }
    double profit(int year) {
        return (balance * annual_interest_rate * year);
    }
    string change_password() {//修改密码
        string new_password;
        string number;
        cout << "请输入原始密码:" << endl;
        cin >> number;
        if (number == password) {
            cout << "请输入新密码:" << endl;
            cin >> new_password;
            password = new_password;
            cout << "修改成功!" << endl;
        }else
        {
            cout << "原始密码错误,请重新选择操作!" << endl;
        }
        return password;
    }
    void getbank() {//获取账户信息
        cout << "姓名:" << GetName()<<endl;
        cout << "账号:" << GetId() << endl;
        cout << "余额:" << GetBalance() << endl;
        cout << "密码:" << GetPassword() << endl;
        cout << "地址:" << GetAddress() << endl;
        cout << "最少余额:" << Get_minimum_balance() << endl;
        cout << "利率:" << Get_annual_interest_rate() << endl;
    }
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值