Tenth Week Item 2-class of students who store monitor information (2)

Source: Internet
Author: User

/*copyright (c) 2016, *all Rights reserved, School of computer and Control engineering, Yantai University.               * File name: My.cpp * Author: * Completion date: May 8, 2016 * * Description: Change the access of the data members of the Stu class to private, can your program complete the required functionality? If not, please modify the program. Please do not modify the code given, you can only modify the code you write.  */#include <iostream>using namespace Std;class Stu//Declaration base class {Public:stu (int n, string nam): num (n), name (NAM) {}; Base class constructor void display ();    member function, output base class data member int Get_num () {return num;    } string get_s () {return name;      }private://(*) Access rights are protected data member int num;  Student study number string name;  Student name};  void Stu::d isplay () {cout<<: "<<num<<" << "Name:" <<name<<endl; }class studetail:public Stu//Declaration derived class Studetail{public://Student Nam, school 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): Stu (N,nam), monitor (N1,NAM1), age (a), addr (AD) {}; Derived class constructor void show ();    member function, output student's information void Show_monitor ();   member function, the output monitor information Private:stu monitor; The monitor of the student's class, the monitor is the student, is the STUThe member of the class int age;   Student Age string Addr; Student's address};void studetail::show () {cout<< "student" <<get_s () << ", Study number" <<get_num () << "," < <age<< "Years old, Lives" &LT;&LT;ADDR;}    void Studetail::show_monitor () {cout<< "monitor:"; 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 information s.show_monitor (); Output monitor message return 0;}

Tenth Week Item 2-class of students who store monitor information (2)

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.