C7-1 账户类(100/100)

 

题目描述

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

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

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

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

//请实现Account构造函数Account(string name)
//请实现Account的PrintUserName()函数
//请实现CreditAccount类的构造函数CreditAccount(string name, long number)
//请实现CreditAccount类的PrintInfo()函数

int main()
{
CreditAccount a("I Love CPP", 10000);
a.PrintInfo();
return 0;
}



输入描述


输出描述

输出共两行,第一行为账户姓名,第二行为账户信用额度



样例输入

 


样例输出

I Love CPP
10000
#include <iostream>
#include <string>
using namespace std;
    
class Account{ 
    string userName;
public:
    Account(){};
    Account( string name );
    void  PrintUserName();
};
    
class CreditAccount : public Account{
public:
    CreditAccount( string name, int credit);
    void PrintInfo();
private:
    int _credit;
};
    
Account::Account( string name ){//请实现Account构造函数Account(string name)
    userName=name;
}
void Account::PrintUserName(){//请实现Account的PrintUserName()函数
    cout<<userName<<endl;
}
CreditAccount::CreditAccount( string name, int credit):Account(name){//请实现CreditAccount类的构造函数CreditAccount(string name, long number)
    _credit=credit;
}
void CreditAccount::PrintInfo(){//请实现CreditAccount类的PrintInfo()函数
    Account::PrintUserName();
    cout<<_credit<<endl;
}

int main(){
    CreditAccount a("I Love CPP", 10000);
    a.PrintInfo();
    return 0;
}

 

转载于:https://www.cnblogs.com/qianxuejin/p/9050376.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
c:/users/86178/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\86178\AppData\Local\Temp\arduino\cores\b5342b8f51c7a5f33a81df0845d289d9\core.a(core_esp8266_main.cpp.o): in function `__loop_end': C:\Users\86178\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/core_esp8266_main.cpp:168: undefined reference to `setup' c:/users/86178/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\86178\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/core_esp8266_main.cpp:168: undefined reference to `loop' c:/users/86178/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\86178\AppData\Local\Temp\arduino\cores\b5342b8f51c7a5f33a81df0845d289d9\core.a(core_esp8266_main.cpp.o): in function `loop_wrapper()': C:\Users\86178\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/core_esp8266_main.cpp:174: undefined reference to `setup' c:/users/86178/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\86178\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/core_esp8266_main.cpp:175: undefined reference to `loop' collect2.exe: error: ld returned 1 exit status exit status 1 Compilation error: exit status 1
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值