第11周 【项目0 - 是春哥啊】

来源:互联网 发布:网站域名备案注册证书 编辑:程序博客网 时间:2024/06/14 12:49

问题描述:

Name: 春哥
Grade: 19

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #include <iostream>  
  2. #include <cstring>  
  3. using namespace std;  
  4. class Person{  
  5. public:  
  6.     Person(char* s){  
  7.         strcpy(name,s);  
  8.     }  
  9.     void display( ){  
  10.         cout<<"Name: "<<name<<endl;  
  11.     }  
  12. private:  
  13.     char name [20];  
  14. };  
  15. class Student: ___________//(1)  
  16. {  
  17. public:  
  18.     Student(char* s, int g):__________ // (2)  
  19.     {grade=g;}  
  20.     void display1( ) {  
  21.         _________;   //  (3)  
  22.         cout<<"Grade: "<<grade<<endl;  
  23.     }  
  24. private:  
  25.     int grade;  
  26. };  
  27. int main( )  
  28. {  
  29.     Student s("春哥",19);  
  30.     ___________;       //  (4)  
  31.     return 0;  
  32. }  
代码:

#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: 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;}
运行结果:



0 0