实验8:Problem D: 选举班干部了!
Home | Web Board | ProblemSet | Standing | Status | Statistics |
Problem D: 选举班干部了!
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 531 Solved: 308
[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
Sample Output
HINT
string类是C++提供的类,在头文件string中,可以用#include <string>来使用这个类。该类的对象可以直接利用赋值运算符(=)进行复制,也可以直接利用cout输出,或利用cin输入。
Append Code
[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;bool sex;int grade;Student *next; public:Student(string _name, bool _sex, int _grade):name(_name),sex(_sex),grade(_grade),next(NULL){cout<<"A student named by "<<name<<" is created!"<<endl;}~Student(){cout<<"A student named by "<<name<<" is erased."<<endl;}void showInfo(){cout<<"name = "<<name<<", sex = "<<sex<<", grade = "<<grade<<";";}Student* getNext(){return next;}void setNext(Student* s){next=s;} }; class StudentCadre:public Student{ protected:string position; public:StudentCadre(string _name, bool _sex, int _grade, string pos):Student(_name,_sex,_grade),position(pos){cout<<"A student cadre with position "<<position<<" is created."<<endl;}~StudentCadre(){cout<<"A student named by "<<name<<" is erased."<<endl;};void showInfo(){cout<<"name = "<<name<<", sex = "<<sex<<", grade = "<<grade<<"; position = "<<position<<".";}}; 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; }
转载于:https://www.cnblogs.com/auto1945837845/p/5425590.html
实验8:Problem D: 选举班干部了!相关推荐
- Problem B: 选举班干部了!
Home Web Board ProblemSet Standing Status Statistics Problem B: 选举班干部了! Time Limit: 1 Sec Memory Li ...
- Problem C: 选举班干部了!
Problem C: 选举班干部了! Description 新学期伊始,某班要通过竞争上岗方式竞选班干部.包括班长.团支书等.现在需要你来设计2个类Student和StudentCadre来模拟这一 ...
- Problem D: 选举班干部了!
Problem D: 选举班干部了! Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1669 Solved: 961 [ Submit][ St ...
- SDUSTOJ1780 Problem E: 选举班干部了!
Description 新学期伊始,某班要通过竞争上岗方式竞选班干部.包括班长.团支书等.现在需要你来设计2个类Student和StudentCadre来模拟这一过程. 1.Student类是学生类, ...
- python集合操作班级干部竞选演讲稿_精选竞选班干部的演讲稿集合7篇
精选竞选班干部的演讲稿集合7篇 演讲稿在写作上具有一定的格式要求.在现实社会中,用到演讲稿的地方越来越多,为了让您在写演讲稿时更加简单方便,以下是小编整理的竞选班干部的演讲稿7篇,欢迎阅读与收藏. 竞 ...
- 计算机学校班干部竞选演讲稿,竞选班干部演讲稿三分钟范文5
不要怕推销自己,只要你认为自己有才华,你就应该认为自己有资格提任.那么,竞选班干部演讲稿三分钟范文怎么写?以下是小编精心收集整理的竞选班干部演讲稿三分钟范文,下面小编就和大家分享,来欣赏一下吧. 竞选 ...
- 校园现金元外交 小学生用压岁钱打点班干部
校园现"金元"外交 小学生用压岁钱"打点"班干部 2007年03月20日 来源:东北新闻网-沈阳今报 [非常现象] 新学期开始,小学班干部面临局部&quo ...
- python集合操作班级干部竞选演讲稿_实用的竞选班干部演讲稿集合八篇
实用的竞选班干部演讲稿集合八篇 演讲稿在写作上具有一定的格式要求.在社会发展不断提速的今天,演讲稿对我们的作用越来越大,大家知道演讲稿的格式吗?下面是小编精心整理的竞选班干部演讲稿8篇,仅供参考,大家 ...
- 计算机学校班干部竞选演讲稿,精选:2019学校班干部个人竞选演讲稿范文五篇...
<2019学校班干部个人竞选演讲稿范文五篇.doc>由会员分享,可免费在线阅读全文,更多与<2019学校班干部个人竞选演讲稿范文五篇>相关文档资源请在帮帮文库(www.woc8 ...
最新文章
- ssh远程操作服务器
- sql中去掉换行符和回车符
- 联通和阿里云合作 试点打通全国IT系统
- MapReduce案例-wordcount-Reduce阶段代码
- 微型计算机具有什么等特点,微机原理 课后题 标准答案
- sqlite管理工具_Liquibase 数据库版本管理工具:1.安装
- ZZULIOJ 1107: 回文数猜想(函数专题)
- 深入Python字典的内部实现
- 服务器进入bios用u盘启动不了系统,用u盘装系统,进入bios后没有usb启动项怎么办...
- java 程序简介
- mac搭建k8s练习环境
- js常用设计模式实现(一)单例模式
- php mysql购物车代码_php购物车实现代码实例汇总
- 数据库系统概论(第五版) 王珊 第一章课后习题答案
- 汽车故障诊断方法及注意事项
- egret 微信小游戏 分享游戏截图
- u盘怎么进入pe系统并修改系统密码
- 2020最受欢迎主动降噪蓝牙耳机盘点,五款性能超强蓝牙耳机推荐
- vue-cropper实现图片裁剪上传
- 罗马数字 古罗马数字转换为阿拉伯数字