Problem D: 我们来做个Student类吧!
来源:互联网 发布:2017年网络电视剧 编辑:程序博客网 时间:2024/06/03 21:06
HomeWeb BoardProblemSetStandingStatusStatistics
Submit: 1052 Solved: 585
[Submit][Status][Web Board][Submit][Status][Web Board]
Problem D: 我们来做个Student类吧!
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1052 Solved: 585
[Submit][Status][Web Board]
Description
请定义一个Student类,有4个属性:
1.char *name:姓名。
2.int numOfScores:课程数量
3.int *scores:所有课程的成绩。
4.int id:学生的编号。
只有3个方法:
1. 构造函数
2.析构函数
3.void Student::showStudent()方法:用于输出学生的信息。
请根据样例输出,写出该类的实现。
Input
输入分为多行。
第一行包含3个正整数M,N和P:其中M表明之后输入的测试用例数量;N表示每个人姓名的最大长度;P表示学生学习的课程的数量。
之后有M行,包含一个学生姓名(没有任何空白符)、P门课程的成绩。
Output
见样例。
注意:所有的输出两两之间用一个空格隔开,且每行输出的首尾都没有空格。
Sample Input
3 10 5Tom 60 61 72 56 89Jack 99 100 98 89 77Mary 88 88 88 88 88
Sample Output
A student whose name is "Tom" and id is 1 is created!This student is "Tom" whose id is 1.This student's scores are: 60 61 72 56 89A student whose name is "Tom" and id is 1 is erased!A student whose name is "Jack" and id is 2 is created!This student is "Jack" whose id is 2.This student's scores are: 99 100 98 89 77A student whose name is "Jack" and id is 2 is erased!A student whose name is "Mary" and id is 3 is created!This student is "Mary" whose id is 3.This student's scores are: 88 88 88 88 88A student whose name is "Mary" and id is 3 is erased!
HINT
Append Code
append.cc,
한국어< 中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include <iostream>#include <iomanip>using namespace std; int id=0;class Student{private: char *name; int numOfScores; int *scores;public: Student(char *ch,int *a,int b):name(ch),scores(a),numOfScores(b) { id++; cout << "A student whose name is \"" << name << "\" and id is " << id << " is created!" << endl; } ~Student() { cout << "A student whose name is \"" << name <<"\" and id is " << id << " is erased!" << endl; } void showStudent() { cout << "This student is \"" << name << "\" whose id is " << id << "." << endl; cout << "This student's scores are:"; for(int i=0;i<numOfScores;i++) cout << " " << scores[i]; cout << endl; }}; int main(){ int cases; char *str; int maxLenOfString, numOfCourses; int *scores; cin>>cases>>maxLenOfString>>numOfCourses; str = new char[maxLenOfString + 1]; scores = new int[numOfCourses]; for (int i = 0; i < cases; i++) { cin>>str; for (int j = 0; j < numOfCourses; j++) cin>>scores[j]; Student stu(str,scores,numOfCourses); stu.showStudent(); } return 0;}
0 0
- Problem D: 我们来做个Student类吧!
- 903AHungry Student Problem
- A. Hungry Student Problem
- Problem D: Person类与Student类的关系(C++期末)
- Problem D
- Problem D
- Problem D
- problem D
- Problem D
- Problem D
- Problem D
- Problem D
- Problem-D
- Problem D
- Problem D
- Problem D
- Problem D
- Problem-D
- How tomcat works——20 基于JMX的管理
- Hive安装配置指北(含Hive Metastore详解)
- linux下的普通文件的递归统计
- Problem C: 选举班干部了!
- mysql不能插入中文字符以及中文显示乱码问题
- Problem D: 我们来做个Student类吧!
- 使用对象进行分页显示
- Hbase架构概述
- Wireshark抓包系列教程之二:HTTP协议分析
- Apache Tomcat、Tomcat、Apache
- Problem E: 质心算法
- 关于机器学习的几个优秀教程
- 自动生成图像标签代码
- Pycharm快捷键