C++7-1-继承和派生:账户类

定义一个基类Account,数据成员包含string类变量userName用于保存账户主人姓名,函数成员包括默认构造函数、带参构造函数用于初始化数据成员和输出姓名的成员函PrintUserName()。从Account类派生出CreditAccount类,增加整型数据成员credit用于记录该用户信用额度,函数成员包括带参构造函数用于初始化数据成员和输出账户信息的成员函数PrintInfo()。要求:在函数PrintInfo()中需要调用基类的成员函数PrintUserName()。

下面是一份可供你填充和测试的代码:

#include <iostream>
#include <string>
using namespace std;

class Account
{
public:
    Account(){}
    Account(string name);
    void PrintUserName();
private:
    string userName;
};

class CreditAccount : public Account
{
public:
     CreditAccount(string name, int credit);
     void PrintInfo();
private:
     int credit;
};

//=============================================
// 请实现Account构造函数Account(string name)
Account::Account(string name) {   }

// 请实现Account的PrintUserName()函数
void Account::PrintUserName() {   }

// 请实现CreditAccount类的构造函数CreditAccount(string name, int credit)
CreditAccount::CreditAccount(string name, int credit) {   }

// 请实现CreditAccount类
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值