sdut oj3-5 学生成绩统计

来源:互联网 发布:画平面图软件 编辑:程序博客网 时间:2024/05/23 12:04

题目链接:点击打开链接

3-5 学生成绩统计
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description

通过本题目练习可以掌握对象数组的用法,主要是对象数组中数据的输入输出操作。

设计一个学生类Student 它具有私有的数据成员:学号、姓名、数学成绩、英语成绩、计算机成绩;具有公有的成员函数:求三门课总成绩的函数int sum(); 求三门课平均成绩的函数 double average(); 输出学生基本信息、总成绩和平均成绩的函数 void print(); 设置学生数据信息的函数void set_stu_info(int n,char *p,int m,int e,int c)。

请编写主函数,建立学生对象数组,从键盘输入一组学生数据,输出学生的成绩统计表:

stuID 姓名 数学 英语 计算机 总成绩 平均成绩

001 xxx 90 85 95 270 90.0

 

002 yyy 95 98 92 285 95.0
Input

输入数据有5行,代表5个学生的信息。

每行有5个数据,数据间用一个空格分隔,分别代表学生的学号、姓名、数学成绩、英语成绩和计算机成绩。除了姓名是符号串外,其他均为整型数据,数据在int类型范围内。
Output

输出数据一共有7行。

第一行输出提示信息“Input the messages of five students(StudentID Name Math English Computer )”

第二行输出一个空行,进行输入输出间的间隔

第三行输出表头“StuID Name Math Eng Com Total Average” ,这一行有7个数据,数据间用制表符’\t’分隔,分别代表学生的学号、姓名、数学成绩、英语成绩、计算机成绩、总成绩和平均成绩。其中平均成绩为实型数据,保留1位小数。

第4-8行分别输出5个学生的相关数据。每个数据占一个制表符的空间。格式同上。
Example Input

1001 Andy 89 90 93
1002 Mary 93 95 98
1003 Luis 90 85 98
1004 Sam 91 95 98
1005 Lily 87 98 99

Example Output

Input the messages of five students(StudentID Name Math English Computer )

StuID    Name    Math    Eng    Com    Total    Average
1001    Andy    89    90    93    272    90.7
1002    Mary    93    95    98    286    95.3
1003    Luis    90    85    98    273    91.0
1004    Sam    91    95    98    284    94.7
1005    Lily    87    98    99    284    94.7

Hint

代码实现:

#include <iostream>#include <string.h>#include <iomanip>using namespace std;const int maxn=10000+1000;class Stud{private:    string name;    int num,math,eng,com;public:    int sum()    {        return math+eng+com;    }    double average()    {        return sum()*1.0/3;    }    void set_stu_info(int n,string p,int m,int e,int c)    {        num = n;math = m;        eng = e;com = c;name = p;    }    void print()    {        cout<<num<<"\t"<<name<<"\t"<<math<<"\t"<<eng<<"\t"<<com<<"\t"<<sum()<<"\t";        cout<<fixed<<setprecision(1)<<average()<<endl;    }};int main(){    cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl;    Stud stu[maxn];    for(int i=0;i<5;i++)    {        int a, b, c, d;        string e;        cin>>a>>e>>b>>c>>d;        stu[i].set_stu_info(a, e, b, c, d);    }    cout<<endl;    cout<<"StuID\tName\tMath\tEng\tCom\tTotal\tAverage"<<endl;    for(int i=0;i<5;i++)    {        stu[i].print();    }    return 0;}


0 0
原创粉丝点击