1. On-Machine content: Inheritance and derivation
2. Purpose of the machine: Learn to use inheritance and derivation simply
/* File name: Student class * Author: Wang Zewen * Completion date: April 22, 2016 * version number: vc6.0 * Description of task and solution method part: * Input Description: Enter student's name, school number, address, age * question Description: Slightly * Program output: Student information, monitor information * problem analysis: slightly * algorithm design: Slightly */#include <iostream> #include <string> using namespace St D Class Stu//declares 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//Declare 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 (); member function, output student's information void Show_monitor (); member function, the output monitor information Private:stu monitor; The class leader of the student, the Monitor is a student, is a member of the Stu class intAge 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) {addr=ad; Age=a; } void Studetail::show () {cout<< "Student information:" <<endl; Display (); cout<< "Age:" <<age<<endl; cout<< "Address:" <<addr<<endl; } void Studetail::show_monitor () {cout<< "Monitor info:" <<endl; Monitor.display (); } int main () {//student Zhang San, 10,010th, 19 years old, lives in Nanchang, Jiangxi Province, his monitor is John Doe, study number 10001 Studetail s (10010, "Zhang San", 19, "Jiangxi Nanchang", 10001, "John Doe"); S.show (); Output Student information s.show_monitor (); Output monitor information return 0; }
3. Experience: To use more inheritance to better grasp
3. Summary of Knowledge Points: application of inheritance and derivation
C + + fourth time on-machine experiment