简单的学籍管理系统(C语言编写)

在TC下调试运行通过。

没有注释,阅读比较困难。

#include <stdio.h>
#include <string.h>
#include <conio.h>
#define maxmenu 7

struct student
{
 long sno;
 char sname[30];
 char sclass[30];
 float sscore;
};

void dispstr(char ch[]);
int Add(struct student stu[],int n);
int Del(struct student stu[],int n);
void Seek(struct student stu[],int n);
     void seekbysno(struct student stu[],int n);
     void seekbysname(struct student stu[],int n);
     void seekbysclass(struct student stu[],int n);
     void seekbysscore(struct student stu[],int n);
void Sort(struct student stu[],int n);
     void sortbysno(struct student stu[],int n);
     void sortbysscore(struct student stu[],int n);
void Correct(struct student stu[],int n);
void Disp(struct student stu[],int n);
void Disptxt();
void pri(struct student stu[],int i);
void num(int n);

main()
{
  struct student stu[100];
  int menupos=0,i,m=0;
  char menuitem[][10]={" Add "," Delete "," Seek "," Correct "," Sort "," Display "," Exit "};
  Disptxt();
  textbackground(BLUE);
  textcolor(YELLOW);
  window(1,5,80,25);
  clrscr();
  while(1)
  {
     num(m);
     window(1,4,80,4);
     textbackground(LIGHTGRAY);
     textcolor(BLACK);
     clrscr();
     for(i=0;i<maxmenu;i++)
     { 
       gotoxy(i*10+1,1);
       printf("%s",menuitem[i]);
     }
     window(1,4,80,4);
     textcolor(WHITE);
     textbackground(BLACK);
     gotoxy(menupos*10+1,1);
     dispstr(menuitem[menupos]);
     i=getch();
     if(!i)
	{i=getch();
	 switch(i)
	 {  
            case 75:menupos--;
		    if(menupos<0) menupos=maxmenu-1;
		    break;
	    case 77:menupos++;
		    if(menupos==maxmenu) menupos=0;
		    break;
	 }
	}
     if(i!=0xd) continue;
     if(menupos==6) break;
     window(1,5,80,25);
     textcolor(YELLOW);
     textbackground(BLUE);
     clrscr();
     switch(menupos)
     {
       case 0:m=Add(stu,m);break;
       case 1:m=Del(stu,m);break;
       case 2:Seek(stu,m);break;
       case 3:Correct(stu,m);break;
       case 4:Sort(stu,m);break;
       case 5:Disp(stu,m);break;
     }
  }
}

int Add(struct student stu[],int n)
{
 float f;
 int i;
 if(n>100) printf("Number fill out!!!\n");
 else
 {
  printf("Please input the NUMBER of this student:");
    scanf("%ld",&stu[n].sno);
  for(i=0;i<n;i++)
   {
    if(stu[n].sno==stu[i].sno)  
     {
      printf("This student is already here!\nAdd student FAIL!\n");
      return(n);
      break;
     }
   }
  printf("Please input the NAME of this student:");
    scanf("%s",stu[n].sname);
  printf("Please input the CLASS of this student:");
    scanf("%s",stu[n].sclass);
  printf("Please input the SCORE of this student:");
    scanf("%f",&f);stu[n].sscore=f;
  printf("Add student sucess!\n");
  return(n+1);
 }
}

int Del(struct student stu[],int n)
{
  int i,j,h=0;
  long s;
  if(n==0)  {printf("None student could be delete!\nPlease add student first!!!");return(n=0);}
  else
  {
    printf("Please input the STUDENT NUMBER you want to delete:");
    scanf("%ld",&s);
    for(i=0;i<n;i++)
    {
      if(stu[i].sno==s)
      {
        h=1;
        for(j=i;j<n;j++)   stu[j]=stu[j+1];
        break;
      }
    }
    if(h==0)  {printf("This student is no hear!\n");return(n);}
    if(h==1)  {printf("Delete success!\n");return(n-1);}
  }
}

void Seek(struct student stu[],int n)
{
  int ch;
  if(n==0)  printf("None student could be seeked!\nPlease add student first!!!");
  else
  {
    printf("Please chose the way to seek:\n");
    printf("1.By student number.\n");
    printf("2.By student name.\n");
    printf("3.By student class.\n");
    printf("4.By student score.\n");
    ch=getch();
    switch(ch)
    {
      case '1':seekbysno(stu,n);break;
      case '2':seekbysname(stu,n);break;
      case '3':seekbysclass(stu,n);break;
      case '4':seekbysscore(stu,n);break;
    }
  }
}

