17th Week OJ Brush problem--problem e:c++ Exercise Input Output--Private inheritance

Source: Internet
Author: User

Description

The student class contains private data members: Num,name,sex, public member functions: Input function Get_value () and Output function display (). Implement class Student1 with private inheritance, adding data members: AGE,ADDR, member functions: Get_value_1 () and Display_1 (). Enter the value of NUM,NAME,SEX,AGE,ADDR when the program runs, and call the output function to output the values of the above 5 data.

Input

Enter a value for NUM,NAME,SEX,AGE,ADDR

Output

The value of the output num,name,sex,age,addr

Sample Input
1001 Zhang M Shanghai
Sample Output
Num:1001name:zhangsex:mage:21address:shanghai
/* All rights reserved. * File Name: Test.cpp * Chen Dani * Completion Date: July 3, 2015 * version number: v1.0 */#include &L T;iostream> #include <cstring>using namespace Std;class student{public:void get_value () {Cin>>    ;num>>name>>sex;        } void Display () {cout<< "num:" <<num<<endl;        cout<< "Name:" <<name<<endl;    cout<< "Sex:" <<sex<<endl;    }private:int num;    Char name[10]; char sex;};    Class Student1:private Student{private:int age;        String Addr;public:void get_value_1 () {get_value ();    cin>>age>>addr;        } void Display_1 () {display ();        cout<< "Age:" <<age<<endl;    cout<< "Address:" <<addr<<endl;    }};int Main () {Student1 stud1;    Stud1.get_value_1 ();    Stud1.display_1 (); return 0;} 
Learning experience: Private inheritance, you can inherit private members, but you cannot access private members directly, you can use a function to access. Keep trying!!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

17th Week OJ Brush problem--problem e:c++ Exercise Input Output--Private inheritance

Related Article

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.