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

📄 xinxiguanlixitong.c

📁 学生信息管理系统(课程设计).简单的界面以及简单功能的源代码.由于技术较低,所以较简单
💻 C
字号:
/* Note:Your choice is C IDE */
#include "stdio.h"
#define NULL 0
#define LEN sizeof(struct student)    /*定义结点长度*/
  /*定义结点结构*/
  struct student
  { int no;                       /*学号*/
  	char name[20];                    /*姓名*/
  	char grade[20];                   /*班级*/
  	char sex[8];                      /*性别*/
  	struct date                       /*生日*/
  	{int year;
  	int month;
  	int day;	
  		}birthday;
  	struct score                      /*课程成绩*/
  	{int math;
  	 int english;   
  	 int tc;
  	}sc;
  	struct  student  *next;			/*指针域*/
  	};
   




int menu_sel()
{
   char *menu[]={"***************学生信息管理系统***************",
   "1.创建学生信息",
   "2.添加学生信息",
   "3.删除学生信息",
   "4.修改学生信息",
   "5.排序",
   "6.列出记录",
   "7.查找学生信息",
   "8.保存到文件",
   "9.从文件调出",
   "10.退出",
   "",
   
   };

 int c,i;
 clrscr();
 gotoxy(1,1);
 textcolor(15);
 textbackground(1);
 gotoxy(10,4);
 for(i=3;i<=59;i++)
    putch('_');
 for(i=5;i<21;i++)
 { gotoxy(10,i);putch('|');
   gotoxy(66,i);putch('|');
 }
 gotoxy(10,20);
 for(i=3;i<=59;i++)
    putch('_');
 window(11,5,65,19);
 clrscr();
 gotoxy(6,2);
   printf("%s", menu[0]);
   gotoxy(8,14);
   printf("%s", menu[12]);
 for(i=1;i<12;i++)
 { gotoxy(22,i+2);
   printf("%s", menu[i]);
 }
 textbackground(0);
 window(1,1,80,25);
 gotoxy(26,2);
 printf("欢迎使用学生信息管理系统");
 gotoxy(10,22);
 do{
 	printf("请输入你选择的数(1--10):");
 	scanf("%d",&c);
 }while(c<1||c>10);
 return c;
}
/*创建学生信息*/
struct student *create(  )
    { struct student *head=NULL, *new, *tail;
        int count=0,n=3,i=0;
        clrscr();             		/*链表中的结点个数(初值为0)*/
        gotoxy(35,2);
          printf("创建学生信息\n"); 
        head=(struct student *)malloc(LEN);
        tail=head;
        for(i=0;i<n;i++)              		/*缺省3个表达式的for语句*/
     	  { new=(struct student *)malloc(LEN);	/*申请一个新结点的空间*/
  /*1、输入结点数据域的各数据项*/
printf("输入第 %d 个学生的学号 : ", count+1);
scanf("%6d", &new->no);
printf("输入第 %d 个学生的姓名 : ", count+1);
scanf("%s", new->name);
printf("输入第 %d 个学生的班级 : ", count+1);
scanf("%s", new->grade);
printf("输入第 %d 个学生的性别 : ", count+1);
scanf("%s", new->sex);
printf("输入第 %d 个学生的生日 : ", count+1);
scanf("%d %d %d", &new->birthday.year,&new->birthday.month,&new->birthday.day);
printf("输入第 %d 个学生的数学成绩 : ", count+1);
scanf("%d", &new->sc.math);
printf("输入第 %d 个学生的英语成绩 : ", count+1);
scanf("%d", &new->sc.english);
printf("输入第 %d 个学生的C语言成绩 : ", count+1);
scanf("%d", &new->sc.tc);
count++;                     		/*结点个数加1*/
/*2、置新结点的指针域为空*/
new->next=NULL;
/*3、将新结点插入到链表尾,并设置新的尾指针*/
tail->next=new;        /*非首结点, 将新结点插入到链表尾*/
       tail=new;                         /*设置新的尾结点*/
     }
   return(head);
    }
    /*添加新的学生信息*/
    struct student *insert(struct student *head )
    { struct student *new,*p,*q;
       int i, j=0;
       clrscr();
             /*将新结点插入到链表中*/
          gotoxy(30,2);
          printf("添加新的学生信息\n");   
        new=(struct student *)malloc(LEN);
            /*1、输入结点数据域的各数据项*/
            
        printf("输入第 %d 个学生的学号 : ");
        scanf("%6d", &new->no);
        printf("输入第 %d 个学生的姓名 : ");
        scanf("%s", new->name);
        printf("输入第 %d 个学生的班级 : ");
        scanf("%s", new->grade);
        printf("输入第 %d 个学生的性别 : ");
        scanf("%s", new->sex);
        printf("输入第 %d 个学生的生日 : ");
        scanf("%d %d %d", &new->birthday.year,&new->birthday.month,&new->birthday.day);
        printf("输入第 %d 个学生的数学成绩 : ");
        scanf("%d", &new->sc.math);
        printf("输入第 %d 个学生的英语成绩 : ");
        scanf("%d", &new->sc.english);
        printf("输入第 %d 个学生的C语言成绩 : ");
        scanf("%d", &new->sc.tc);
        printf("请输入添加学生的位置 : ");
        scanf("%d",&i);
        q=head;
        p=q->next;
        while(++j<i&&p->next!='\0')
        {q=p;p=q->next;}
        if(j==i)
        {new->next=p;q->next=new;}
        else
        {new->next=p->next;p->next=new;}
       
       return(head);
    } 
    /*删除学生信息*/
    
    struct student *delete(struct student *head)
    {int i,j=0;
    	struct student *r,*q;
    	clrscr();
    	gotoxy(35,2);
          printf("删除学生信息\n");
          gotoxy(5,4);
    	printf("输入删除位置第i位的学生记录 :");
    	scanf("%d",&i);
    	r=head;
    	q=r->next;
    	while(++j<i&&q->next!='\0')
    	{r=q;q=r->next;}
    	r->next=q->next;
    	return(head);
    }
    /*修改学生信息*/
