0
点赞
收藏
分享

微信扫一扫

第十一周项目一 类的继承填空


/*       
*Copyright(c) 2016,烟台大学计算机学院
*作 者:刘金石
*完成日期:2016年5月10日
*问题描述:在下面空格写入代码使程序输出为
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
{
public:
Student(char* s, int g):Person(s)
{grade=g;}
void display1( )
{
display(); // (3)
cout<<"Grade: "<<grade<<endl;
}
private:
int grade;
};
int main( )
{
Student s("春哥",19);
s.display1(); // (4)
return 0;
}


举报

相关推荐

0 条评论