大學C語言實訓課,C語言學生成績管理系統。
#include<stdio.h>
#include<string.h>
#include<math.h>
struct student
{
int num;
char name[20];
float pingshi;
float shiyan;
float kaoshi;
double zongping;
}stu[4];
void main()
{
void a();
void b();
void c();
void d();
void e();
int n;
while(n!=6)
{ printf("\t大學計算機基礎成績管理系統\n");
printf("1:輸入一個班學生大學計算機基礎成績記錄\n");
printf("2:顯示所有成績記錄\n");
printf("3:計算並輸出平均成績,均方差\n");
printf("4:輸出成績與排名\n");
printf("5:結果存入文件chengji.txt\n");
printf("6:退出系統\n");
printf("輸入選項代碼:");
scanf("%d",&n);
switch(n)
{
case 1:a();break;
case 2:b();break;
case 3:c();break;
case 4:d();break;
case 5:e();break;
case 6:printf("\n*******************謝謝使用!*******************\n");break;
break;
}
}
getchar();
}
/* 子 函 數*/
void a() /* 輸入一個班的學生記錄*/
{
int i;
for(i=0;i<4;i++)
{
printf("請輸入學號 姓名 平時成績 實驗成績 考試成績:");
scanf("%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].pingshi,&stu[i].shiyan,&stu[i].kaoshi);
}for(i=0;i<4;i++)
stu[i].zongping=0.1*stu[i].pingshi+0.3*stu[i].shiyan+0.6*stu[i].kaoshi;
}
void b()/* 顯示所有記錄*/
{
int i;
printf("學號 姓名 平時成績 實驗成績 考試成績 總評成績\n");
for(i=0;i<4;i++)
printf("%d%14.2s%14.2f%14.2f%14.2f%14.2f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaoshi,stu[i].zongping);
}
void c()/* 求出全班平均成績,顯示均方差*/
{
int a[4]={0,1,2,3};
int i,j;
double total=0,pfc=0,bzc=0;
double ave;
for(i=0;i<4;i++)
{
total=total+stu[i].zongping;
}
ave=total/4.0;
printf("總評平均成績是%f\n",ave);
for(i=0;i<4;i++)
{
pfc=pow((stu[i].zongping-ave),2)/4;
}
bzc=sqrt(pfc);
printf("\n平方差是%f\n",pfc);
printf("\n標準差是%f\n",bzc);
}
void d()
{
int a[4]={0,1,2,3};
int i,j,temp;
for(j=0;j<3;j++)
{
for(i=0;i<3-j;i++)
if(stu[a[i]].zongping>stu[a[i+1]].zongping)
{
temp=a[i];a[i]=a[i+1];
a[i+1]=temp;
}
}
printf("順序爲:\n");
printf("學號 姓名 總評成績\n");
for(i=0;i<4;i++)
printf("%d%10.2s%15.2f\n",stu[a[i]].num,stu[a[i]].name,stu[a[i]].zongping);
printf("\n");
}
void e()
{int i;
FILE *fp;
fp=fopen("chengji.txt","w");
fprintf(fp,"學號 姓名 平時成績 實驗成績 考試成績 總評成績\n");
for(i=0;i<4;i++)
fprintf(fp,"%d%14.2s%14.2f%14.2f%14.2f%14.2f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaoshi,stu[i].zongping);
printf("\n\n*******************恭喜,保存完成!*******************\n\n");
}
簡單記錄。
關注微信公衆號“資料在線”,回覆“C語言源碼”,即可獲得C語言源碼包。
更多資源等着你