当前位置:编程学习 > C/C++ >>

帮忙编写个学生成绩管理系统,只能用c语言,不能用C++!

要求:用C语言!只能用C语言!能输入成绩和学号,查询,修改,求平均数,优秀率,谢了!
追问:#include <stdio.h>
#include <string.h>
#define N 100
void menu();
int dedao();
int add();
void modify(struct STUDENT shu[],int len);
int uninque(struct STUDENT shu[],int len,int xuehao);
void shuchu(struct STUDENT shu[],int len);
void send(struct STUDENT shu[],int len);
int readFromFile(struct STUDENT shu[]);
void chaxun(struct STUDENT shu[],int len);
void paixu(struct STUDENT shu[],int len);
void average(struct STUDENT shu[], int len);

struct STUDENT
{
   int num;
   char name[10];
   float score;
};
int main()
{
 static int len=0,choice;
 struct STUDENT shu[100];
    while(1)
 {
  menu();
        printf("请输入选项<1,2,3,4,5,6,7,8,9,10>\n");
        scanf("%d",&choice);
        switch(choice)
  {
  case 1:printf("输入信息函数\n");         len=dedao(shu,100);  printf("len=%d\n",len);  break;
        case 2:printf("输出函数被调用\n");       shuchu(shu,len);        break;
        case 3:printf("保存到文件函数被调用\n"); send(shu,len);          break;
        case 4:printf("从文件读函数被调用\n");   len=readFromFile( shu); break;
        case 5:printf("按学号查询函数被调用\n"); chaxun(shu,len);        break;
        case 6:printf("按成绩排序函数被调用\n"); paixu(shu,len);         break ;
     case 7:printf("平均成绩被调用\n"); average(shu,len);             break ;
  case 9:len=add(shu,len);break;
     case 8:modify(shu,len);             break ;
        case 10:exit(0);break;
  }
 }
}
void menu()
{
 printf("\n");
    printf("          *******************************************\n");
    printf("         *          学生成绩管理系统                 *\n");
    printf("         *          1.输入成绩                       *\n");
    printf("         *          2.输出成绩                       *\n");
    printf("         *          3.保存成绩                       *\n");
    printf("         *          4.读取成绩                       *\n");
    printf("         *          5.按学号查询                     *\n");
    printf("         *          6.按成绩排序(由大到小)         *\n");
 printf("         *          7.平均成绩及优秀率               *\n");
    printf("         *          8.修改                           *\n");
    printf("         *          9.添加                           *\n");
    printf("         *          10.程序结束                      *\n");
    printf("          *******************************************\n");

}
int add(struct STUDENT shu[],int n)
{
 int i=n;
    int flag=0,c=1;
 char s;
    int xuehao,bank;
 float chengji;
    while(c)
 {
  while(1)
  {
   printf("学号:");
            scanf("%d",&xuehao);
            if(xuehao==0)
   {
    flag=1;
    break;
   }
   bank=uninque(shu,i,xuehao);
            if(bank==0)
   {
    shu[i].num=xuehao;
    break;
   }
  }
  if(flag==1)  break;
  printf("姓名:");
        scanf("%s",&shu[i].name);
  while (1)
  {
   printf("成绩:");
         if(scanf("%f",&chengji)==1)
   {
         break;
   }
         printf("输入格式错误,请重新输入!");
         while(getchar()!='\n')   continue;
  }
        while(getchar()!='\n') continue;
        shu[i].score=chengji;
         i++;
   printf("是否继续输入学生信息,输入Y或y继续,否则退出\n");
   scanf("%c",&s);
   if(s=='y'||s=='Y')  c=1;
   else c=0;
 }
 return i;

}
void modify(struct STUDENT shu[],int len)
{
 int i,nue,b=0,n,pan=1;
 char s[10],c;
    int xuehao;
 float chengji;
 while(pan)
 {
     printf("请输入要修改的学号\n");
        scanf("%d",&n);
        for (i=0;i<len;i++)
  {
  // printf("xuehao=%d,,num=%d\n",n,shu[i]);
        //    printf("i=%d\n",i);
   if(n==shu[i].num) break;
  }
  if(i>=len)
  {
   printf("该学号不存在!\n");
   break;
  }
  printf("请输入要修改哪项(1--学号,3--姓名,2--成绩)(输入'0'退出): ");
  scanf("%d",&nue);
  if(nue==0)
   break;
  switch(nue)
  {
  case 1:
   printf("请输入你要修该的学号\n");
   scanf("%d",&xuehao);
   shu[b].num=xuehao;
   break;
  case 2:
   printf("请输入你要修该的成绩\n");
   scanf("%f",&chengji);
   shu[b].score=chengji;
   break;
  case 3:
   printf("请输入你要修该的姓名\n");
   scanf("%s",s);
   strcmp(shu[b].name,s);
   break;
  }
   printf("是否继续修改学生信息,输入Y或y继续,否则退出\n");
   scanf("% c",&c);
   if(c=='y'||c=='Y')  pan=1;
   else pan=0;
 }

}

