⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wancheng1.c

📁 比较详细的学生信息管理系统
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h> /*标准输入输出库*/
#include <string.h> /*字符串操作库*/
#include <conio.h> /*控制台函数库*/
#include <malloc.h> /*内存分配库*/
#include <process.h> /*进程库*/
#include <stdlib.h>

#define LEN sizeof(struct student )


struct student 
{
int num; /*学生序号*/
int sex;/*学生性别*/
int age;/*年龄*/
int english;/*英语成绩*/
int math; /*数学成绩*/
int program; /*程序设计成绩*/
int amount; /*总分*/
char name[30]; /*学生姓名*/
char major[20];/*专业班级*/
struct student *next;
}; /*学生结构体*/

int n=0;     /* 统计记录条数*/
struct student *head=NULL;  /*定义头指针为全局变量*/

struct student *create();
struct student *add(struct student *head) ;
struct student *delet(struct student *head);
struct student *correct(struct student *head);
void search(struct student *head);
void save();
struct student *op();
struct student C_MATH(struct student *head);
struct student C_ENG(struct student *head);
struct student C_PRO(struct student *head);
void order_PRO(struct student *head,int n);
void order_ENG(struct student *head,int n);
void order_MATH(struct student *head,int n);
void print(struct student *head);

struct student *create()                                  /*建立链表*/
{ struct student *p3,*p4;
  char c;
  head=NULL;
  do
  {p3=(struct student *)malloc(LEN);
   printf("请输入学号:");scanf("%d",&p3->num);



   printf("请输入姓名:");scanf("%s",p3->name);
   printf("请输入性别: ");scanf("%d",&p3->sex);
   printf("请输入年龄: ");scanf("%d",&p3->age);
   printf("请输入专业班级: ");scanf("%s",p3->major);
   printf("请输入英语成绩:");scanf("%d",&p3->english);
   printf("请输入数学成绩:");scanf("%d",&p3->math);
   printf("请输入C语言成绩:");scanf("%d",&p3->program);
   p3->next=NULL;
   p3->amount=(p3->english+p3->math+p3->program);
   n++;
   if (n==1) head=p3;
   else p4->next=p3;
   p4=p3;
   printf ("继续输入吗?(y/n):");
   c=getch();
   printf("\n");
  }while(c=='y');
  printf("输入完成!!!");
  return (head);

}

/*增加函数*/
struct student *add(struct student *head)
{
    struct student *p0,*p1,*p2;
    printf("输入要增加的学生记录:");

    p1=head;         /*p1指向第一个结点*/
    
    if(head==NULL)    /*原来是空表*/
      {head=p0;          /*使p0指向的结点作为链表第一个结点*/
       p0->next=NULL;
      }
    else
    {while((p0->num>p1->num)&&(p1->next!=NULL))
        {p2=p1;
         p1=p1->next;     /*找插入点*/
        }
         if(head==p1)
         {p0->next=head;
          head=p0;
         }                /*作为表头*/
         else
         {p2->next=p0;      /*插到p2指向的结点之后*/
          p0->next=p1;
         }

    }
    if(p0->num!=0)
      {printf("增加新的记录:\n");
        printf("学号:");
        scanf("%d",&p0->num);
        if(p0->num==0)
        goto end;
        printf("姓名:");
        scanf("%s",p0->name);
        printf("性别:");
        scanf("%d",&p0->sex);
        printf("年龄:");
        scanf("%d",&p0->age);
         printf("专业班级:");
        scanf("%s",p0->major);
        printf("英语成绩:");
        scanf("%d",&p0->english);
        printf("数学成绩:");
        scanf("%d",&p0->math);
        printf("C语言成绩:");
        scanf("%d",&p0->program);
        p0->amount=p0->english+p0->math+p0->program;
        printf("\n添加成功!");
        n++;
        getch();
        print(head);
        n++;
       }
     else
      printf("添加失败!");
end: return(head);
}


/*删除函数*/


struct student *delet(struct student *head)

{   int num;
    struct student *p1,*p2;
    printf("输入要删除学生的学号:\n");
    scanf("%d",&num);
    if(head==NULL)
    {
        printf("\n是空链表!\n");
        goto end;
    }
    p1=head;
    while(num!=p1->num&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num)
     {if(p1==head)
        head=p1->next;
     else p2->next=p1->next;
     printf("%d 号被删除,删除成功!\n",num);
     free(p1);
     n--;
     }
    else
      printf("\n你输入的学号不存在,删除失败");
end : return(head);
}


/*修改函数*/
struct student *correct(struct student *head)
{int num;
 struct student *p1;
 p1=head;
 printf("输入要修改的学号:");
 scanf("%d",&num);
 while(num!=p1->num&&p1->next!=NULL)
   {p1=p1->next;
    if(p1->num==0)break;
   }
 if(num==p1->num)
  {printf("请输入新的记录:\n");
    printf("学号:");
    scanf("%d",&p1->num);
    printf("姓名:");
    scanf("%s",p1->name);
    printf("性别:");
    scanf("%d",&p1->sex);
    printf("年龄:");
    scanf("%d",&p1->age);
    printf("专业班级:");
    scanf("%s",p1->major);
    printf("英语成绩:");
    scanf("%d",&p1->english);
    printf("数学成绩:");
    scanf("%d",&p1->math);
    printf("C语言成绩:");
    scanf("%d",&p1->program);
    p1->amount=p1->english+p1->math+p1->program;
    printf("\n修改成功!");
  }
 else printf("\n该学号不存在!");
 return(head);
}


