Problem A: Person类与Student类的关系
来源:互联网 发布:上过好身材的体验知乎 编辑:程序博客网 时间:2024/05/29 13:22
HomeWeb BoardProblemSetStandingStatusStatistics#include <iostream>using namespace std;class Person{public: string name; int age;public: Person(string n ,int a ) : name(n), age(a){ cout << "A person " << name <<" whose age is " << age << " is created." << endl; } ~Person() { cout << "A person " << name << " whose age is " << age << " is erased." << endl; }public: void show() const { cout << "Name is " << name << " and age is " << age << "." << endl; }};class Student : public Person{private: int grade;public: Student(string n, int a, int g) : Person(n, a), grade(g) { cout << "A student whose grade is " << grade << " is created." << endl; } ~Student() { cout << "A student whose grade is " << grade << " is erased." << endl; } void show()const { cout << "Grade is " << grade << "." << endl; }};int main(){ string n; int a, g; cin>>n>>a>>g; Student student(n, a, g); student.Person::show(); student.show(); return 0;}Problem A: Person类与Student类的关系
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2013 Solved: 1544[Submit][Status][Web Board]Description
当然,一个student首先是一个person。所以,Student类是Person类的派生类。请定义Person类,包括:
1. 数据成员string name和int age,分别表示姓名和年龄。
2. 构造函数和析构函数,它们有相应的输出,见样例。
3. void show()函数:按照样例输出该对象的name和age属性值。
定义Student类,是Person类的子类:
1. 数据成员int grade,表示学生所在年级。
2. 构造函数和析构函数,它们有相应的输出,见样例。
3. void show()函数:按照样例输出该对象的grade属性值。
Input
只有1行,分为三部分:一个不含空白符的字符串以及两个整数。
Output
见样例。
Sample Input
Tom 19 3Sample Output
A person Tom whose age is 19 is created.A student whose grade is 3 is created.Name is Tom and age is 19.Grade is 3.A student whose grade is 3 is erased.A person Tom whose age is 19 is erased.HINT
Append Code
append.cc,[Submit][Status][Web Board] 한국어< 中文 فارسی English ไทยAll Copyright Reserved 2010-2011 SDUSTOJ TEAMGPL2.0 2003-2011 HUSTOJ Project TEAMAnything about the Problems, Please Contact Admin:admin
0 0
- Problem A: Person类与Student类的关系
- Problem A: Person类与Student类的关系
- Problem B: Person类与Student类的关系
- (继承)Problem A: Person类与Student类的关系
- Problem D: Person类与Student类的关系(C++期末)
- 创建继承类Person的类Student
- 创建继承类Person的类Student
- 创建继承于类person的类student
- 创建继承于类person的类student
- 创建继承于类person的类student
- Person Student Employee Faculty Staff 类
- 创建子类student继承父类person
- 《JAVA继承与多态》【Person、Student、Employee类】(注:此题在书上原题基础上有修改)设计一个名为Person的类和它的两个名为Student和Employee子类。
- A. Hungry Student Problem
- 9、 java Person,Student,GoodStudent 三个类的继承、构造函数的执行
- 实现一个名为Person的类和它的两个子类Student和Employee。
- Java:创建继承于类Person的类Student并重写方法
- 创建继承于类person的类student并重写方法
- 155.n1-Sliding menu的使用,创建侧边栏
- 计蒜客 跳跃游戏二 动态规划
- Java入门学习-自我理解IO流
- 填报表更新时去除重复数据
- java获取当天的开始时间,当前周的开始时间
- Problem A: Person类与Student类的关系
- docker 安装 zabbix
- Catch That Cow POJ 3278 BFS 广度优先搜索
- iOS逆向 ipa包重签名
- c#编程之文件操作
- 【微机实验系列】标准输入输出系统
- 为什么app卡顿?
- Subtree 解题报告
- Android状态栏和导航栏透明和沉浸式模式