Problem A: 家教课程
来源:互联网 发布:淘宝客链接怎么生成 编辑:程序博客网 时间:2024/04/27 23:38
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
append.cc,
#include <iostream>using namespace std; class Person{ protected: string name; public: Person(){} Person(string _name):name(_name) { cout << "Person "<< name <<" is created." << endl; } ~Person() { cout << "Person "<<name<<" is erased." << endl; }};class Student:public Person{private: int id;public: Student(string _name,int _id):Person(_name) { id = _id; //name = _name; cout << "Student "<<name<<" with id "<< id <<" is created." << endl; } ~Student() { cout << "Student "<<name<<" with id "<<id<<" is erased."<< endl; }};class Teacher:public Person{private: string position;public: Teacher(string _name ,string _position):Person(_name) { //name = _name; position = _position; cout << "Teacher "<<name<<" with position "<<position<<" is created." << endl; } ~Teacher() { cout << "Teacher "<<name<<" with position "<<position<<" is erased." << endl; }};class Course{private: Teacher teacher; Student student; string name;public: Course(string s1,string s2,string _position,string _name,int _id):student(s2,_id),teacher(s2,_position) { name = _name; cout << "Course "<<name<<" is created."<< endl; } ~Course() { cout << "Course "<<name<<" 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;}
阅读全文
0 0
- Problem A: 家教课程
- Problem C: 家教课程
- (继承)Problem C: 家教课程
- 课程练习一Problem A 搬桌子
- 课程练习三-1001-problem A
- 课程练习四—problem A
- 2016SDAU课程练习三1001 Problem A
- 2016SDAU课程练习四1001 Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- problem A
- Problem a
- UVa 1149 Bin Packing——优先队列
- 程序设计师真情忏悔录
- hive数据挖掘
- R语言基础
- Swift静态和动态分发机制
- Problem A: 家教课程
- map,set,multimap,multiset的异同
- 关于C++中的虚拟继承的一些总结
- Origin 求空域频率时 sample interval的设定
- build zxing-cpp
- 如何在mac的terminal安装Apache Tomcat
- 公积金单位账号和个人账号
- hdu4572_Bottles Arrangement_(思维+找规律)
- CFA将人工智能列入考试内容折射啥