3-5 学生成绩统计

来源:互联网 发布:js点击跳转到指定页面 编辑:程序博客网 时间:2024/04/29 21:33

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 931002 Mary 93 95 981003 Luis 90 85 981004 Sam 91 95 981005 Lily 87 98 99

Example Output

Input the messages of five students(StudentID Name Math English Computer )StuIDNameMathEngComTotalAverage1001Andy89909327290.71002Mary93959828695.31003Luis90859827391.01004Sam91959828494.71005Lily87989928494.7
#include <iostream>
#include <iomanip>  //使用 setprecision 的头文件
using namespace std;
class Student
{
    int stuID;
    string name;
    int math;
    int english;
    int computer;
    public:
    void intput(int a,string e,int b,int c,int d)
    {
        stuID=a;
        name=e;
        math=b;
        english=c;
        computer=d;
    }
    double ave()
    {
        return (math+english+computer)/3.0;
    }
    void output()
    {
        cout<<stuID<<"\t"<<name<<"\t"<<math<<"\t"<<english<<"\t"<<computer<<"\t";
        cout<<math+english+computer<<"\t"<<fixed<<setprecision(1)<<ave()<<endl;
    }
};
int main()
{
    int a,b,c,d;
    string e;
    Student stu[6];
    for(int i=0;i<5;i++)
    {
        cin>>a>>e>>b>>c>>d;
        stu[i].intput(a,e,b,c,d);
    }
    cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl;
    cout<<endl;
    cout<<"StuID\tName\tMath\tEng\tCom\tTotal\tAverage"<<endl;
    for(int i=0;i<5;i++)
    {
        stu[i].output();
    }
    return 0;
}
原创粉丝点击