學生成績管理系統

#include
#include <stdlib.h>
#define N 10
void Sort(struct StudentInfo Student[]);//提出函數
///////////////////////////////
///首先定義一個結構
//////////////////////////////
struct StudentInfo
{
int StudentID; //學號
char StudentName[20]; //姓名
float StudentMath; //數學成績
float StudentEnglish; //英語成績
float StudentComputer;//計算機成績
float StudentAve; //平均成績
float StudentScore; //總成績
};
int main(void)
{
struct StudentInfo Student[N];//定義學生和中間的交換值
int i;
for(i=0;i<N;i++)
{
printf("請輸入第%d個學生的學號\n",i+1);
scanf("%d",&Student[i].StudentID);//輸入學號
printf("請輸入第%d個學生的姓名\n",i+1);
scanf("%s",Student[i].StudentName);//輸入學生姓名
printf("請輸入第%d個學生的數學成績\n",i+1);
scanf("%f",&Student[i].StudentMath);//輸入學生成績
printf("請輸入第%d個學生的英語成績\n",i+1);
scanf("%f",&Student[i].StudentEnglish);//輸入學生英語成績
printf("請輸入第%d個學生的計算機基礎的成績\n",i+1);
scanf("%f",&Student[i].StudentComputer);//輸入學生機算計成績
Student[i].StudentScore = Student[i].StudentComputer+Student[i].StudentEnglish+Student[i].StudentMath;//邱總成績
Student[i].StudentAve = Student[i].StudentScore/3;//求平均成績
system("cls");
}
//排序
Sort(Student);
//輸出
printf("名次\t學號\t姓名\t數學\t英語\t計算機\t總\t平均\t\n");
for(i=0;i<N;i++)
{
printf("%d\t",i+1);
printf("%d\t",Student[i].StudentID);
printf("%s\t",Student[i].StudentName);
printf("%.1f\t",Student[i].StudentMath);
printf("%.1f\t",Student[i].StudentEnglish);
printf("%.1f\t",Student[i].StudentComputer);
printf("%.1f\t",Student[i].StudentScore);
printf("%.1f\t",Student[i].StudentAve);
printf("\n");
}
return 0;
}
///////////////////////////////////////////
///冒泡排序
///////////////////////////////////////////
void Sort(struct StudentInfo Student[])
{
struct StudentInfo Tmp;
int i,j;
for(i=0;i<N;i++)
{
for(j=i;j<N;j++)
{
if(Student[i].StudentScore<Student[j+1].StudentScore)//判斷總成績大小,將第j個排成成績最高
{
Tmp = Student[i];
Student[i]=Student[j+1];
Student[j+1] = Tmp;//交換順序
}
}
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章