<pre name= "code" class= "CPP" >/* *copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved * File name: 123.cpp * Author: Wang Lui * finish date : May 6, 2016 * version number: v1.0 * * Problem Description: Complete the definition of the member function in the class according to the declared class and test function * Input description: None. * Program output: None. */#include <iostream> #include <string>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) {}///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 information:" <<endl; cout<< "Study No.:" <<num<<endl; Output num cout<< "Name:" <<name<<endl; Output name 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 ();} int main () {Studetail s (10010, "Wang-li", "Beijing Road,shanghai", 10001, "Li-sun");//Students Wang Li, No. 10,010th, 19 years old, lives in Shanghai's Beijing Road, His monitor is Jason, study number 10001 s.show (); Output Student's information s.show_monitor (); Output sub-object information return 0;}
Operation Result:
Tenth to tenth week item two-class of students who store monitor information