YTU 2769: 结构体--成绩统计

2769: 结构体--成绩统计

时间限制: 1 Sec   内存限制: 128 MB
提交: 1021   解决: 530

题目描述

建立一个简单的学生信息表,包括:姓名、性别、年龄及一门课程的成绩,统计输出学生的平均成绩和不及格同学姓名和不及格人数。
根据给出的代码实现函数total,只需提交该函数。

#include<iostream>
#include<iomanip>
using namespace std;
struct student
{
    char name[20];
    char sex;
    int age;
    float score;
} ;

void input(struct student stud[],int n)
{
    int i;
    for(i=0; i<n; i++)
    {
        cin>>stud[i].name;  //输入姓名
        cin.get();
        cin>>stud[i].sex;   //输入性别
        cin>>stud[i].age;   //输入年龄
        cin>>stud[i].score; //输入成绩
    }
}


int main()
{
    struct student stud[100];
    int n;
    cin>>n;
    input(stud,n);  //输入n个学生的信息
    total(stud,n);  //统计并输出平均成绩和不及格同学姓名和不及格人数
    return 0;
}

输入

n 和 n个学生的姓名,性别,年龄,成绩

输出

学生的平均成绩和不及格同学姓名和不及格人数。

样例输入

3
zhangsan M 20 80
lisi F 19 59
wangwu F 20 100

样例输出

lisi不及格
平均成绩为:79.7
不及格人数为:1

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include<iostream>
#include<iomanip>
using namespace std;
struct student
{
    char name[20];
    char sex;
    int age;
    float score;
} ;
void input(struct student stud[],int n)
{
    int i;
    for(i=0; i<n; i++)
    {
        cin>>stud[i].name;  //输入姓名
        cin.get();
        cin>>stud[i].sex;   //输入性别
        cin>>stud[i].age;   //输入年龄
        cin>>stud[i].score; //输入成绩
    }
}
void total(struct student stud[100],int n)
{
    int s=0,i;
    float aver=0.0;
    for(i=0; i<n; i++)
    {
        if(stud[i].score<60)
        {
            cout<<stud[i].name<<"不及格"<<endl;
            s++;
        }
        aver+=stud[i].score;
    }
    cout<<"平均成绩为:"<<fixed<<setprecision(1)<<aver/n<<endl;
    cout<<"不及格人数为:"<<s<<endl;
}
int main()
{
    struct student stud[100];
    int n;
    cin>>n;
    input(stud,n);  //输入n个学生的信息
    total(stud,n);  //统计并输出平均成绩和不及格同学姓名和不及格人数
    return 0;
}

转载于:https://www.cnblogs.com/im0qianqian/p/5989562.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值