您的位置:首页 > 其它

3-5 学生成绩统计

2017-12-25 20:11 357 查看
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

Author

黄晶晶

#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
using namespace std;
class Student
{
private:int num,math,english,computer;
char name[20];
public:
int sum();
double average();
void set_stu_info(int n,char *p,int m,int e,int c);
void print();
};
void Student::set_stu_info(int n,char *p,int m,int e,int c)
{
num = n;
strcpy(name,p);
math = m;
english = e;
computer = c;
}
int Student::sum()
{
return math + english+computer;
}
double Student::average()
{
return (math+english+computer)*1.0/3;
}
void Student::print()
{
cout<<num<<'\t'<<name<<'\t'<<math<<'\t'<<english<<'\t'<<computer<<'\t'<<sum()<<'\t';
double y = average();
printf("%.1lf\n",y);
}
int main()
{
int i,num,m,e,c;
char a[20];
Student s[5];
cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl;
for(i = 0;i <5;i++)
{
cin>>num>>a>>m>>e>>c;
s[i].set_stu_info(num,a,m,e,c);
}
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].print();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: