/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:汤善晔
*完成日期:2016年9月1日
*版本号:v1.0
*/
问题描述:建立一个简单的学生信息表,包括:姓名、性别、年龄及一门课程的成绩,统计输出学生的平均成绩和不及格同学姓名和不及格人数。
#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[],int n)
{
int i,d=0;
float pj,sum=0;
for(i=0;i<n;i++)
{
sum=stud[i].score+sum;
if(stud[i].score<60)
{
cout<<stud[i].name<<"不合格"<<endl;
d++;
}
}
pj=sum/n;
cout<<setprecision(1)<<setiosflags(iOS::fixed)<<"平均成绩为:"<<pj<<endl;
cout<<"不合格人数为:"<<d;
}
int main()
{
struct student stud[100];
int n;
cin>>n;
input(stud,n); //输入n个学生的信息
total(stud,n); //统计并输出平均成绩和不及格同学姓名和不及格人数
return 0;
}