Questions and codes:
/* *copyright (c) 2016, *all right reserved, school of computer and Control engineering, Yantai University. * File name: 77.cpp * Author: Dong Kai * Completion Date: May 6, 2016 * version number: v1.0 * * Problem Description: Please complete the definition of member function in class * Input Description: * Program output: Student's information */#include <iostream> using namespace Std; Class Stu {public:stu (int n,string nam); void display (); Protected:int num; String 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{public://Student NAM, study number n, live ad, his monitor nam1, study number n1 studetail (int n,string nam,int a,string ad,int N1 , string nam1); void Show (); void Show_monitor ();p rivate:stu Monitor; int age; string addr;}; Studetail::studetail (int n,string nam,int n1,string nam1,int a,string AD): Stu (N,nam), monitor (N1,NAM1), age (a), addr (ad {}void studetail::show () {cout<< "Student information:" <<endl; cout<< "Study No.:" <<num<<endl; cout<< "Name:" <<name<<endl; cout<< "Age: "<<age<<endl; cout<< "Address:" <<addr<<endl; Cout<<endl;} void Studetail::show_monitor () {cout<< "Monitor info:" <<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's data s.show_monitor (); Output sub-object data return 0;}
Operation Result:
Summary of Knowledge points:
If a derived class data member contains a base class object, it should be noted that when assigning a value to a base class, the base class object is assigned a value, or a warning is generated.
Learning experience:
To notice every detail, every detail can be the point of making a mistake.
11th Week Practice Item 2-Class of students who store monitor information