int dedao(struct STUDENT shu[],int n)
{
    static int i=0;
    int flag=0,c=1;
 char s;
    int xuehao,bank;
 float chengji;
    while(c)
 {
  while(1)
  {
   printf("学号:");
            scanf("%d",&xuehao);
            if(xuehao==0)
   {
    flag=1;
    break;
   }
   bank=uninque(shu,i,xuehao);
            if(bank==0)
   {
    shu[i].num=xuehao;
    break;
   }
  }
  if(flag==1) 
   break;
  printf("姓名:");
        scanf("%s",&shu[i].name);
  while (1)
  {
   printf("成绩:");
         if(scanf("%f",&chengji)==1)
   {
         break;
   }
         printf("输入格式错误,请重新输入!");
         while(getchar()!='\n')   continue;
  }
        while(getchar()!='\n') continue;
        shu[i].score=chengji;
         i++;
   printf("是否继续输入学生信息,输入Y或y继续,否则退出\n");
   scanf("%c",&s);
   if(s=='y'||s=='Y')  c=1;
   else c=0;
 }return i;
}

int uninque(struct STUDENT shu[],int len,int xuehao)
{
 int i;
    int bank=0;
    for (i=0;i<len;i++)
 {
  if(xuehao==shu[i].num)
   bank=1;
 }
 return bank;
}

void shuchu(struct STUDENT shu[],int len)
{
 int j;
 printf("%-4s %-10s    %-3s","学号","姓名","成绩\n\n");
    for(j=0;j<len;j++)
 {
  printf("%-4d %-10s    %-3.1f",shu[j].num,shu[j].name,shu[j].score);
        printf("\n");
 }
printf("\n\n");
}

void send(struct STUDENT shu[],int len)
{
 int i;
    FILE *fp;
    fp=fopen("chengji.txt","wb");
    if(fp==NULL)
 {
  printf("打开文件出错!\n");
      //  exit(0);
    }
 for(i=0;i<len;i++)
  fwrite(shu+i,sizeof(struct STUDENT),1,fp);
 fclose(fp);
}

int readFromFile(struct STUDENT shu[])
{
 FILE *fp=NULL;
 int i=0;
 fp=fopen("chengji.txt","rb");
 if(fp!=NULL)
 {
  printf("%-4s %-10s    %-3s","学号","姓名","成绩\n\n");
  while(!feof(fp))
  {
   if(i>=N)
    break;
   if(fread(shu+i,sizeof(struct STUDENT),1,fp))
    printf("%-4d %-10s    %-3.1f",shu[i].num,shu[i].name,shu[i].score);
   printf("\n");
   i++;
  }
  fclose(fp);
 }
 i=i-1;
 return i;
}

void chaxun(struct STUDENT shu[],int len)
{
 int i,nue,b=0;
 while(1)
 {
  printf("请输入学生学号(输入'0'退出): ");
  scanf("%d",&nue);
  b=0;
  if(nue==0)
   break;
  for (i=0;i<len;i++)
  {
   if(nue==shu[i].num)
   {
    printf("%-4s %-10s    %-3s","学号","姓名","成绩\n\n");
    printf("%-4d %-10s    %-3.1f\n",shu[i].num,shu[i].name,shu[i].score);
    b=1;
   }
  }
  if(b==0)
   printf("该学号不存在!\n");
 }

}

