Home Web Board ProblemSet Standing Status Statistics

Problem B: 选举班干部了!

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2377  Solved: 1426
[Submit][Status][Web Board]

Description

新学期伊始,某班要通过竞争上岗方式竞选班干部。包括班长、团支书等。现在需要你来设计2个类Student和StudentCadre来模拟这一过程。

1.Student类是学生类,包括

(1)属性:string name——姓名。bool sex——性别。int grade——年级。Student *next——指向下一个学生指针。

(2)方法:

  • 构造函数Student(string _name, bool _sex, int _grade)——初始化一个对象。注意:其中的next初始化为NULL。
  • 析构函数。
  • void showInfo()——输出一个学生的信息。next除外。
  • Student* getNext()——获得next指针。
  • void setNext(Student*)——设置next指针指向对象。

2. StudentCadre类是Student类的派生类,包括:

(1)属性:string position——表示竞聘岗位。

(2)方法:

  • StudentCadre(string _name, bool _sex, int _grade, string pos)——构造函数,初始化各种属性。
  • 析构函数。
  • void showInfo()——显示信息。

构造函数和析构函数都有输出,具体见样例。

Input

输入有多行。

第1行有4部分:姓名、性别(0或1)、年级(整数)和岗位。

第2行是一个正整数N,表示有N个学生支持该人竞聘相应岗位。之后有N行,每行有3个部分,分别是一个学生的姓名、性别和年级。

Output

见样例。

Sample Input

Tom 0 2015 Monitor3Jack 1 2015Mary 0 2015Sherry 1 2015

Sample Output

A student named by Tom is created!A student cadre with position Monitor is created.A student named by Jack is created!A student named by Mary is created!A student named by Sherry is created!name = Tom, sex = 0, grade = 2015; position = Monitor.name = Jack, sex = 1, grade = 2015;name = Mary, sex = 0, grade = 2015;name = Sherry, sex = 1, grade = 2015;A student named by Tom is erased.A student named by Jack is erased.A student named by Mary is erased.A student named by Sherry is erased.

HINT

string类是C++提供的类,在头文件string中,可以用#include <string>来使用这个类。该类的对象可以直接利用赋值运算符(=)进行复制,也可以直接利用cout输出,或利用cin输入。

Append Code

append.cc,

[Submit][Status][Web Board]

한국어<  中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin

#include <iostream>
#include <string>
using namespace std;
class Student
{
protected:string name;int grade;bool sex;Student *next;
public:Student(string n, bool s, int g) : name(n), sex(s), grade(g), next(NULL){cout << "A student named by " << name << " is created!" << endl;}~Student(){cout << "A student named by " << name << " is erased." << endl;}void showInfo()const{cout << "name = " << name << ", sex = " << sex << ", grade = " << grade << ";" ;}Student* getNext(){return next;}void setNext(Student* s){next = s;}
};
class StudentCadre : public Student
{
private:string pos;
public:StudentCadre(string n, bool s, int g, string p) : Student(n, s, g) , pos(p){cout << "A student cadre with position Monitor is created." << endl;}~StudentCadre(){}void showInfo() const{cout << "name = " << name << ", sex = " << sex << ", grade = " << grade << "; position = " << pos << "." ;}};
int main()
{int num;string name, position;bool sex;int grade;Student *header, *student, *curStudent;cin>>name>>sex>>grade>>position;header = new StudentCadre(name, sex, grade,position);curStudent = header;cin>>num;for (int i = 0; i < num; i++){cin>>name>>sex>>grade;student = new Student(name, sex, grade);curStudent -> setNext(student);curStudent = curStudent -> getNext();}((StudentCadre*)header) -> showInfo();cout<<endl;curStudent = header;while (curStudent -> getNext() != NULL){curStudent = curStudent -> getNext();curStudent->showInfo();cout<<endl;}curStudent = header;while (curStudent != NULL){student = curStudent;curStudent = curStudent -> getNext();delete student;}return 0;
}

