标签:odi arc tco lse print for core lag output
#include<stdio.h>
#define N 100
int Count=0;
struct stu
{
int num;
char name[20];
int computer;
int math;
int english;
float average;
};
void input(struct stu s[N]);
void output(struct stu s[N]);
void modify(struct stu s[N]);
void average(struct stu s[N]);
void sort(struct stu s[N]);
void search(struct stu s[N]);
void average(struct stu s[N])
{
int i;
for(i=0;i<Count;i++)
s[i].average=(s[i].computer+s[i].math+s[i].english)/3.0;
}
void sort(struct stu s[N])
{
int i,j,index;
struct stu temp;
for(i=0;i<Count-1;i++)
{
index=i;
for(j=i+1;j<Count;j++)
if(s[j].average>s[index].average)
index=j;
temp=s[index];
s[index]=s[i];
s[i]=temp;
}
output(s);
}
void input(struct stu s[N])
{
int i,n,flag=0;
while(flag==0){
printf("学生数量n(<=%d):",N);
scanf("%d",&n);
if(n!=0)flag=1;
else printf("学生数量不能为零!\n");
}
for(i=0;i<n;i++)
{
printf("1.学号:");
scanf("%d",&s[i].num);
printf("2.姓名:");
scanf("%s",&s[i].name);
printf("3.计算机成绩:");
scanf("%d",&s[i].computer);
printf("4.数学成绩:");
scanf("%d",&s[i].math);
printf("5.英语成绩:");
scanf("%d",&s[i].english);
Count++;
}
}
void output(struct stu s[N])
{
int i;
printf("成绩如下:\n");
printf("num\tname\tcomputer math\tenglish\taverage\t\n");
for(i=0;i<Count;i++)
{
printf("%d\t",s[i].num);
printf("%s\t",s[i].name);
printf("%d\t",s[i].computer);
printf("%d\t",s[i].math);
printf("%d\t",s[i].english);
printf("%.2f\n",s[i].average);
}
}
void modify(struct stu s[N])
{
int num,course,score,i;
printf("1.学号:\n");
scanf("%d",&num);
printf("2.课程(1:计算机,2:数学,3:英语):\n");
scanf("%d",&course);
printf("3.新的分数:\n");
scanf("%d",&score);
for(i=0;i<Count;i++)
if(s[i].num==num)
break;
switch(course)
{
case 1:s[i].computer=score;break;
case 2:s[i].math=score;break;
case 3:s[i].english=score;break;
}
s[i].average=(s[i].computer+s[i].math+s[i].english)/3.0;
printf("更改后该学生的成绩如下:\n");
printf("num\tname\tcomputer math\tenglish\taverage\t\n");
printf("%d\t",s[i].num);
printf("%s\t",s[i].name);
printf("%d ",s[i].computer);
printf("%d\t",s[i].math);
printf("%d\t",s[i].english);
printf("%.2f\n",s[i].average);
}
void search(struct stu s[N])
{
int i,flag=0,num;
printf("请输入您要查找的学生学号:\n");
scanf("%d",&num);
for(i=0;i<Count;i++)
if(s[i].num==num)
{
flag=1;
break;
}
if(flag)
{
printf("您所查找的学生成绩如下:\n");
printf("num\tname\tcomputer math\tenglish\taverage\t\n");
printf("%d\t",s[i].num);
printf("%s\t",s[i].name);
printf("%d\t",s[i].computer);
printf("%d\t",s[i].math);
printf("%d\t",s[i].english);
printf("%.2f\n",s[i].average);
}
else printf("学号错误!\n");
}
int main()
{
struct stu stu[N];
int num;
int n;
printf("您好,欢迎使用成绩信息系统!\n");
printf("请输入学生信息:\n");
input(stu);average(stu);
printf("成绩查询请输1,成绩更改请输2\n成绩排序请输3,退出系统请输0.\n");
scanf("%d",&n);
for(;;)
{
if(n==0)
{
printf("谢谢您的使用!");
return 0;
}
switch(n)
{
case 1:search(stu);break;
case 2:modify(stu);break;
case 3:sort(stu);break;
default :printf("输入错误!\n");break;
}
printf("成绩查询请输1,成绩更改请输2\n成绩排序请输3,退出系统请输0.\n");
scanf("%d",&n);
}
return 0;
}
标签:odi arc tco lse print for core lag output
原文地址:https://www.cnblogs.com/mathstudysharing/p/10153712.html