/*查找记录函数*/
void search(struct student *head)
{struct student *p;    /*  移动指针*/
 int num;     /*存放姓名用的字符数组*/
 clrscr();
 printf("输入要查找的学号:\n");
 scanf("%d",&num);
 p=head;    /*将头指针赋给p*/
 while(p->num!=num&& p != NULL)  /*当记录的学号不是要找的*/
   p=p->next;     /*移动指针,指向下一结点*/
 if(p!=NULL)         /*如果指针不为空*/
   { printf("\n                                   FOUND\n");
     printf("___________________________________________________________________________\n");
     printf("|  学号 |  姓名 | 性别 |  年龄 |   专业  |  英语 |  数学  |  C语言  |  总分 |\n");
     printf("____________________________________________________________________________\n");
     printf("|  %d   |  %s   |  %d  |  %d   |    %s   |  %d   |   %d   |   %d    |   %d  |\n",
      p->num,p->name,p->sex,p->age,p->major,p->english,p->math,p->program,p->amount);
     printf("________________________________________________________________________________\n");
     printf("                                      END\n");
   }
  else
     printf("\n没有该学生.");   /*显示没有该学生*/
}



/*保存文件*/
void save()
{   
    FILE *fp;
    char filename[20];
    struct student *p,*head;
    p=head;
    printf("\n输入文件名和保存路径:");
    scanf("%s",filename);
    if((fp=fopen(filename,"wb+"))==NULL)
    { printf("\n 输入保存路径和文件名:\n");
        exit(1); 
    }
    for(;p!=NULL;p=p->next)
    {
        if((fwrite(p,sizeof(struct student),1,fp))!=1)
        printf("输入错误!");
    }
 clrscr();
 printf("\n保存成功!\n");
 fclose(fp);
 getch();
}


/* 打开文件 */
struct student *op()
{
    FILE *fp;
    char filename[20];
    int n=0;
    struct student *p,*p1,*p2,*head;
    clrscr();
    printf("\n输入路径和文件名:");
    scanf("%s",filename);
    fp=fopen(filename,"rb");
    head=p=p1=(struct student *)malloc(LEN);
    for(;!feof(fp);)
    {
        n=n+1;
        fread(p,sizeof(struct student),1,fp);
        p1=p;
        if(n!=1)
        {
            p2=p1;
            p1->next=p;
        }
        p=( struct student*)malloc(LEN);
    }
    p2->next=NULL;
    clrscr();
    printf("\n 打开文件成功!\n\n");
    getch();
    return(head);
}

/*统计数学*/
struct student C_MATH(struct student *head)
{
   struct student *p1;
   int a=0,b=0,c=0,d=0,e=0,f=0,i=0;
   p1=head;
   while(p1->num!=0)
   {i=i+1;
      if(p1->math>=100) a=a+1;
      else if(p1->math>=90) b=b+1;
           else if(p1->math>=80) c=c+1;
                else if(p1->math>=70) d=d+1;
                      else if(p1->math>=60) e=e+1;
                           else f=f+1;
    p1=p1->next;
   }
   printf("\n There are %d students get 100 mark!",a);
   printf("\n There are %d students get 90~99 mark!",b);
   printf("\n There are %d students get 80~89 mark!",c);
   printf("\n There are %d students get 70~79 mark!",d);
   printf("\n There are %d students get 60~69 mark!",e);
   printf("\n There are %d students get under 60 mark!",f);
}


/*统计英语*/

   
struct student C_ENG(struct student *head)
{
   struct student *p1;
   int a=0,b=0,c=0,d=0,e=0,f=0,i=0;
   float a1,b1,c1,d1,e1,f1;
   p1=head;
   while(p1->num!=0)
   {i=i+1;
      if(p1->english>=100) a=a+1;
      else if(p1->english>=90) b=b+1;
           else if(p1->english>=80) c=c+1;
                else if(p1->english>=70) d=d+1;
                      else if(p1->english>=60) e=e+1;
                           else f=f+1;
    p1=p1->next;
   }
   printf("\n There are %d students get 100 mark!",a);
   printf("\n There are %d students get 90~99 mark!",b);
   printf("\n There are %d students get 80~89 mark!",c);
   printf("\n There are %d students get 70~79 mark!",d);
   printf("\n There are %d students get 60~69 mark!",e);
   printf("\n There are %d students get under 60 mark!",f);
}


/*统计C语言程序设计*/
struct student C_PRO(struct student *head)
{
   struct student *p1;
   int a=0,b=0,c=0,d=0,e=0,f=0,i=0;
   float a1,b1,c1,d1,e1,f1;
   p1=head;
   while(p1->num!=0)
   {i=i+1;
      if(p1->program>=100) a=a+1;
      else if(p1->program>=90) b=b+1;
           else if(p1->program>=80) c=c+1;
                else if(p1->program>=70) d=d+1;
                      else if(p1->program>=60) e=e+1;
                           else f=f+1;
    p1=p1->next;
   }
   printf("\n There are %d students get 100 mark!",a);
   printf("\n There are %d students get 90~99 mark!",b);
   printf("\n There are %d students get 80~89 mark!",c);
   printf("\n There are %d students get 70~79 mark!",d);
   printf("\n There are %d students get 60~69 mark!",e);
   printf("\n There are %d students get under 60 mark!",f);
}


/*学生记录排序函数*/
void order_ENG(struct student *head,int n)                   /*按英语成绩排序*/
{char b[20];
 int x;
 int i,j,flag;
 int num,t;
 struct student *p1,*p2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -