C + + fourth time on-machine experiment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.