Problem B: 选举班干部了!相关推荐

  1. 实验8:Problem D: 选举班干部了!

    Home Web Board ProblemSet Standing Status Statistics Problem D: 选举班干部了! Problem D: 选举班干部了! Time Limi ...

  2. Problem C: 选举班干部了!

    Problem C: 选举班干部了! Description 新学期伊始,某班要通过竞争上岗方式竞选班干部.包括班长.团支书等.现在需要你来设计2个类Student和StudentCadre来模拟这一 ...

  3. Problem D: 选举班干部了!

    Problem D: 选举班干部了! Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 1669   Solved: 961 [ Submit][ St ...

  4. SDUSTOJ1780 Problem E: 选举班干部了!

    Description 新学期伊始,某班要通过竞争上岗方式竞选班干部.包括班长.团支书等.现在需要你来设计2个类Student和StudentCadre来模拟这一过程. 1.Student类是学生类, ...

  5. 计算机学校班干部竞选演讲稿,竞选班干部演讲稿三分钟范文5

    不要怕推销自己,只要你认为自己有才华,你就应该认为自己有资格提任.那么,竞选班干部演讲稿三分钟范文怎么写?以下是小编精心收集整理的竞选班干部演讲稿三分钟范文,下面小编就和大家分享,来欣赏一下吧. 竞选 ...

  6. 校园现金元外交 小学生用压岁钱打点班干部

    校园现"金元"外交 小学生用压岁钱"打点"班干部 2007年03月20日 来源:东北新闻网-沈阳今报    [非常现象] 新学期开始,小学班干部面临局部&quo ...

  7. python集合操作班级干部竞选演讲稿_实用的竞选班干部演讲稿集合八篇

    实用的竞选班干部演讲稿集合八篇 演讲稿在写作上具有一定的格式要求.在社会发展不断提速的今天,演讲稿对我们的作用越来越大,大家知道演讲稿的格式吗?下面是小编精心整理的竞选班干部演讲稿8篇,仅供参考,大家 ...

  8. python集合操作班级干部竞选演讲稿_精选竞选班干部的演讲稿集合7篇

    精选竞选班干部的演讲稿集合7篇 演讲稿在写作上具有一定的格式要求.在现实社会中,用到演讲稿的地方越来越多,为了让您在写演讲稿时更加简单方便,以下是小编整理的竞选班干部的演讲稿7篇,欢迎阅读与收藏. 竞 ...

  9. 计算机学校班干部竞选演讲稿,精选:2019学校班干部个人竞选演讲稿范文五篇...

    <2019学校班干部个人竞选演讲稿范文五篇.doc>由会员分享,可免费在线阅读全文,更多与<2019学校班干部个人竞选演讲稿范文五篇>相关文档资源请在帮帮文库(www.woc8 ...

最新文章

  1. Spark中自定义排序
  2. 使用Mapreduce案例编写用于统计文本中单词出现的次数的案例、mapreduce本地运行等,Combiner使用及其相关的知识,流量统计案例和流量总和以及流量排序案例,自定义Partitioner
  3. 太强了!Python 开发桌面小工具,让代码替我们干重复的工作!
  4. Storyboard的简单使用
  5. 简约响应式导航主题VIK_WordPress模板
  6. linux编译cpp文件命令,Jsoncpp Linux 下编译为 .a 文件
  7. linux更新模块,GNOME 3.29.3 发布,大量模块更新及功能改进
  8. 力扣-48 旋转图像
  9. 190601每日一句
  10. Redis安装与开机启动
  11. 腾讯首款区块链AR游戏上线《一起来捉妖》,风物志里的奇珍异兽
  12. 基于python实现FFT和DWT记录
  13. SLAM【十】回环检测
  14. Android App内打开淘宝详情页
  15. layui表格使用及分页实现
  16. oracle取上行数据进行填充
  17. linux驱动设备开发1——字符设备驱动
  18. 为什么函数f(x)=x²不是满射
  19. 驱动 | Linux | NVMe | 2. nvme_probe
  20. DiscoveryClient

热门文章

  1. 点播 构造自己的播放器 用户调用获取视频播放地址接口
  2. 2019年程序员岗位招聘信息分析
  3. mysql144,通过phpMyAdmin从MySQL错误144中恢复
  4. Tryhackme-Introduction to Web Hacking
  5. 国产ThinkJS 项目构建 Docker 镜像制作与log日志问题
  6. thinkjs连接mysql_Mysql_ThinkJs2.0开发手册_w3cschool
  7. What's Great 2012
  8. Ajax中的<form>标签
  9. c++ txt文件的读写及乱码问题解决
  10. 我的学习计划,反思……