Home | ProblemSet | Standing | Status | Statistics |
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
#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;
}
};