码迷,mamicode.com
首页 > 其他好文 > 详细

第11周 代码填充-是春哥啊

时间:2015-05-17 13:43:45      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:c++   大一练习   继承和派生   

请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:

Name: 春哥
Grade: 19

#include <iostream>
#include <cstring>
using namespace std;
class Person{
public:
    Person(char* s){
        strcpy(name,s);
    }
    void display( ){
        cout<<"Name: "<<name<<endl;
    }
private:
    char name [20];
};
class Student: ___________//(1)
{
public:
    Student(char* s, int g):__________ // (2)
    {grade=g;}
    void display1( ) {
        _________;   //  (3)
        cout<<"Grade: "<<grade<<endl;
    }
private:
    int grade;
};
int main( )
{
    Student s("春哥",19);
    ___________;       //  (4)
    return 0;
}


代码:

#include <iostream>
#include <cstring>
using namespace std;
class Person{
public:
    Person(char* s){
        strcpy(name,s);
    }
    void display( ){
        cout<<"Name: "<<name<<endl;
    }
private:
    char name [20];
};
class Student: public Person//(1)
{
public:
    Student(char* s, int g):Person(s) // (2)
    {grade=g;}
    void display1( ) {
        display();   //  (3)
        cout<<"Grade: "<<grade<<endl;
    }
private:
    int grade;
};
int main( )
{
    Student s("春哥",19);
    s.display1();       //  (4)
    return 0;
}

运行结果:

技术分享

 

 

 

 

第11周 代码填充-是春哥啊

标签:c++   大一练习   继承和派生   

原文地址:http://blog.csdn.net/ljd939952281/article/details/45788239

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!