struct student *update(struct student *head)
  { struct student *p;
  	int k;
  	clrscr();
  	gotoxy(35,2);
          printf("修改学生信息\n");
  	p=head->next;
  	gotoxy(5,4);
  	printf("输入要修改的学生的学号:");scanf("%d",&k);
  	while(p->no!=k && p->next!='\0')    
      p=p->next;    
    if(p->next=='\0')
     printf("不存在该学号学生");
    else 
       { int x;
       	 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.C语言\n");
       	 printf("\n");
       	 printf("\n");printf("**************************************************************\n");
       	 printf("        请输入要修改的项目:");scanf("%d",&x);
       	 switch(x)
       	  { case 1:printf("      请输入学号:");scanf("%6d",&p->no);break;
       	  	case 2:printf("      请输入姓名:");scanf("%s",p->name);break;
       	  	case 3:printf("      请输入班级:");scanf("%s",p->grade);break;
       	  	case 4:printf("      请输入性别:");scanf("%s",p->sex);break;
       	  	case 5:printf("      请输入出生年月日:");scanf("%d %d %d",&p->birthday.year,&p->birthday.month,&p->birthday.day);break;
       	  	case 6:printf("      请输入数学分数:");scanf("%d",&p->sc.math);break;
       	  	case 7:printf("      请输入英语分数:");scanf("%d",&p->sc.english);break;
       	  	case 8:printf("      请输入C语言分数:");scanf("%d",&p->sc.tc);break; }
       	  
       	      }
         return(head);  
  }
    
    /*按学号从小到大排序*/
   struct student *sort(struct student *head)
    {   struct student *p,*p1,*p2,*t;
    	int n;
    	char ch[10];
    
    p=head;
    p1=p->next;
    if(p1==NULL||p1->next==NULL)
    printf("无法找到信息不能排序");
    for(;p1!=NULL;)
    {p2=p1->next;
    	for(;p2!=NULL;)
    	if((p1->no)>(p2->no))
    	  { n=p1->no;
    	   p1->no=p2->no;
    	   p2->no=n;
    	   strcpy(ch,p1->name);
    	   strcpy(p1->name,p2->name);
    	   strcpy(p2->name,ch);
    	   strcpy(ch,p1->grade);
    	   strcpy(p1->grade,p2->grade);
    	   strcpy(p2->grade,ch);
    	   strcpy(ch,p1->sex);
    	   strcpy(p1->sex,p2->sex);
    	   strcpy(p2->sex,ch);
    	   n=p1->birthday.year;
    	   	p1->birthday.year=p2->birthday.year;
    	   	p2->birthday.year=n;
    	   	n=p1->birthday.month;
    	   	p1->birthday.month=p2->birthday.month;
    	   	p2->birthday.month=n;
    	   	n=p1->birthday.day;
    	   	p1->birthday.day=p2->birthday.day;
    	   	p2->birthday.day=n;
    	   	n=p1->sc.math;
    	   	p1->sc.math=p2->sc.math;
    	   	p2->sc.math=n;
    	   	n=p1->sc.english;
    	   	p1->sc.english=p2->sc.english;
    	   	p2->sc.english=n;
    	   	n=p1->sc.tc;
    	   	p1->sc.tc=p2->sc.tc;
    	   	p2->sc.tc=n;
    	   	
    	p2=p2->next;}
    	else
        p2=p2->next;
    	p1=p1->next;
    	}
    return(head);
    }   
  /*输出学生信息*/  