void paixu(struct STUDENT shu[],int len)
{
 int i,j,k;
    struct STUDENT temp; 
 for(i=0;i<len;i++)
 {
  for(j=i;j<len;j++)
  {
   if(shu[j].score>shu[i].score)
   {
    temp=shu[j];
    shu[j]=shu[i];
    shu[i]=temp;
   }
  }
 }
 for(k=0;k<len;k++)
 {
     printf("%-4d %-10s    %-3.1f\n",shu[k].num,shu[k].name,shu[k].score);
 }
}

void  average(struct STUDENT shu[], int len)

    float sum=0;
 int i=0;
 int x=0;
 for(i=0;i<len;i++)
 {
  sum+=shu[i].score;
 }
 printf("%s%f\n","平均成绩:",sum/len);
 for(i=0;i<len;i++)
 {
  if(shu[i].score>90)
   x=x+1;
 }
 printf("%s%f\n","优秀率:",(float)x/(float)len);
}

 

这是我的,但老师说void modify(struct STUDENT shu[],int len);
int uninque(struct STUDENT shu[],int len,int xuehao);
void shuchu(struct STUDENT shu[],int len);
void send(struct STUDENT shu[],int len);
int readFromFile(struct STUDENT shu[]);
void chaxun(struct STUDENT shu[],int len);
void paixu(struct STUDENT shu[],int len);
void average(struct STUDENT shu[], int len);

struct STUDENT
{
   int num;
   char name[10];
   float score;
};
int main()
{
 static int len=0,choice;
 struct STUDENT shu[100];
    while(1)
 {
  menu();
        printf("请输入选项<1,2,3,4,5,6,7,8,9,10>\n");
        scanf("%d",&choice);
        switch(choice)
  {
  case 1:printf("输入信息函数\n");         len=dedao(shu,100);  printf("len=%d\n",len);  break;
        case 2:printf("输出函数被调用\n");       shuchu(shu,len);        break;
        case 3:printf("保存到文件函数被调用\n"); send(shu,len);          break;
        case 4:printf("从文件读函数被调用\n");   len=readFromFile( shu); break;
        case 5:printf("按学号查询函数被调用\n"); chaxun(shu,len);        break;
        case 6:printf("按成绩排序函数被调用\n"); paixu(shu,len);         break ;
     case 7:printf("平均成绩被调用\n"); average(shu,len);             break ;
  case 9:len=add(shu,len);break;
     case 8:modify(shu,len);             break ;
        case 10:exit(0);break;
是C++的!要用纯C语言的,能帮我下吗?

答案://你自己试试 还有什么要求就跟我说


#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
struct stu
{
long num;
char name[20];
float score1,score2,score3;
float aver;
};


typedef struct stucode
{
struct stu student ;
struct stucode *next;
}M;


void menu();
void createlist(struct stucode **w);
float averege( float a,float b,float c);
void out(struct stucode *w);
void search_num(struct stucode *w);
void search_name(struct stucode *w);
void del(struct stucode **w);
void insert(struct stucode **w);
void sort_score(struct stucode **w);
void sort_num(struct stucode **w);


void main()
{
int choose;
int flag=1;
struct stucode *w=NULL;
while(flag)
{
  system("cls");
  menu();
  scanf("%d",&choose);
  switch(choose)
  {
  case 1:
  createlist(&w);
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 2:
  search_num(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 3:
  search_name(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 4:
  del(&w);
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 5:
  insert(&w);
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 6:
  sort_score(&w);
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 7:
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 8:
  sort_num(&w);
  out(w);
  printf("\nPress any key to continue\n");
  getchar();
  getchar();
  break;


  case 0:
  flag=0;
  printf("The end.\n");
  break;


  default: printf("\nWrong Selection!(选择错误,请重选!)\n");
  getchar();
  getchar();
  }
}
}

上一个:我马上要去计算机C语言二级考试了 想了解下二级考试C语言的一个范围
下一个:一个统计输入字符串中各种字符个数的C语言代码,求指点。。

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,