void Correct(struct student stu[],int n)
{
 float f;
 long s;
 int i,m,h;
 if(n==0) printf("None student could be corrected!\nPlease add student first!!!");
 else
 {
   printf("Input NUMBER that you want to Correct:\n");
   scanf("%ld",&s);
   for(i=0;i<n;i++)
   {
    if(stu[i].sno==s)  {m=i;h=1;break;}
    else h=0;
   }
   if(h==1)
   {
     printf("Please input the new NUMBER:\n");
     scanf("%d",&stu[m].sno);
     printf("Please input the new NAME:\n");
     scanf("%s",stu[m].sname);
     printf("Please input the new CLASS:\n");
     scanf("%s",stu[m].sclass);
     printf("Please input the new SCORE:\n");
     scanf("%f",&f);stu[m].sscore=f;
     printf("Correct information success!\n");
   }
   if(h==0)  printf("Correct fail!\nBecause haven't found this student!!!");
 }
}

void Sort(struct student stu[],int n)
{
 char ch;
 if(n==0) printf("None student could be sorted!\nplease add student first!!!");
 else
 {
   printf("Please chose the way to Sort:\n");
   printf("1.By student number.\n");
   printf("2.By student score.\n");
   ch=getch();
   switch(ch)
   {
     case'1':sortbysno(stu,n);break;
     case'2':sortbysscore(stu,n);break;
   }
 }
}

void Disp(struct student stu[],int n)
{
  int i;
  if(n==0) printf("None student could be Display!\nPlease add student first!!!");
  else
  {
    printf("ID            NAME             CLASS          SCORE\n");
    for(i=0;i<n;i++)
	pri(stu,i);
  }
}
void dispstr(char ch[])
{
  int k=0;
  while (ch[k])  putch(ch[k++]);
}
void Disptxt()
{
  textbackground(CYAN);
  textcolor(BLACK);
  clrscr();
  window(1,1,80,3);
  printf("Designer:\002zhong\001zhi\001huai\002            ID:0950303054           Class:JiKe-(2)BAN\n");
  printf("\n");
  textcolor(WHITE);
  window(1,3,80,3);
  clrscr();
  printf("                      \002Student Information Manage System\002\n");
}
void num(int n)
{
 textbackground(WHITE);
 textcolor(BLACK);
 window(61,6,79,9);
 clrscr();
 window(62,7,80,7);
 printf("Nowhave_%d_student",n);
 window(62,8,80,8);
 printf("in the SYSTEM!");
}
void pri(struct student stu[],int i)
{
   printf("%-14ld",stu[i].sno);
   printf("%-17s",stu[i].sname);
   printf("%-15s",stu[i].sclass);
   printf("%6.2f\n",stu[i].sscore);
}

void seekbysno(struct student stu[],int n)
{
 long s;
 int i;
 printf("Please input the NUMBER to seek:");
 scanf("%ld",&s);
 printf("\n");
 for(i=0;i<n;i++)
 {
   if(stu[i].sno==s)
    {
      printf("The information of this student is:\n");
      printf("ID            NAME             CLASS          SCORE\n");
      pri(stu,i);
      break;
    }
 }
}
void seekbysname(struct student stu[],int n)
{
 char s[30];
 int i;
 printf("Please input the NAME to seek:");
 scanf("%s",s);
 printf("ID            NAME             CLASS          SCORE\n");
 for(i=0;i<n;i++)
  {
    if(strcmp(stu[i].sname,s)==0)  pri(stu,i);
  }
}
void seekbysclass(struct student stu[],int n)
{
 char s[30];
 int i;
 printf("Please input the CLASS to seek:");
 scanf("%s",s);
 printf("ID            NAME             CLASS          SCORE\n");
 for(i=0;i<n;i++)
  {
   if(strcmp(stu[i].sclass,s)==0)  pri(stu,i);
  }
}
void seekbysscore(struct student stu[],int n)
{
 int i;
 float f;
 printf("Please input the SCORE to seek:");
 scanf("%f",&f);
 printf("ID            NAME             CLASS          SCORE\n");
 for(i=0;i<n;i++)
  {
   if(stu[i].sscore==f)  pri(stu,i);
  }
}

