Code:
/**copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp;* Author: Ye Chengyan May 6, 2016; * Version number: vc++6.0;** problem Description: Store monitor Letter and other types of interest. * Program input: slightly; * Program output: slightly; */#include <iostream> #include <string>using namespace Std;class Stu//Declaration base class {Public:stu (in T n, String nam); Base class constructor void display (); member function, output base class data member Private://access permission is a protected data member int num; Student study number string name; Student name}; Stu::stu (int n, string nam): num (n), name (NAM) {}///base class constructor void Stu::d isplay ()//member function, output base class data member { cout<< "Study No.:" <<num<<endl; cout<< "Name:" <<NAME<<ENDL;} Class Studetail:public Stu//Declaration Common derived class Studetail{public://Student NAM, study number n,a years old, live 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 (); void Show_monitor (); member function, output sub-object Private:stu Monitor; The class monitor of the students, the monitor is a student, with Stu Declaration 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) {}//derived class constructor void Studetail:: Show () {cout<< "Student info:" <<endl; Display (); 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's data s.show_monitor (); Output sub-object data return 0;}
Run the test;
10.11 Week Project 2--the student class that stores the monitor's information