您的位置:首页 > 编程语言 > C语言/C++

3-5 学生成绩统计

2016-10-23 11:11 113 查看


3-5 学生成绩统计

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic


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
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

class student
{
private:
int n,m,e,c;
char name[11];
public:
int sum();
double average();
void input();
void output();
};

int student :: sum()
{
return (m + e + c);
}

double student :: average()
{
return ((m + e + c) / 3.0);
}

void student :: input()
{
cin>>n>>name>>m>>e>>c;
}

void student :: output()
{
cout<<n<<'\t'<<name<<'\t'<<m<<'\t'<<e<<'\t'<<c<<'\t'<<sum()<<'\t';
printf("%.1lf\n",average());
}

int main()
{
int i;
student s[5];
for(i = 0;i < 5;i++)
s[i].input();
cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl;
cout<<endl;
cout<<"StuID"<<'\t'<<"Name"<<'\t'<<"Math"<<'\t'<<"Eng"<<'\t'<<"Com"<<'\t'<<"Total"<<'\t'<<"Average"<<endl;
for(i = 0;i < 5;i++)
s[i].output();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++