zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    BZOJ3236:[AHOI2013]作业(莫队,分块)
    BZOJ5334:[TJOI2018]数学计算(线段树)
    BZOJ3173:[TJOI2013]最长上升子序列(Splay)
    BZOJ3211:花神游历各国(线段树)
    BZOJ3155:Preprefix sum(线段树)
    HDU5002:Tree(LCT)
    【BZOJ 1911】 [Apio2010]特别行动队
    【BZOJ 2875】 [Noi2012]随机数生成器
    【BZOJ 1054】 [HAOI2008]移动玩具
    【BZOJ 1497】 [NOI2006]最大获利
  • 原文地址:https://www.cnblogs.com/qianxuejin/p/9050376.html
Copyright © 2011-2022 走看看