11th Week Practice Item 2-Class of students who store monitor information

Source: Internet
Author: User

Questions and codes:

/* *copyright (c) 2016, *all right reserved, school of computer and Control engineering, Yantai University. * File name: 77.cpp * Author: Dong Kai * Completion Date: May 6, 2016 * version number: v1.0 * * Problem Description: Please complete the definition of member function in class * Input Description: * Program output: Student's information */#include <iostream> using namespace Std;    Class Stu {public:stu (int n,string nam); void display ();    Protected:int num; String 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{public://Student NAM, study number n, live ad, his monitor nam1, study number n1 studetail (int n,string nam,int a,string ad,int N1    , string nam1);    void Show ();    void Show_monitor ();p rivate:stu Monitor;    int age; string addr;}; Studetail::studetail (int n,string nam,int n1,string nam1,int a,string AD): Stu (N,nam), monitor (N1,NAM1), age (a), addr (ad    {}void studetail::show () {cout<< "Student information:" <<endl;    cout<< "Study No.:" <<num<<endl;    cout<< "Name:" <<name<<endl; cout<< "Age: "<<age<<endl;    cout<< "Address:" <<addr<<endl; Cout<<endl;}    void Studetail::show_monitor () {cout<< "Monitor info:" <<endl; 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's data s.show_monitor (); Output sub-object data return 0;}

Operation Result:


Summary of Knowledge points:

If a derived class data member contains a base class object, it should be noted that when assigning a value to a base class, the base class object is assigned a value, or a warning is generated.

Learning experience:

To notice every detail, every detail can be the point of making a mistake.


11th Week Practice Item 2-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.