定义一个基类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类