Questions and codes:
/*copyright (c) 2016. College of Computer Science, Yantai University * All rights reserved, * file name: text. CPP * Li Yipo * Completion date: May 10, 2016 * version number: vc++6.0 * * Problem Description: * Input Description: * Program output: */#include <iostream>using namespace Std;class St U//Declare base class {public:stu (int n, string nam); Base class constructor void display (); int Getnum () {return num;} String GetName () {return name;} Protected://(*) Access rights are protected data member int num; Student study number string name; Student name};class studetail:public STU//Declaration derived class Studetail{public://Student NAM, study number n,a years old, live ad, his monitor is NAM1, study number N1 Studeta Il (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}; Stu::stu (int n, string nam) {num=n; Name=nam;} void Stu::d isplay () {cout<< "Study No.:" <<num<<endl; cout<< "Name:" <<NAME<<ENDL;} Studetail::studetail (int n, String nam,int A, string ad,int N1, String nam1): Stu (N,nam), age (a), addr (AD), monitor (n1,nam1) {}void studetail::show () {display (); cout<< "Age:" <<age<<endl; cout<< "Address:" <<ADDR<<ENDL;} void Studetail::show_monitor () {cout<< "Monitor's information:" <<endl; Monitor.display ();} int main () {//Student 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", "1", "Beijing Road,shanghai" 0001, "Li-sun"); S.show (); Output Student information s.show_monitor (); Output monitor message return 0;}
Operation Result:
Tenth Week Project 2--the class of students who store monitor information