求解这道C语言题目如何解答
定义学生结构体类型,其成员包括学号、姓名、3门课的成绩(1)用一个函数input从键盘输入5个学生的数据(2)用一个函数average求每个学生的总平均分(3)用一个函数...
定义学生结构体类型,其成员包括学号、姓名、3门课的成绩
(1) 用一个函数input从键盘输入5个学生的数据
(2) 用一个函数average求每个学生的总平均分
(3) 用一个函数max找出总分最高学生的数据
(4) 输出3门课总平均成绩,以及最高分学生的数据 展开
(1) 用一个函数input从键盘输入5个学生的数据
(2) 用一个函数average求每个学生的总平均分
(3) 用一个函数max找出总分最高学生的数据
(4) 输出3门课总平均成绩,以及最高分学生的数据 展开
2个回答
展开全部
#include <iostream>
using namespace std;
struct student
{
char stu_num[4];
char stu_name[15];
int score1,score2,score3;
}stu[5];
void max_stu(student *stu)
{
int max_score=0,max_ID,tot_score[5];
for(int i=0;i!=5;i++)
{
tot_score[i]=stu[i].score1+stu[i].score2+stu[i].score3;
}
for(int i=0;i!=5;i++)
{
if(max_score<=tot_score[i])
{
max_score=tot_score[i];
max_ID=i;
}
}
cout<<"The highest score is "<<max_score<<endl;
cout<<"********INFORMATION********"<<endl;
cout<<"Student ID:"<<stu[max_ID].stu_num<<endl;
cout<<"Sutdent name:"<<stu[max_ID].stu_name<<endl;
cout<<"Score 1:"<<stu[max_ID].score1<<endl;
cout<<"Score 2:"<<stu[max_ID].score2<<endl;
cout<<"Score 3:"<<stu[max_ID].score3<<endl;
}
void average(student *stu)
{
float ave[5];
for(int i=0;i!=5;i++)
{
ave[i]=(stu[i].score1+stu[i].score2+stu[i].score3)/3.0;
}
for(int i=0;i!=5;i++)
{
cout<<"Average of Student "<<i+1<<" is "<<ave[i]<<endl;
}
cout<<endl;
cout<<endl;
}
void input(student *stu)
{
for(int i=0;i!=5;i++)
{
cout<<"Student "<<i+1<<":"<<endl;
cout<<"Student ID:";
gets(stu[i].stu_num);
cout<<"Student name:";
gets(stu[i].stu_name);
cout<<"Score 1:";
cin>>stu[i].score1;
cout<<"Score 2:";
cin>>stu[i].score2;
cout<<"Socre 3:";
cin>>stu[i].score3;
getchar();
}
average(stu);
max_stu(stu);
}
int main()
{
input(stu);
getchar();
getchar();
return 0;
}
using namespace std;
struct student
{
char stu_num[4];
char stu_name[15];
int score1,score2,score3;
}stu[5];
void max_stu(student *stu)
{
int max_score=0,max_ID,tot_score[5];
for(int i=0;i!=5;i++)
{
tot_score[i]=stu[i].score1+stu[i].score2+stu[i].score3;
}
for(int i=0;i!=5;i++)
{
if(max_score<=tot_score[i])
{
max_score=tot_score[i];
max_ID=i;
}
}
cout<<"The highest score is "<<max_score<<endl;
cout<<"********INFORMATION********"<<endl;
cout<<"Student ID:"<<stu[max_ID].stu_num<<endl;
cout<<"Sutdent name:"<<stu[max_ID].stu_name<<endl;
cout<<"Score 1:"<<stu[max_ID].score1<<endl;
cout<<"Score 2:"<<stu[max_ID].score2<<endl;
cout<<"Score 3:"<<stu[max_ID].score3<<endl;
}
void average(student *stu)
{
float ave[5];
for(int i=0;i!=5;i++)
{
ave[i]=(stu[i].score1+stu[i].score2+stu[i].score3)/3.0;
}
for(int i=0;i!=5;i++)
{
cout<<"Average of Student "<<i+1<<" is "<<ave[i]<<endl;
}
cout<<endl;
cout<<endl;
}
void input(student *stu)
{
for(int i=0;i!=5;i++)
{
cout<<"Student "<<i+1<<":"<<endl;
cout<<"Student ID:";
gets(stu[i].stu_num);
cout<<"Student name:";
gets(stu[i].stu_name);
cout<<"Score 1:";
cin>>stu[i].score1;
cout<<"Score 2:";
cin>>stu[i].score2;
cout<<"Socre 3:";
cin>>stu[i].score3;
getchar();
}
average(stu);
max_stu(stu);
}
int main()
{
input(stu);
getchar();
getchar();
return 0;
}
追问
额,你给我的程序是C++的,不适用于c语言,你能给我一个适用于C语言的啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询