首页 > 其他分享 >Problem D: 我们来做个Student类吧!

Problem D: 我们来做个Student类吧!

时间:2023-05-29 14:05:43浏览次数:29  
标签:whose Student int id 88 student Problem 我们 name


Home

Web Board

ProblemSet

Standing

Status

Statistics


Problem D: 我们来做个Student类吧!


Time Limit: 1 Sec   Memory Limit: 128 MB

Submit: 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,


[ 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 <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;
}



标签:whose,Student,int,id,88,student,Problem,我们,name
From: https://blog.51cto.com/u_16129621/6370402

相关文章

  • Problem A: 整型数组运算符重载
    HomeWebBoardProblemSetStandingStatusStatisticsProblemA:整型数组运算符重载TimeLimit:1Sec  MemoryLimit:128MBSubmit:1458  Solved:954[Submit][Status][WebBoard]Description定义Array类:1.拥有数据成员intlength和int*mems,分别是数......
  • Problem D: 字符构成的图形
    HomeWebBoardProblemSetStandingStatusStatisticsProblemD:字符构成的图形TimeLimit:1Sec  MemoryLimit:128MBSubmit:1342  Solved:832[Submit][Status][WebBoard]Description定义CharGraph类,用于输出一个由指定字符组成的图形。该类包括:1......
  • Problem A: 克隆人来了!
    HomeWebBoardProblemSetStandingStatusStatisticsProblemA:克隆人来了!TimeLimit:1Sec  MemoryLimit:128MBSubmit:1979  Solved:1072[Submit][Status][WebBoard]Description克隆技术飞速发展,克隆人已经成为现实了!!所以,现在由你来编写一个Pe......
  • Problem L: STL——字符串排序
    HomeWebBoardProblemSetStandingStatusStatisticsProblemL:STL——字符串排序TimeLimit:1Sec  MemoryLimit:128MBSubmit:3482  Solved:1666[Submit][Status][WebBoard]Description  对N个字符串排序。  0<N<=5000......
  • Problem G: 时间类的12小时制输出
    HomeWebBoardProblemSetStandingStatusStatisticsProblemG:时间类的12小时制输出TimeLimit:4Sec  MemoryLimit:128MBSubmit:4541  Solved:2405[Submit][Status][WebBoard]Description封装一个时间类Time,用于时间处理的相关功能,支持24......
  • Problem F: 时间类的常量
    HomeWebBoardProblemSetStandingStatusStatisticsProblemF:时间类的常量TimeLimit:4Sec  MemoryLimit:128MBSubmit:2103  Solved:1715[Submit][Status][WebBoard]Description封装一个时间类Time,用于时间处理的相关功能,支持以下操作:......
  • Problem A: 平面上的点和线——Point类、Line类 (I)
    HomeWebBoardProblemSetStandingStatusStatisticsProblemA:平面上的点和线——Point类、Line类(I)TimeLimit:1Sec  MemoryLimit:128MBSubmit:3609  Solved:2357[Submit][Status][WebBoard]Description在数学上,平面直角坐标系上的点......
  • Problem B: 类的初体验(II)
    HomeWebBoardProblemSetStandingStatusStatisticsProblemB:类的初体验(II)TimeLimit:1Sec  MemoryLimit:128MBSubmit:715  Solved:653[Submit][Status][WebBoard]Description定义一个类Data,只有一个double类型的属性和如下3个方法:1. 带1......
  • Problem D: 类的初体验(IV)
    HomeWebBoardProblemSetStandingStatusStatisticsProblemD:类的初体验(IV)TimeLimit:1Sec  MemoryLimit:128MBSubmit:1075  Solved:657[Submit][Status][WebBoard]Description定义一个类Data,只有一个int类型的属性和如下方法:1. 缺省构造......
  • Problem A: 平面上的点——Point类 (I)
    ProblemA:平面上的点——Point类(I)TimeLimit:1Sec  MemoryLimit:4MBSubmit:8255  Solved:3705[Submit][Status][WebBoard]Description在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上......