#include <stdio.h>#include<string.h>typedef struct student{ long studentID; char studentname[10]; char studentsex; int studentage; int score[6]; int studentsum;}STUDENT;int main(void){ void InputScore(STUDENT stu[],int n,int m); void TallSort(STUDENT stu[],int n,int m); void NumberSearch(STUDENT stu[],int n,int m); void PrintScore(STUDENT stu[],int n,int m); STUDENT stu[30]; int n,m,x; int coursesum[30]; printf("How many student?\n"); scanf("%d",&n); printf("How many subject?\n"); scanf("%d",&m); do{ printf("1.录入学生信息\n"); printf("2.按科目总分排名\n"); printf("3.按学号查询学生信息\n"); printf("4.学生信息修改\n"); printf("5.学生信息删除\n"); printf("6.List record\n"); printf("0.Exit\nPlease enter your choice:"); scanf("%d",&x); getchar(); switch(x) { case 0: return 0; case 1: InputScore(stu,n,m); break; case 2: TallSort(stu,n,m); break; case 3: NumberSearch(stu,n,m); break; case 6: PrintScore(stu,n,m); } }while(1);}/*------------录入学生信息子程序------------*/void InputScore(STUDENT stu[],int n,int m){ int i,j; for (i = 0;i < n;i++) { stu[i].studentsum = 0; printf("录入学生信息 %d:\n",i+1); scanf("%ld",&stu[i].studentID); getchar(); scanf("%s",&stu[i].studentname); scanf("%s",&stu[i].studentsex); scanf("%s",&stu[i].studentage); for(j = 0;j < m;j++) { scanf("%d",&stu[i].score[j]); stu[i].studentsum = stu[i].studentsum + stu[i].score[j]; } }}void StudentScore(STUDENT stu[],float studentaver[],int n, int m){ int i,j; for(i = 0;i < n;i++) { stu[i].studentsum ; printf("%s's sum is %d\n",stu[i].studentname,stu[i].studentsum); }}/*------------按科目总分排序子程序------------*/void TallSort(STUDENT stu[],int n,int m){ int i,j; STUDENT temp; for(i = 0;i < n-1;i++) { for(j = i+1;j < n;j++) { if(stu[i].studentsum < stu[j].studentsum) { temp = stu[j]; stu[j] = stu[i]; stu[i] = temp; } } } for(i = 0;i < n;i++) { printf("%4d%4d%8s%8s%4d%4d\n",i+1, stu[i].studentID,stu[i].studentname,stu[i].studentsex,stu[i].studentage,stu[i].studentsum); }}/*------------按学号查询子程序------------*/void NumberSearch(STUDENT stu[],int n,int m){ int pos; long a; printf("Input the searching ID:"); scanf("%ld",&a); pos = Search1(stu,a,n,m); if(pos != -1){ //return 0; }else{ printf("no found\n"); }}int Search1(STUDENT stu[],long a,int n,int m){ int i,j; STUDENT temp; for(i = 0;i < n-1;i++) { for(j = i+1;j < n;j++) { if(stu[i].studentsum < stu[j].studentsum) { temp = stu[j]; stu[j] = stu[i]; stu[i] = temp; } } } for(i = 0;i < n;i++) { if(stu[i].studentID == a){ printf("name = %d,ID = %d,sex = %s,age = %d,score = %d,rank = %d\n",stu[i].studentID,stu[i].studentname,stu[i].studentsex,stu[i].studentage,stu[i].studentsum,i+1); return 1; }} return -1;}/*------------打印成绩子程序------------*/void PrintScore(STUDENT stu[],int n,int m){ int i,j; for(i = 0;i < n;i++) { printf("%10d%8s",stu[i].studentID,stu[i].studentname); for(j = 0;j < m;j++) { printf("%4d",stu[i].score[j]); } printf(" sum is %d\n",stu[i].studentsum); }}
- 3 回答
- 1 关注
- 1451 浏览
添加回答
举报
0/150
提交
取消