The relationship between the Problem D:person class and the Student class (end of C + +) __c++

Source: Internet
Author: User
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; 
 }



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.