Questions and codes:
/*copyright School of Computer and control engineering completion Date: May 6, 2016 Ma Yanyan problem Description: "Project-student class to store monitor information" Output Description: Student information */#include <iostream>using namespace std Class Stu//Declaration base class {Public:stu (int n,string nam); Base class constructor void display (); member function, output base class data member Protected://(*) Access rights are protected data member int num; Student study number string name; Student name}; Stu::stu (int n, string nam): num (n), name (NAM) {}void Stu::d isplay () {cout<< "Study No.:" <<num<<endl; cout<< "name" <<NAME<<ENDL;} Class Studetail:public Stu//Declaration derived class Studetail{public://Student Nam, school number n,a years old, lives in AD, his monitor is NAM1, study number n1 studetail (int n , string nam,int A, string ad,int n1, string nam1); Derived class constructor void show (); member function, output student's information void Show_monitor (); member function, the output monitor information Private:stu monitor; The class monitor of the student, the monitor is the student, is the member of the Stu class int age; Student Age string Addr; Student's address}; Studetail::studetail (int n, String nam,int A, string ad,int n1, String nam1): Stu (N,nam), monitor (N1,NAM1), age (a), addr (ad {} void Studetail::show () {cout<< "Student information: "<<endl; cout<< "Study No.:" <<num<<endl; Output num and name cout<< "Name:" <<name<<endl; cout<< "Age:" <<age<<endl; Output Age cout<< "Address:" <<addr<<endl<<endl; Output addr}void Studetail::show_monitor ()//member function, output sub-object {cout<< "Monitor info:" <<endl; Monitor.display (); Call the base class member function}int Main () {//Students Wang Li, No. 10,010th, 19 years old, lives in Shanghai's Beijing Road, his monitor is Jason, study number 10001 Studetail s (10010, "Wang-li", "a", "King Beijing Road, Shanghai ", 10001," Li-sun "); S.show (); Output Student information s.show_monitor (); Output monitor message return 0;}
Operation Result:
Summary of Knowledge points:
Take advantage of the relationship between derived classes and base classes
Week tenth-Class of students who store monitor information