10.11 Week Project 2--the student class that stores the monitor's information

Source: Internet
Author: User

Code:

/**copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp;* Author: Ye Chengyan May 6, 2016; * Version number: vc++6.0;** problem Description: Store monitor Letter and other types of interest. * Program input: slightly; * Program output: slightly; */#include <iostream> #include <string>using namespace Std;class Stu//Declaration base class {Public:stu (in  T n, String nam);          Base class constructor void display ();      member function, output base class data member Private://access permission is a 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 info:" <<endl;    Display ();            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 (); Call the base class member function}int Main () {//Students 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", "a", "King Beijing Road,    Shanghai ", 10001," Li-sun ");                       S.show ();                Output Student's data s.show_monitor (); Output sub-object data return 0;}
Run the test;



10.11 Week Project 2--the student class that stores the monitor's 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.