Problem C: 家教课程

Problem C: 家教课程

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 604   Solved: 401
[ Submit][ Status][ Web Board]

Description

老师都是穷人,所以需要经常去外面搞点兼职啥的。可是除了上课,啥也不会啊。所以就只好做家教了。现在请利用面向对象的思想设计这样一个系统。具有如下类:

1. Person类:有一个string类型的属性,表明对象的名字。是Student和Teacher的父类。

2. Student类:是Person类的子类,拥有一个int类型的属性,表明对象的序号。

3. Teacher类:是Person类的子类,拥有一个string类型的属性,表明对象的职称。

4. Course类:是一个组合类,有1个Teacher类的对象、1个Student类型的对象,以及一个string类型的属性(表明对象的名称)组成。

请定义上述类的构造函数和析构函数,并在函数中输出相应的字符串。具体格式请参照样例输出。

Input

输入5行,前4个是4个字符串,分别是老师的名字、学生的名字、老师的职称、课程的名字。最后一行是一个整数,表示学生的序号。

Output

见样例~

Sample Input

TomJackProfC++10

Sample Output

Person Tom is created.Person Jack is created.Person Tom is created.Teacher Tom with position Prof is created.Person Jack is created.Student Jack with id 10 is created.Person Jack is created.Teacher Jack with position Prof is created.Person Jack is created.Student Jack with id 10 is created.Course C++ is created.Course C++ is erased.Student Jack with id 10 is erased.Person Jack is erased.Teacher Jack with position Prof is erased.Person Jack is erased.Student Jack with id 10 is erased.Person Jack is erased.Teacher Tom with position Prof is erased.Person Tom is erased.Person Jack is erased.Person Tom is erased.

HINT

注意根据main函数分析各个构造函数的每个参数的含义。

Append Code


#include <iostream>
using namespace std;

class Person
{
public:
    string name;
    Person(string name):name(name){cout<<"Person "<<name<<" is created."<<endl;}
    ~Person(){cout<<"Person "<<name<<" is erased."<<endl;}
};
class Student :public Person
{
public:
    int num;
    Student(string name,int _num):Person(name)
    {
        num = _num;
        cout<<"Student "<<name<<" with id "<<num<<" is created."<<endl;
    }
    ~Student(){ cout<<"Student "<<name<<" with id "<<num<<" is erased."<<endl;}
};
class Teacher:public Person
{
public:
    string p;
    Teacher(string name,string _p):Person(name){p = _p;cout<<"Teacher "<<name<<" with position "<<p<<" is created."<<endl;}
    ~Teacher(){cout<<"Teacher "<<name<<" with position "<<p<<" is erased."<<endl;}
};
class Course
{
public:

    Teacher tea;
    Student stu;
    string course;
    Course(string sname,string name,string p,string _course,int num):tea(name,p),stu(name,num){
        course = _course;
        cout<<"Course "<<course<<" is created."<<endl;}
    ~Course(){cout<<"Course "<<course<<" is erased."<<endl;}
};
int main()
{
    string s1, s2, s3, s4;
    int i;
    cin>>s1>>s2>>s3>>s4>>i;
    Person person1(s1), person2(s2);
    Teacher teacher(s1, s3);
    Student student(s2, i);
    Course course(s1, s2, s3, s4, i);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Usher_Ou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值