void sortbysno(struct student stu[],int n)     
{
  struct student h;
  int i,j,k;
   for(i=0;i<n-1;i++)
   {
    k=i;
    for(j=i+1;j<n;j++)
        if(stu[j].sno<stu[k].sno)  k=j;
    if(k!=i)
     {
      h=stu[i];
      stu[i]=stu[k];
      stu[k]=h;
     }
   }
    printf("SORT with student number:\n");
    printf("ID            NAME             CLASS          SCORE\n\n");
    for(i=0;i<n;i++)
        pri(stu,i);
}
void sortbysscore(struct student stu[],int n)
{
  struct student h;
  int i,j,k;
  for(i=0;i<n-1;i++)
   {
    k=i;
    for(j=i+1;j<n;j++)
        if(stu[j].sscore<stu[k].sscore)  k=j;
    if(k!=i)
     {
      h=stu[i];
      stu[i]=stu[k];
      stu[k]=h;
     }
   }
   printf("SORT with student score:\n");
   printf("ID            NAME             CLASS          SCORE\n\n");
   for(i=0;i<n;i++)  
       pri(stu,i);
}




  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
一、学籍管理系统 1.问题提出 为了分析教学效果并进行相应的学籍处理,各学校每到期末都对综合成绩进行分类统计、上报成绩汇总结果等,这给每位老师和学籍管理人员带来很大工作量。使用学籍管理系统可以减少工作者的工作负担。 2.功能要求 循环显示如图7(a)所示的主菜单。 ………………………………………………….        .………………………………………………………        …………………………………………………………. 请输入选项编号(0 ~4):.        . 请输入选项编号(0 ~4):.        .请输入选项编号(0 ~4):. ………………………………………………….        .………………………………………………………        …………………………………………………………. . 1——录入成绩.                . 1——按学号排序.               . 1——生成并打印补考通知单 . . 2——统计成绩.                . 2——计算平均分并排序 .         . 2——生成并打印退学通知单 . . 3——处理学籍.                . 3——统计分数段.               . 3——生成并打印新名册. . 4——创新功能.                . 4——返回.                    . 4——返回. . 0——退出系统.                . 0——退出系统.                 . 0——退出系统. ……………………………………………………         ……………………………………………………….        …………………………………………………………. 图7(a) 学籍管理主菜单            (b)成绩统计子菜单               (c)学籍处理子菜单 在主菜单中选择1:录入成绩。假设某班的原始成绩形式如下: 学号        姓名        高数    英语    物理    编程    马哲 0909339105 Huangying  89      92      85     88     82 0909339102 Zhangchen  72      68      83     90     78 0909339108 Linan      91      84      90     79     81 …… 其中,原始数据的排列是无序的。系统应能够保留原始成绩单。 在主菜单中选择2:进入如图7(b)所示的子菜单,并统计成绩。在此可以计算平均分、统计各分数段、按学号排序、按平均分排序。在子菜单选择1时,将该班学生的成绩按学号升序排序后的顺序存入std.dat文件中,以方便打印。在子菜单选择2时,求出每位学生的平均分,并按平均分从高到低的顺序进行排序后,写入文件sort.dat中。在子菜单选择3时,统计出各门课、各分数段学生的人数,并如表1所示的形式输出。在子菜单选择4时,返回主菜单;选择0,退出整个系统。 在主菜单选择3:进入如图7(c)所示的子菜单,并处理学籍。为不及格的学生打印重考通知单时,应在通知单上写明重考的课程、时间和地点(由键盘输入)。为了参加多门课重考的学生完成补考,应避免时间重复。为3门以上不及格的学生打印退学通知单。通知单上应写明学生的学号、姓名、退学原因(几门课不及格,成绩多少)。删除已退学的学生信息,将该班中升入高年级的学生信息写入文件next.dat中。在子菜单选择4,返回主菜单;选择0,退出整个系统。 在主菜单中选择4:此项功能学生自由发挥,根据本组爱好增加与本题止相关的新功能。 在主菜单中选择0:显示结束信息(如“感谢使用本软件!已正常退出,按任意键结束。”),按任意键后,退出本功能。 表1 各门课、各分数段学生的人数 ……………………………………………………………………………………………………………….   . 90以上. 80~89分.70~79分.60~69分.60分以下. 高数.      .       .       .       .       . 英语.      .       .       .       .       . 物理.      .       .       .       .       . 编程.      .       .       .       .       . 马哲.      .       .       .       .       . ……………………………………………………………………………………………………………….

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值