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 common inheritance, add 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 * finish Date: July 3, 2015 * version No.: v1.0 */#include <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:public Student{private:int age; String Addr;public:void get_value_1 () {cin>>age>>addr; } void Display_1 () {cout<< "Age:" <<age<<endl; cout<< "Address:" <<addr<<endl; }};int Main () {Student1 stud1; Stud1.get_value (); Stud1.get_value_1 (); Stud1.display (); Stud1.display_1 (); return 0;}
Learning experience: inheritance and derivation of this piece, I have to review carefully, continue to work!!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
17th Week OJ Brush problem--problem d:c++ Exercise Input output--common inheritance