山东科技大学OJ Problem C: 简单教务系统中的用户

HomeProblemSetStandingStatusStatistics

Problem C: 简单教务系统中的用户

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1152  Solved: 421
[Submit][Status]

Description

一个简单的教务系统中的用户至少包含学生、老师两类用户。两类用户都有共同的属性姓名,教师有特有的属性职称,学生有特有的属性成绩。根据给出的主函数、输入和输出,定义三个类Person、Teacher和Student,实现基本的构造和析构功能。

Input

只有一行。第1个和第2个是字符串,表示姓名、职称,第3个是一个实数,表示成绩。

Output

见样例。

Sample Input

Tom Prof 234

Sample Output

A person without name is created. Person Tom is created. Teacher Tom Prof is created. Teacher Tom is erased. Person Tom is erased. Person Tom is created. Student Tom 234 is created. Student Tom is erased. Person Tom is erased. A person without name is erased.

HINT

Append Code

append.cc,

[Submit][Status]

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
class Person
{
public:
    string n;
    int fff;
    Person(){cout<<"A person without name is created."<<endl;fff=0;}
    Person(string x):n(x)
    {fff=1;
        cout<<"Person "<<n<<" is created."<<endl;
    }
    virtual ~Person()
    {if(fff==0)cout<<"A person without name is erased."<<endl;
    if(fff==1)cout<<"Person "<<n<<" is erased."<<endl;}
};
class Teacher:public Person
{
public:
    string p;
    Teacher(string x,string y):Person(x),p(y)
    {
        cout<<"Teacher "<<n<<" "<<p<<" is created."<<endl;
    }
    ~Teacher()
    {
        cout<<"Teacher "<<n<<" is erased."<<endl;
    }
};
class Student:public Person
{
public:
    double s;
    Student(string x,double y):Person(x),s(y)
    {
        cout<<"Student "<<n<<" "<<s<<" is created."<<endl;
    }
    ~Student()
    {
        cout<<"Student "<<n<<" is erased."<<endl;
    }
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值