16,472
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define N 100
struct stu{
char number[8];
char name[8];
char sex[2];
int yw,sx,yy,sum;
float ave;
};
void choose();
void creat(struct stu score[],int n);
void add(struct stu score[],int n);
void search(struct stu score[],int n);
void alter(struct stu score[],int n);
void del(struct stu score[],int n);
void sta(struct stu score[],int n);
void sort(struct stu score[],int n);
void print(struct stu score[],int n);
static int m;
void main(){
void choose();
printf("请输入人数:");
scanf("%d",&m);
}
void choose(struct stu score[],int n){
int p;
printf(" 学生成绩管理系统");
printf("1.创建学生的资料 2.追加学生的资料");
printf("3.查询学生的资料 4.修改学生的资料");
printf("5.删除学生的资料 6.统计学生的资料");
printf("7.对学生资料进行排序");
printf("***欢迎进入成绩管理系统,请选择您所要的操作(按任意键退出):");
scanf("%d",&p);
while(p>=1&&p<=7){
switch(p){
case 1:creat(score,n);break;
case 2:add(score,n);break;
case 3:search(score,n);break;
case 4:alter(score,n);break;
case 5:del(score,n);break;
case 6:sta(score,n);break;
case 7:sort(score,n);break;
default :exit(0);
}
printf("请选择您所要的操作:");
scanf("%d",&p);
}
}
void creat(struct stu score[],int n){
int i;
for(i=0;i<m;i++){
printf("请依次输入第%d个学生的学号、姓名、性别、语文、数学、英语、总成绩、平均成绩:\n");
scanf("%c%c%c%d%d%d%f%f",
&score[i].number,&score[i].name,&score[i].sex,&score[i].yw,&score[i].sx,
&score[i].yy,&score[i].sum,&score[i].ave);
}
void add(struct stu score[],int n){
int i;
int q;
printf("要添加的人数:");
scanf("%d",&q);
for(i=0;i<q;i++){
printf("请依次输入要添加的第%d个学生的学号、姓名、性别、语文、数学、英语、总成绩、平均成绩:\n");
scanf("%c%c%c%d%d%d%f%f",
&score[m+i].number,&score[m+i].name,&score[m+i].sex,&score[m+i].yw,&score[m+i].sx,
&score[m+i].yy,&score[m+i].sum,&score[m+i].ave);
m=m+q;
}
}
void search(struct stu score[],int n){
char q;int i;
printf("输入要查询的学生的姓名或学号:");
scanf("%c",&q);
for(i=0;i<m;i++){
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
printf("%c%c%c%d%d%d%f%f",
score[i].number,score[i].name,score[i].sex,score[i].yw,score[i].sx,score[i].yy,score[i].sum,score[i].ave);
}
}
void alter(struct stu score[],int n){
char q;int i;
printf("资料要修改的学生的姓名或学号:");
scanf("%c",&q);
for(i=0;i<m;i++){
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0){
printf("请重新依序输入该学生资料(学号、姓名、性别、语文、数学、英语、总成绩、平均成绩):");
scanf("%c%c%c%d%d%d%f%f",
&score[i].number,&score[i].name,&score[i].sex,&score[i].yw,&score[i].sx,
&score[i].yy,&score[i].sum,&score[i].ave);
}
}
}
void del(struct stu score[],int n){
char q;
int i,j;
printf("要删除的学生的姓名或学号:");
scanf("%c",&q);
for(i=0;i<m;i++){
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0){
for(j=i;j<m-1;j++){
score[j].number=score[j+1].number;
score[j].name=score[j+1].name;
score[j].sex=score[j+1].sex;
score[j].yw=score[j+1].yw;
score[j].sx=score[j+1].sx;
score[j].yy=score[j+1].yy;
score[j].sum=score[j+1].sum;
score[j].ave=score[j+1].ave;
}
}
}
void sta(struct stu score[],int n)
{
int i;
for(i=0;i<m;i++)
{
score[i].sum=score[i].yw+score[i].sx+score[i].yy;
score[i].ave=(float)score[i].sum/3;
}
}
void sort(struct stu score[],int n){
int i,j;
struct stu t;
for(i=0;i<m-1;i++){
for(j=i+1;j<m;j++){
if(score[i].ave<score[j].ave)
t=score[i],score[i]=score[j],score[j]=t;
}
}
}
void print(struct stu score[],int n)
{
int i;
for(i=0;i<m;i++)
printf("%c%c%c%d%d%d%f%f",
score[i].number,score[i].name,score[i].sex,score[i].yw,score[i].sx,score[i].yy,score[i].ave);
}