C++第四次作业

来源:互联网 发布:交大知行大厦 邮编 编辑:程序博客网 时间:2024/06/06 23:55

【项目1 - 龙三】

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

Grade: 19

#include <iostream>  #include <string>  using namespace std;  class Person{  public:      Person(string s){          name=s;      }      void display( ){          cout<<"Name: "<<name<<endl;      }  private:      string name;  };  class Student:public Person//(1)参考教材P169加底纹部分  {  public:      Student(string 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
原创粉丝点击