void display(struct student *head)
{
  struct student *p;
  clrscr();
  gotoxy(35,2);
          printf("输出学生信息\n");
  p=head->next;
  if(p==NULL)
  printf("没有学生信息");
  else
  { gotoxy(1,10);
  	 printf("学号     姓名    班级   性别   生日      数学  英语  C语言\n");
  while(p!=NULL)
  { 
   printf("%d %8s %8s  %4s   %4d-%d-%d %5d  %5d %6d\n",p->no,p->name,p->grade,p->sex,p->birthday.year,p->birthday.month,p->birthday.day,p->sc.math,p->sc.english,p->sc.tc);
   p=p->next;
  } 
  }
  getch();
}
/*查找学生信息*/
   void search(struct student *head)
   { 
   	struct student *p;
     int i, no;
     clrscr();
   	gotoxy(35,2);
          printf("查找学生信息\n");
   loop:
   p=head->next; 
   printf("请输入要查找学生的坐号 :");
   	scanf("%d",&no);
   	
   	while(p->no!=no&&p!=NULL)
   	p=p->next;
   	if(p==NULL)
   	printf("列表中没有学号为 %d 的学生",no);
   	else
   	 {   printf("学号     姓名    班级   性别   生日      数学  英语  C语言\n");
   	     printf("%d %8s %8s  %4s   %4d-%d-%d %5d  %5d %6d\n",p->no,p->name,p->grade,p->sex,p->birthday.year,p->birthday.month,p->birthday.day,p->sc.math,p->sc.english,p->sc.tc);
   	 }
   	 printf("\n");
   	 printf("1.查找其他学生信息.     2.返回主界面");
   printf("请选择:");
   scanf("%d",&i);
   if(i==1) goto loop;
   else if(i==2) getch();
   else printf("输入错误");

   }
   /*把学生信息保存到文件*/
void savefile(struct student *head)
 {
 	FILE *fp;
 	 struct student *p;
 	 clrscr();
 	gotoxy(30,2);
          printf("把学生信息保存到文件\n");
 if((fp=fopen("学生信息.txt","wb"))==NULL)
 {printf("文件不能打开");
  return;
 }
 
 p=head->next;
 while(p!=NULL)
 {fwrite(p,LEN,1,fp);
  p=p->next;
 }
fclose (fp);
gotoxy(10,10);
printf("你已成功把学生信息存入该文件上\n");
gotoxy(10,11);
printf("按任一键进入主菜单......\n");
getch();
return (head);
 }
 
 /*从文件调出学生信息*/
 struct student *load()
{
	FILE *fp;
	 struct student *p,*q,*head;
	 head=(struct student *)malloc(LEN);
	 clrscr();
	 gotoxy(30,2);
          printf("从文件调出学生信息\n");
 if((fp=fopen("stu_list.txt","rb"))==NULL)
 {printf("文件不能打开");
  return(head);
 }
 p=(struct student *)malloc(LEN);
head->next=p;
if(!p)
{printf("输出存储信息");
return(head);
}
while(!feof(fp)) 
{if(fread(p,LEN,1,fp)!=1) break;
p->next=(struct student *)malloc(LEN);  
if(!p->next)
{printf("输出存储信息");
return (head);
}
q=p;        
p=p->next; 	 
}
q->next=NULL;
fclose(fp);
gotoxy(10,10);
printf("你已成功读取到该文件上的学生信息\n");
gotoxy(10,11);
printf("按任一键进入主菜单......\n");
getch();
return (head);
}	
 
  
main()
{
  struct student *head=NULL;
  clrscr();
  while(1)
   {switch(menu_sel())
   	 { case 1: head=create();break;
   	   case 2: head=insert(head);break;
   	   case 3: head=delete(head);break;
   	   case 4: head=update(head);break;
   	   case 5: head=sort(head); break;
   	   case 6: display(head);break;
   	   case 7: search(head);break;
   	   case 8: savefile(head);break;
   	   case 9: head=load();break;
   	   case 10: exit(0);
   	 }
   }
   }

⌨️ 快捷键说明

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