the relationship between Problem D:person class and Student classTime limit:1 Sec Memory limit:128 MB
submit:623 solved:438
[Submit] [Status] [Web Board]
Description
Of course, a student first is a person. Therefore, the student class is a derived class of the person class. Please define the person class, including:
1. Data member string name and int age, representing names and ages, respectively.
2. Constructors and destructors, which have corresponding outputs, see examples.
3. void Show () function: Prints the name and age property values of the object by sample.
Define the student class, which is a subclass of the person class:
1. data member int grade, which indicates the student's grade.
2. Constructors and destructors, which have corresponding outputs, see examples.
3. void Show () function: Prints the Grade property value of the object by sample.
Input
There are only 1 lines, divided into three parts: a string that contains no whitespace and two integers.
Output
See examples.
Sample Input
Tom 19 3
Sample Output
A person Tom whose The age is created.
A student whose grade is 3 is created.
The Name is Tom and the.
Grade is 3.
A student whose grade is 3 is erased.
A person Tom whose The age is erased.
HINT
Append Code append.cc,
int main ()
{
string n;
int A, G;
cin>>n>>a>>g;
Student Student (n, A, g);
Student. Person::show ();
Student.show ();
return 0;
}
The code is as follows:
#include <iostream> #include <iomanip> #include <string> #include <cstring> using namespace std
;
Class Person {public:string name;
int age;
Public:person (String _name,int _age) {name = _name;
age = _age; cout<< ' A person ' <<name<< ' whose age is ' <<age<< ' is created. '
<<endl; } ~person () {cout<< ' A person ' <<name<< ' whose ' is ' <<age<< ' is erased ."
<<endl; } void Show () {cout<< ' Name is ' <<name<< ' and ' is ' <<age<< '. '
<<endl;
}
};
Class Student:public person {public:int g;
Public:student (String _name,int _age,int _g):P Erson (_name,_age) {g=_g; cout<< ' A student whose grade is ' <<g<< ' is created. '
<<endl; } void Show () {cout<< ' Grade is ' <<g<< "."
<<endl; } ~student () {cout<< ' A Student whose grade is ' <<g<< ' is erased. '
<<endl;
}
};
int main () {string n;
int A, G;
cin>>n>>a>>g;
Student Student (n, A, g); Student.
Person::show ();
Student.show ();
return 0;
}