Tenth to tenth week item two-class of students who store monitor information

Source: Internet
Author: User

<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:" &LT;&LT;NAME&LT;&LT;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

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.