• sdut 3-5 学生成绩统计


    3-5 学生成绩统计

    Time Limit: 1000MS Memory limit: 65536K

    题目描写叙述

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

    设计一个学生类Student它具有私有的数据成员:学号、姓名、数学成绩、英语成绩、计算机成绩;具有公有的成员函数:求三门课总成绩的函数int sum();求三门课平均成绩的函数double average();输出学生基本信息、总成绩和平均成绩的函数void print()设置学生数据信息的函数voidset_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

    输入

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

    每行有5个数据,数据间用一个空格分隔,分别代表学生的学号、姓名、数学成绩、英语成绩和计算机成绩。

    除了姓名是符号串外,其它均为整型数据,数据在int类型范围内。

    输出

    输出数据一共同拥有7行。

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

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

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

    4-8行分别输出5个学生的相关数据。每一个数据占一个制表符的空间。

    格式同上。

    演示样例输入

    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

    演示样例输出

    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>//c语言输入输出头文件
    #include<cstring>//字符串操作头文件
    
    using namespace std;
    //定义一个学生类
    class student
    {
    private://私有
        int sno,math,english,computer;
        char name[100];
    
    public://公有
        void input(int id, char *s, int a, int b, int c)//输入函数   注意:别忘了*号
        {
            sno=id;
            strcpy(name,s);//字符串复制
            math=a;
            english=b;
            computer=c;
        }
    
        void output()//输出函数
        {
            printf("%d	%s	%d	%d	%d	%d	%.1f
    ",sno,name,math,english,computer,math+english+computer,(math+english+computer)*1.0/3.0);
        }
    };
    
    int main()//主函数
    {
        int i;
        int sno,math,english,computer;
        char name[100];
        student stu[5];
        for(i=0; i<5; i++)//输入五个学生信息
        {
            cin>>sno>>name>>math>>english>>computer;
            stu[i].input(sno,name,math,english,computer);
        }
        cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl<<endl;
        cout<<"StuID"<<"	"<<"Name"<<"	"<<"Math"<<"	"<<"Eng"<<"	"<<"Com"<<"	"<<"Total"<<"	"<<"Average"<<endl;
        for(i=0; i<5; i++)//输出五个学生信息
        {
            stu[i].output();
        }
        return 0;
    }
    

    以下别人的:

    #include <iostream>
    #include<stdio.h>
    using namespace  std;
    class student
    {
    public:
    
        int sum();
        double average();
        void print();
        void set();
    private:
    
        int num;
        char name[20];
        int math;
        int eng;
        int com;
    };
    int student::sum()
    {
        return (math+eng+com);
    }
    double student::average()
    {
        return ((math+eng+com)/3.0);
    }
    void student::print()
    {
        cout<<num<<'	'<<name<<'	'<<math<<'	'<<eng<<'	'<<com<<'	'<<sum()<<'	';
        printf("%.1f",average());
        cout<<endl;
    }
    void student::set()
    {
        cin>>num>>name>>math>>eng>>com;
    }
    int main()
    {
        int i;
        student stu[5];
        for(i=0; i<=4; i++)
            stu[i].set();
        cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl;
        cout<<endl;
        cout<<"StuID"<<'	'<<"Name"<<'	'<<"Math"<<'	'<<"Eng"<<'	'<<"Com"<<'	'<<"Total"<<'	'<<"Average"<<endl;
        for(i=0; i<=4; i++)
            stu[i].print();
        return 0;
    }
    
    
    /**************************************
    	Problem id	: SDUT OJ E 
    	User name	: 
    	Result		: Accepted 
    	Take Memory	: 556K 
    	Take Time	: 0MS 
    	Submit Time	: 2014-09-30 08:43:56  
    **************************************/
    



  • 相关阅读:
    博客园电子期刊2009年6月刊发布
    今晚22:30~23:00博客程序更新
    博客园上海俱乐部活动通知(2009613)
    【意见征集补充】09'博客园T恤设计
    C# WinForm webBrowser 内嵌网页的按钮的OnClientClick事件的return false 在webBrowser中绑定onclick事件后 失效 的变通解决办法
    [转]VS2008中开发智能设备程序的一些总结收藏1
    [转]C#访问SQLite数据库
    [转]VS C# 怎么调试调试服务?
    [转]弹出窗口刷新它的父页面后。出现不重新发送信息,则无法刷新网页
    [转]外部css文件中的 BACKGROUNDIMAGE: url(..\image.gif)指定的背景图像无法显示,谁有好主意?
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5209598.html
Copyright © 2020-2023  润新知