"TOJ 5253" C + + experiment: Multiple inheritance

Source: Internet
Author: User

Describe

Define the following classes:

1 CPerson classes, whose attributes are: Name, gender, and age.

2, from the CPerson class derived from the Cstudent class, add attributes: Student number, the time of admission and school performance;

3, derived from the CPerson class Cteacher class, add attributes: Job, department and working hours;

4, derived from the Cstudent class Cgraduate class, add attributes: Research direction and mentor;

5, by Cgraduate and Cteacher jointly derived from the working postgraduate class Cgradonwork;

6, CDate is the date class.

Each class defines a print function that outputs its property values, and the output is shown in the sample.

The code in the main function is given, please fill it out, and do not include the code that you have given when committing.

int main () {cgradonwork S1 ("Crq", "Max", "Male", "Teacher", "Sxxy", CDate (2002,9,1), "All", CDate (2003, 9, 1), +, "TM", "CS"); s 1.Print (); S1. Cteacher::P rint (); S1. Cgraduate::P rint (); S1. Cstudent::P rint (); S1. CPerson::P rint (); return 0;}

Input

No

Output

Output Sample Information

Sample input

No

Sample output

Crq Male teacher Sxxy 2002-9-1 2003-9-1-TM CS
Crq Male teacher Sxxy 2002-9-1
CRQ Male 2003-9-1 CS
CRQ Male 15 2003-9-1 400
CRQ Male

#include <iostream>#include<string>using namespacestd;classcdate{ Public:        inty,m,d;        CDate (); CDate (intYintMintd): Y (y), M (m), D (d) {}};classcperson{ Public:        stringName,sex; intAge ;        CPerson (); CPerson (stringNameintAgestringsex): Name, age, sex (Sex) {}voidPrint () {cout<<name<<" "<<age<<" "<<sex<<Endl; }};classCstudent:Virtual  Publiccperson{ Public:        stringID;        CDate School; intgrade;        Cstudent (); Cstudent (stringNameintAgestringSexstringId,cdate School,intgrade): CPerson (name,age,sex), ID (ID), school (school), grade (grade) {}voidPrint () {cout<<name<<" "<<age<<" "<<sex<<" "<<id<<" "<<school.y<<"-"<<school.m<<"-"<<school.d<<" "<<grade<<Endl; }};classCteacher:Virtual  Publiccperson{ Public:        stringDuty,depart;                CDate work;        Cteacher (); Cteacher (stringNameintAgestringSex,cdate work,stringDutystringdepart): CPerson (Name,age,sex), Duty (Duty), Depart (depart), work (work) {}voidPrint () {cout<<name<<" "<<age<<" "<<sex<<" "<<duty<<" "<<depart<<" "<<work.y<<"-"<<work.m<<"-"<<work.d<<Endl; }};classCgraduate: Publiccstudent{ Public:        stringStudy,tutor;        Cgraduate (); Cgraduate (stringNameintAgestringSexstringId,cdate School,intGradestringStudystringtutor): Cstudent (Name,age,sex,id,school,grade), CPerson (name,age,sex), Study (study), Tutor (tutor) {} 
    voidPrint () {cout<<name<<" "<<age<<" "<<sex<<" "<<id<<" "<<school.y<<"-"<<school.m<<"-"<<school.d<<" "<<grade<<" "<<study<<" "<<tutor<<Endl; }};classCgradonwork: PublicCgraduate, Publiccteacher{ Public:        stringName,sex; intAge ;        Cgradonwork (); Cgradonwork (stringNameintAgestringSexstringDutystringDepart,cdate work,stringId,cdate School,intGradestringStudystringtutor): Cteacher (Name,age,sex,work,duty,depart), Cgraduate (name,age,sex,id,school,grade,study,tutor), CPerso N (name,age,sex), name (name), age, sex (Sex) {}voidPrint () {cout<<name<<" "<<age<<" "<<sex<<" "<<duty<<" "<<depart<<" "<<work.y<<"-"<<work.m<<"-"<<work.d<<" "<<id<<" "<<school.y<<"-"<<school.m<<"-"<<school.d<<" "<<grade<<" "<<study<<" "<<tutor<<Endl; }};intMain () {cgradonwork S1 ("Crq", +,"Male","Teacher","Sxxy", CDate (2002,9,1)," the", CDate (2003,9,1), -,"TM","CS"); S1.    Print (); S1.    Cteacher::P rint (); S1.    Cgraduate::P rint (); S1.    Cstudent::P rint (); S1.    CPerson::P rint (); return 0;}

"TOJ 5253" C + + experiment: Multiple inheritance

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.