C语言学生管理系统

/* 
* C语言学生管理系统(动态链表版)
* 界面比较混乱,因为只是实现了初步功能,同时学生可以修改自己的成绩,这一点不是很好,后面会改进,还有一些功能需要读者自己去发现和修改,谢谢! * 作者:老猫历险记 * 时间:2017年4月6号 * 功能:增添新键数据 * 平台:linux (Ubuntu)
*/ 创建main.h 内容为下 #ifndef _MAIN_H_ #define _MATH_H_ #include"stu.h" #include"teacher.h" #include"ClassTutor.h" void edit();/*管理员操作界面*/ void interface();/*总登录界面*/ void login_manger();/*管理员登录界面*/ #endif

创建stu.h文件,由于老师、班主任的头文件可以直接用学生的模板来套,所以我详细的讲解stu.h文件的敲写,需要和stu.c函数一起看。
 1 #ifndef _STU_H_
 2 #define _STU_H_
 3 #include<stdio.h>
 4 #include<string.h>
 5 #include<stdlib.h>
 6 #define NONE  "33[m" /*宏定义声明颜色*/
 7 #define RED   "33[0;32;31m" 
 8 #define LIGHT_RED    "33[1;31m" 
 9 #define GREEN         "33[0;32;32m" 
10 #define LIGHT_GREEN   "33[1;32m" 
11 #define BLUE          "33[0;32;34m" 
12 #define LIGHT_BLUE    "33[1;34m" 
13 #define DARY_GRAY     "33[1;30m" 
14 #define CYAN          "33[0;36m" 
15 #define LIGHT_CYAN    "33[1;36m" 
16 #define PURPLE        "33[0;35m" 
17 #define LIGHT_PURPLE     "33[1;35m" 
18 #define BROWN            "33[0;33m" 
19 #define YELLOW           "33[1;33m" 
20 #define LIGHT_GRAY       "33[0;37m" 
21 #define WHITE            "33[1;37m"/*宏定义声明颜色,一共16种颜色*/
22 #define LL sizeof(NODE)   /*宏定义,说明sizeof(NODE)用LL替换*/
23typedef struct student  /*结构体数据,包含学生内容的所有数据*/
24 {
25     char name[32];  /*定义字符串类型数据*/
26     char pawd[32];  /*定义字符串类型数据*/
27     char id[32];  /*定义字符串类型数据*/
28     int clss;    /*定义整型数据*/
29     char obje[32];  /*定义字符串类型数据*/
30     float cpro;    /*定义单精度类型数据*/
31     float chin;    /*定义单精度类型数据*/
32     float math;    /*定义单精度类型数据*/
33     float add;    /*定义单精度类型数据*/
34 }S;//学生结构体
35 
36 typedef struct node
37 {
38     S student;/*内嵌S型结构体数据变量student*/
39     struct node* next;/*指向自身结构体的指针*/
40 }NODE,*PH;//学生初始链表构建有内容头结点,此处定义了一种node结构体的NODE类型,NODE现在是类型名,后面数据读取分配大小时需要用到NODE。
41 
42 typedef struct head
43 {
44     int len_s;
45     struct node *pfhead;
46 }Head,*PF;//学生空头结点,说明的是后面利用PF,先创建一个空指针节点,指针指向空,节点存取数据len_s.
47 
48 void login_student();/*学生登录界面,直接登录没有参数和返回值*/
49 void edit_student();/*登录嵌入函数,编辑学生的信息,没有传参和返回值*/
50 PF creat_student();/*创建学生存储链表,由于需要返回空节点指针(也是链表的头),所以需要定义为PF类型*/
51 PH student_data();/*创建学生信息,由于创建的节点是保存学生的信息的,需要定义为PH类型*/
52 PF insert_student(PF phead);/*插入学生信息,利用头结点的移动和student_data的返回值来添加,需要返回一个头结点,所以定义为PF型*/
53 PF modify_student_list(PF phead);/*修改学生信息,利用头结点的传参遍历来获取学生数据,比较进行修改数据,这边需要进行传参和返回值,类型为PF*/
54 void search_student(PF phead);/*搜索学生信息,利用头结点的传参遍历来搜索学生信息,由于不需要改变学生信息,所以不需要返回值*/
55 PF read_student();/*读取学生信息,利用创建空节点的函数来不断将文本中的数据读取添加到所创建的新链表中,同时返回头节点,所以函数定义需要使用PF类型*/
56 void prin_student(PF phead);/*打印学生信息,打印学生信息使用到传参,在函数内部创建一个PH类型数据节点==传参节点指向下一个的结构体内容*/
57 void save_student(PF phead);/*保存学生信息,利用头结点的传参和新建PH类型的数据节点来遍历存取数据,所以需要传参,是否需要返回值,由于对链表无操作,所以不需要返回值*/
58 PF delete_student(PF phead);/*删除学生信息,由于需要使用到头结点进行传参,同时返回修改后的头结点,所以需要使用到PF来定义。*/
59 #endif
创建teacher.h文件
 1 #ifndef _TEACHER_H_
 2 #define _TEACHER_H_
 3 #define DD sizeof(Date)
 4 #include"stu.h"
 5 typedef struct teacher
 6 {
 7     char name[32];
 8     char pawd[32];
 9     char clss[32];
10     char id[32];
11 }T;//老师结构体
12 
13 typedef struct date
14 {
15     T teacher;
16     struct date* next;
17 }Date,*PT;//老师初始链表构建有内容头结点
18 
19 typedef struct back
20 {
21     int len_t;
22     struct date *pbhead;
23 }Back,*PB;//老师空头结点
24 
25 void login_teacher();/*老师登录界面*/
26 PB creat_teacher();/*创建老师存储链表*/
27 PT teacher_data();/*创建老师信息*/
28 void get_teacher_data();/*老师对学生和自己的操作*/
29 PB insert_teacher(PB phead);/*插入老师信息*/
30 void search_teacher(PB phead);/*搜索老师信息*/
31 void prin_teacher(PB phead);/*打印老师信息*/
32 PB modify_teacher_list(PB phead);/*修改老师信息*/
33 PB delete_teacher(PB phead);/*删除老师信息*/
34 PB read_teacher();/*打开老师存储文本信息*/
35 void save_teacher(PB phead);/*保存老师信息*/
36 
37 #endif

创建ClassTutor.h文件

 1 #ifndef _CLASS_TUTOR_H_
 2 #define _CLASS_TUTOR_H_
 3 #include"stu.h"
 4 #include"teacher.h"
 5 #define PsP sizeof(P_class_Tutor)
 6 typedef struct Class_Tutor
 7 {
 8     char ID[32];
 9     char name[32];
10     char pawd[32];    
11 }C;
12 
13 typedef struct class_Tutor
14 {
15     C Class_Tutor;
16     struct class_Tutor *next;
17 }P_class_Tutor,*PC;
18 typedef struct pm
19 {
20     int len_c;
21     struct class_Tutor *pchead;
22 }lp,*PM;//老师空头结点
23 
24 void edit_Class_Tutor();/*班主任编辑内容*/
25 void login_Class_Tutor();/*班主任登录界面*/
26 PM creat_Class_Tutor();/*创建班主任存储链表*/
27 PC Class_Tutor_data();/*创建班主任信息*/
28 PM insert_Class_Tutor(PM phead);/*插入班主任信息*/
29 void prin_Class_Tutor(PM phead);/*打印班主任信息*/
30 PM modify_Class_Tutor_list(PM phead);/*修改班主任信息*/
31 void search_Class_Tutor(PM phead);/*搜索班主任信息*/
32 PM delete_Class_Tutor(PM phead);/*删除班主任信息*/
33 PM read_Class_Tutor();/*打开班主任存储文本信息*/
34 void save_Class_Tutor(PM phead);/*保存班主任信息*/
35 #endif

创建stu.c文件

  1 #include"stu.h"
  2 /*******************************************************************************************
  3 创建空节点指针,用来指向内容首节点。
  4 创建头指针用来指向链表第一个元素        phead->pfhead=NULL   !!!
  5 *******************************************************************************************/
  6 
  7 PF creat_student()
  8 {
  9     PF phead=NULL;
 10     phead=(PF)malloc(sizeof(Head));
 11     phead->pfhead=NULL;
 12     phead->len_s=0;
 13     return phead;
 14 }
 15 
 16 /*******************************************************************************************
 17 
 18 录信息函数      p=(PH)malloc(LL)
 19 *******************************************************************************************/
 20 
 21 PH student_data()
 22 {
 23     PH p;
 24     p=(PH)malloc(LL);
 25     printf("请输入以下信息

");
 26     printf("NAME:");
 27     scanf("%s",p->student.name);
 28     getchar();
 29     printf("PAWD:");
 30     scanf("%s",p->student.pawd);
 31     getchar();
 32     printf("ID:");
 33     scanf("%s",p->student.id);
 34     getchar();
 35     printf("CLSS:");
 36     scanf("%d",&p->student.clss);
 37     getchar();
 38     printf("OBJE:");
 39     scanf("%s",p->student.obje);
 40     getchar();
 41     printf("CPRO:");
 42     scanf("%f",&p->student.cpro);
 43     getchar();
 44     printf("CHIN:");
 45     scanf("%f",&p->student.chin);
 46     getchar();
 47     printf("MATH:");
 48     scanf("%f",&p->student.math);
 49     getchar();
 50     printf("ADD:");
 51     scanf("%f",&p->student.add);
 52     getchar();
 53     
 54 
 55     return p;
 56 }
 57 
 58 
 59 
 60 
 61 
 62 /*******************************************************************************************
 63 
 64 创建链表     p->next=phead->pfhead;       phead->pfhead=p;
 65 *******************************************************************************************/
 66 PF insert_student(PF phead)
 67 {
 68     PH p=NULL;
 69     int i=0,k=0;
 70     while(1)
 71     {
 72         if(k!=0)
 73         {
 74             printf("if want to add ,input 1	exit:input 0
");
 75             printf("your choose:");
 76             scanf("%d",&i);
 77             getchar();
 78             if(i==0)
 79             {
 80                 break;
 81             }
 82         }
 83         p=student_data();
 84         p->next=phead->pfhead;
 85         phead->pfhead=p;
 86         k++;
 87         phead->len_s++;
 88     }
 89 
 90     return phead;
 91 }
 92 
 93 
 94 /*******************************************************************************************
 95 
 96 输出链表    
 97 *******************************************************************************************/
 98 void prin_student(PF phead)
 99 {
100     PH p=phead->pfhead;
101     printf("学生信息如下:
");
102     printf("姓名	密码	昵称	班级	专业	c语言	语文	数学	总分
");
103     while(p!=NULL)
104     {
105         printf("%-8s%-8s%-8s%-8d%-8s%-8.2f%-8.2f%-8.2f%-8.2f
",p->student.name,p->student.pawd,p->student.id,p->student.clss,p->student.obje,p->student.cpro,p->student.chin,p->student.math,p->student.cpro+p->student.chin+p->student.math);
106         p=p->next;
107     }
108     //printf("any exit");
109     //getchar();
110 }
111 
112 
113 /*******************************************************************************************
114 
115 查找链表中学生的信息
116 *******************************************************************************************/
117 
118 void search_student(PF phead)
119 {
120     PH p=phead->pfhead;
121     char id[32];
122     printf("please input id:");
123     scanf("%s",id);
124     getchar();
125     while(p!=NULL)
126     {
127     if(strcmp(p->student.id,id)==0)
128     {
129         printf("%-8s%-8s%-8s%-8d%-8s%-8.2f%-8.2f%-8.2f%-8.2f
",p->student.name,p->student.pawd,p->student.id,p->student.clss,p->student.obje,p->student.cpro,p->student.chin,p->student.math,p->student.add);
130     return ;
131     }
132         p=p->next;
133     }
134     printf("no this boy
");
135     printf("input any to exit:");
136     getchar();
137     return ;
138 }
139 /*******************************************************************************************************************
140 
141 删除链表中的信息    p2=p1;     p1=p1->next;
142 *******************************************************************************************************************/
143 PF delete_student(PF phead)
144 {
145     PH p1=phead->pfhead;
146     PH p2;
147     char name[32];
148     printf("
input  NAME:");
149     scanf("%s",name);
150     getchar();
151     while(p1!=NULL&&strcmp(name,p1->student.name))
152     {
153         p2=p1;
154         p1=p1->next;
155     }
156     if(strcmp(p1->student.name,name)==0)
157     {    
158         printf("是否确定删除!");
159         printf("确定删除请输入:1   取消:0
");
160         int i;
161         scanf("%d",&i);
162         if(i==1)
163     {
164         if(p1==phead->pfhead)
165         {
166             phead->pfhead=p1->next;
167         }
168         else
169         {
170             p2->next=p1->next;
171         }
172         phead->len_s--;
173     }
174         if(i==0)return phead;
175     }
176     return phead;
177 }
178 /********************************************
179 修改学生信息
180 
181 ********************************************/
182 
183 PF modify_student_list(PF phead)
184 {
185     PH temp;
186     char ch[32];
187     int a;
188     printf("输入需要修改的ID:");
189     scanf("%s",ch);
190     getchar();
191     temp=(PH)malloc(sizeof(NODE));
192     temp=phead->pfhead;
193     while(temp!=NULL)
194     {
195         if(strcmp(temp->student.id,ch)==0)
196         {    
197             break;
198         }
199         temp=temp->next;
200     }
201     if(temp==NULL)
202     {
203         printf("无此id
");
204         getchar();
205         printf("按任意键退出");
206         return phead;
207     }
208     else
209     {
210         printf("开始修改
");
211         while(1)
212         {
213             printf("1:名字  2:密码  3:id 4:班级 5:科目 6:c语言 7:语文 8:数学 9:离开
");
214             scanf("%d",&a);
215             getchar();
216             switch(a)
217             {
218                 case 1:
219                         printf("名字:");
220                         scanf("%s",temp->student.name);
221                         getchar();
222                         printf("修改成功
");
223                         break;
224                 case 2:
225                         printf("密码");
226                         scanf("%s",temp->student.pawd);
227                         getchar();
228                         printf("修改成功
");
229                         break;                
230                 case 3:
231                         printf("id:");
232                         scanf("%s",temp->student.id);
233                         getchar();
234                         printf("修改成功
");
235                         break;
236                 case 4:
237                         printf("班级:");
238                         scanf("%d",&temp->student.clss);
239                         getchar();
240                         printf("修改成功
");
241                         break;
242                 case 5:
243                         printf("科目:");
244                         scanf("%s",temp->student.obje);
245                         getchar();
246                         printf("修改成功
");
247                         break;
248                 case 6:
249                         printf("c语言:");
250                         scanf("%f",&temp->student.cpro);
251                         getchar();
252                         printf("修改成功
");
253                         break;
254                 case 7:
255                         printf("语文:");
256                         scanf("%f",&temp->student.chin);
257                         getchar();
258                         printf("修改成功
");
259                         break;
260                 case 8:
261                         printf("数学:");
262                         scanf("%f",&temp->student.math);
263                         getchar();
264                         printf(
265 "修改成功
");
266                         break;
267                 case 9:
268                         return phead;
269                 default:
270                         printf("输入非法
");
271                         break;
272 
273             }
274         }
275     }
276 }
277 
278 /*******************************************************************************************
279 
280 保存链表到文件中   fwrite(p,LL,1,fp)
281 *******************************************************************************************/
282 
283 void save_student(PF phead)
284 {
285     FILE *fp;
286     fp=fopen("STU.txt","w");
287     PH p=phead->pfhead;
288     while(p!=NULL)
289     {
290         fwrite(p,LL,1,fp);
291         p=p->next;
292     }
293     fclose(fp);
294 }
295 
296 /*******************************************************************************************
297 10534672        -nan    -16026678757718275813152237186711552.00
298 读取文件中的数据到链表中    while(fread(p,LL,1,fp))    p->next=phead->pfhead;    phead->pfhead=p
299 *******************************************************************************************/
300 PF read_student()
301 {
302     FILE *fp;
303     fp=fopen("STU.txt","r");
304     PF phead=creat_student();
305     PH p=(PH)malloc(LL);
306     while(fread(p,LL,1,fp)!=0)
307     {
308         p->next=phead->pfhead;
309         phead->pfhead=p;
310         p=(PH)malloc(LL);
311         phead->len_s++;
312     }
313     fclose(fp);
314     return phead;
315 }
View Code

创建teacher.c文件

  1 #include"teacher.h"
  2 PB creat_teacher()
  3 {
  4     PB phead=NULL;
  5     phead=(PB)malloc(sizeof(Back));
  6     phead->pbhead=NULL;
  7     phead->len_t=0;
  8     return phead;
  9     printf("请任意键退出:");
 10     getchar();
 11 }
 12 
 13 /*创建老师信息*/
 14 
 15 PT teacher_data()
 16 {
 17     PT p;
 18     p=(PT)malloc(DD);
 19     printf("请输入以下信息

");
 20     printf("NAME:");
 21     scanf("%s",p->teacher.name);
 22     getchar();
 23     printf("PAWD:");
 24     scanf("%s",p->teacher.pawd);
 25     getchar();
 26     printf("ID:");
 27     scanf("%s",p->teacher.id);
 28     getchar();
 29     printf("Class:");
 30     scanf("%s",p->teacher.clss);
 31     getchar();
 32     printf("please input any to exit:");
 33     getchar();
 34     return p;
 35 }
 36 /*插入数据:老师信息*/
 37 PB insert_teacher(PB phead)
 38 {
 39     PT p=NULL;
 40     int i=0,k=0;
 41     while(1)
 42     {
 43         if(k!=0)
 44         {
 45             printf("if want to add ,input 1	  exit:input 0
");
 46             printf("your choose:");
 47             scanf("%d",&i);
 48             getchar();
 49             if(i==0)
 50             {
 51                 break;
 52             }
 53         }
 54         p=teacher_data();
 55         p->next=phead->pbhead;
 56         phead->pbhead=p;
 57         k++;
 58         phead->len_t++;
 59     }
 60 
 61     return phead;
 62 }
 63 
 64 /*打印老师信息*/
 65 void prin_teacher(PB phead)
 66 {
 67     PT p=phead->pbhead;
 68     printf("任课老师信息如下:
");
 69     printf("姓名	密码	ID	班级
");
 70     while(p!=NULL)
 71     {
 72         printf("%-8s%-8s%-8s%-8s
",p->teacher.name,p->teacher.pawd,p->teacher.id,p->teacher.clss);
 73         p=p->next;
 74     }
 75     printf("any exit");
 76     getchar();
 77 }
 78 
 79 /*搜索老师信息*/
 80 void search_teacher(PB phead)
 81 {
 82     PT p=phead->pbhead;
 83     char id[32];
 84     printf("please input ID:");
 85     scanf("%s",id);
 86     getchar();
 87     if(p==NULL)exit(1);
 88     while(p!=NULL&&strcmp(id,p->teacher.id)!=0)
 89     {
 90         p=p->next;
 91 
 92     }
 93     if(strcmp(id,p->teacher.id)==0)
 94     {
 95         printf("%-8s%-8s%-8s%-8s
",p->teacher.name,p->teacher.pawd,p->teacher.id,p->teacher.clss);
 96     }
 97     else
 98     {
 99         printf("此老师不存在
");
100     }
101     printf("input any to exit:");
102     getchar();
103 }
104 
105 PB delete_teacher(PB phead)
106 {
107     PT p1=phead->pbhead;
108     PT p2;
109     char name[32];
110     printf("
input  NAME:");
111     scanf("%s",name);
112     getchar();
113     while(p1!=NULL&&strcmp(name,p1->teacher.name))
114     {
115         p2=p1;
116         p1=p1->next;
117     }
118     if(strcmp(p1->teacher.name,name)==0)
119     {
120         if(p1==phead->pbhead)
121         {
122             phead->pbhead=p1->next;
123         }
124         else
125         {
126             p2->next=p1->next;
127         }
128         phead->len_t--;
129     }
130     return phead;
131 }
132 /*修改老师信息*/
133 PB modify_teacher_list(PB phead)
134 {
135     PB temp;
136     char ch[32];
137     int a;
138     printf("输入需要修改的ID:");
139     scanf("%s",ch);
140     getchar();
141     temp=(PB)malloc(sizeof(Back));
142     temp->pbhead=phead->pbhead;
143     while(temp->pbhead!=NULL)
144     {
145         if(strcmp(temp->pbhead->teacher.id,ch)==0)
146         {    
147             break;
148         }
149         temp->pbhead=phead->pbhead;
150     }
151     if(temp->pbhead==NULL)
152     {
153         printf("无此id
");
154         getchar();
155         return phead;
156     }
157     else
158     {
159         printf("开始修改
");
160         while(1)
161         {
162             printf("1:名字  2:密码  3:id 4:班级 0:离开
");
163             scanf("%d",&a);
164             getchar();
165             switch(a)
166             {
167                 case 1:
168                         printf("名字:");
169                         scanf("%s",temp->pbhead->teacher.name);
170                         getchar();
171                         printf("修改成功
");
172                         break;
173                 case 2:
174                         printf("密码");
175                         scanf("%s",temp->pbhead->teacher.pawd);
176                         getchar();
177                         printf("修改成功
");
178                         break;                
179                 case 3:
180                         printf("id:");
181                         scanf("%s",temp->pbhead->teacher.id);
182                         getchar();
183                         printf("修改成功
");
184                         break;
185                 case 4:
186                         printf("班级:");
187                         scanf("%s",temp->pbhead->teacher.clss);
188                         getchar();
189                         printf("修改成功
");
190                         break;
191                 case 0:
192                         return phead;
193                 default:
194                         printf("输入非法
");
195                         break;
196 
197             }
198         }
199     }
200 }
201 
202 void save_teacher(PB phead)
203 {
204     FILE *fp;
205     fp=fopen("TEACHER.txt","w");
206     PT p=phead->pbhead;
207     while(p!=NULL)
208     {
209         fwrite(p,DD,1,fp);
210         p=p->next;
211     }
212     fclose(fp);
213 }
214 /*读取文件中的数据到链表中    while(fread(p,DD,1,fp))    p->next=phead->pbhead;    phead->pbhead=p*/
215 PB read_teacher()
216 {
217     FILE *fp;
218     fp=fopen("TEACHER.txt","r");
219     PB phead=creat_teacher();
220     PT p=(PT)malloc(DD);
221 
222     while(fread(p,DD,1,fp)!=0)
223     {
224         p->next=phead->pbhead;
225         phead->pbhead=p;
226         p=(PT)malloc(DD);
227         phead->len_t++;
228     }
229     fclose(fp);
230     return phead;
231 }
View Code

创建main.c文件

1 #include"main.h"
2 int main()
3 {
4     interface();
5     return 0;
6 }
View Code

创建interface.c文件

 1 #include"main.h"
 2 void interface()
 3 {
 4     while(1)
 5     {
 6         printf("						用户请登录:
");
 7         printf("						1.管理员登陆:
");
 8         printf("						2.教师登录:
");
 9         printf("						3.班主任登陆:
");
10         printf("						4.学生登陆:
");
11         printf("						退出:0
");
12         int n;
13         printf("						请输入你的选择:");
14         scanf("%d",&n);
15         switch(n)
16         {
17             case 1:login_manger();break;
18             case 2:login_teacher();break;
19             case 3:login_Class_Tutor();break;
20             case 4:login_student();break;
21             case 0:break;
22             default:printf("已退出
");break;
23         }
24         if(n==0)
25             break;
26     }
27     return;
28 }
View Code

创建Class_Tutor.c文件

  1 #include"ClassTutor.h"
  2 PM creat_Class_Tutor()
  3 {
  4     PM phead=NULL;
  5     phead=(PM)malloc(sizeof(lp));
  6     phead->pchead=NULL;
  7     phead->len_c=0;
  8     return phead;
  9 }
 10 
 11 /*创建班主任信息*/
 12 
 13 PC Class_Tutor_data()
 14 {
 15     PC p;
 16     p=(PC)malloc(sizeof(C));
 17     printf("请输入以下信息

");
 18     printf("NAME:");
 19     scanf("%s",p->Class_Tutor.name);
 20     getchar();
 21     printf("PAWD:");
 22     scanf("%s",p->Class_Tutor.pawd);
 23     getchar();
 24     printf("ID:");
 25     scanf("%s",p->Class_Tutor.ID);
 26     getchar();
 27     printf("please input any to exit:");
 28     getchar();
 29     return p;
 30 }
 31 /*插入数据:班主任信息*/
 32 PM insert_Class_Tutor(PM phead)
 33 {
 34     PC p=NULL;
 35     int i=0,k=0;
 36     while(1)
 37     {
 38         if(k!=0)
 39         {
 40             printf("if want to add ,input 1	  exit:input 0
");
 41             printf("your choose:");
 42             scanf("%d",&i);
 43             getchar();
 44             if(i==0)
 45             {
 46                 break;
 47             }
 48         }
 49         p=Class_Tutor_data();
 50         p->next=phead->pchead;
 51         phead->pchead=p;
 52         k++;
 53         phead->len_c++;
 54     }
 55 
 56     return phead;
 57 }
 58 
 59 /*打印班主任信息*/
 60 void prin_Class_Tutor(PM phead)
 61 {
 62     PC p=phead->pchead;
 63     printf("班主任信息如下:
");
 64     printf("姓名	密码	ID
");
 65     while(p!=NULL)
 66     {
 67         printf("%-8s%-8s%-8s
",p->Class_Tutor.name,p->Class_Tutor.pawd,p->Class_Tutor.ID);
 68         p=p->next;
 69     }
 70     printf("any exit");
 71     getchar();
 72 }
 73 
 74 /*搜索班主任信息*/
 75 void search_Class_Tutor(PM phead)
 76 {
 77     PC p=phead->pchead;
 78     char id[32];
 79     printf("please input ID:");
 80     scanf("%s",id);
 81     getchar();
 82     if(p==NULL)exit(1);
 83     while(p!=NULL&&strcmp(id,p->Class_Tutor.ID)!=0)
 84     {
 85         p=p->next;
 86 
 87     }
 88     if(strcmp(id,p->Class_Tutor.ID)==0)
 89     {
 90         printf("%-8s%-8s%-8s
",p->Class_Tutor.name,p->Class_Tutor.pawd,p->Class_Tutor.ID);
 91     }
 92     else
 93     {
 94         printf("此班主任不存在
");
 95     }
 96     printf("input any to exit:");
 97     getchar();
 98 }
 99 
100 PM delete_Class_Tutor(PM phead)
101 {
102     PC p1=phead->pchead;
103     PC p2;
104     char id[32];
105     printf("
input  ID:");
106     scanf("%s",id);
107     getchar();
108     while(p1!=NULL&&strcmp(id,p1->Class_Tutor.ID))
109     {
110         p2=p1;
111         p1=p1->next;
112     }
113     if(strcmp(p1->Class_Tutor.ID,id)==0)
114     {
115         if(p1==phead->pchead)
116         {
117             phead->pchead=p1->next;
118         }
119         else
120         {
121             p2->next=p1->next;
122         }
123         phead->len_c--;
124     }
125     return phead;
126 }
127 /*修改班主任信息*/
128 PM modify_Class_Tutor_list(PM phead)
129 {
130     PC temp;
131     char ch[32];
132     int a;
133     printf("输入需要修改的班主任ID:");
134     scanf("%s",ch);
135     getchar();
136     temp=(PC)malloc(sizeof(C));
137     temp=phead->pchead;
138     while(temp!=NULL)
139     {
140         if(strcmp(temp->Class_Tutor.ID,ch)==0)
141         {    
142             break;
143         }
144         temp=temp->next;
145     }
146     if(temp==NULL)
147     {
148         printf("无此id
");
149         getchar();
150         return phead;
151     }
152     else
153     {
154         printf("开始修改
");
155         while(1)
156         {
157             printf("1:名字  2:密码  3:id  0:离开
");
158             scanf("%d",&a);
159             getchar();
160             switch(a)
161             {
162                 case 1:
163                         printf("名字:");
164                         scanf("%s",temp->Class_Tutor.name);
165                         getchar();
166                         printf("修改成功
");
167                         break;
168                 case 2:
169                         printf("密码");
170                         scanf("%s",temp->Class_Tutor.pawd);
171                         getchar();
172                         printf("修改成功
");
173                         break;                
174                 case 0:
175                         return phead;
176                 default:
177                         printf("输入非法
");
178                         break;
179 
180             }
181         }
182     }
183 }
184 
185 void save_Class_Tutor(PM phead)
186 {
187     FILE *fp;
188     fp=fopen("Class_Tutor.txt","w");
189     PC p=phead->pchead;
190     while(p!=NULL)
191     {
192         fwrite(p,PsP,1,fp);
193         p=p->next;
194     }
195     fclose(fp);
196 }
197 /*读取文件中的数据到链表中    while(fread(p,DD,1,fp))    p->next=phead->pchead;    phead->pchead=p*/
198 PM read_Class_Tutor()
199 {
200     FILE *fp;
201     fp=fopen("Class_Tutor.txt","r");
202     PM phead=creat_Class_Tutor();
203     PC p=(PC)malloc(PsP);
204 
205     while(fread(p,PsP,1,fp)!=0)
206     {
207         p->next=phead->pchead;
208         phead->pchead=p;
209         p=(PC)malloc(PsP);
210         phead->len_c++;
211     }
212     fclose(fp);
213     return phead;
214 }
View Code

创建login_Class_Tutor.c文件

 1 #include"main.h"
 2 void login_Class_Tutor()
 3 {
 4     char id[100],passwd[100];
 5     printf("请输入班主任ID:");
 6     scanf("%s",id);
 7     getchar();
 8     printf("请输入密码:");
 9     scanf("%s",passwd);
10     getchar();
11     PC p=(PC)malloc(PsP);
12     PM Read=read_Class_Tutor();
13     p=Read->pchead;
14     do
15 {
16     if(strcmp(p->Class_Tutor.ID,id)==0&&strcmp(p->Class_Tutor.pawd,passwd)==0)
17     {
18         printf("欢迎%s班主任登录:
",p->Class_Tutor.name);
19         edit_Class_Tutor();
20     }
21     p=p->next;
22 }while(p!=NULL);
23     printf("按任意键退出:");
24     getchar();
25     return ;
26 }
27 
28 void edit_Class_Tutor()
29 {
30     PF phead;
31 
32     while(1)
33     {    
34         
35         printf(CYAN  "********************     1:读取学生数据    *********************************
");
36         printf(GREEN "********************     2:搜索学生数据     *********************************
");
37         printf(GREEN "********************     3:保存学生数据     *********************************
");
38         printf(YELLOW"********************     4:打印学生信息    *********************************
");
39         printf(BLUE "********************      5:修改学生数据    **********************************
");
40         printf(BROWN"********************      0:退出        **********************************
");
41         int key;
42         printf(WHITE "



				请选择:");
43         scanf("%d",&key);
44         getchar();
45         switch(key)
46         {
47             case 4:prin_student(phead);           break;
48             case 2:search_student(phead);         break; 
49             case 3:save_student(phead);           break;
50             case 1:phead=read_student();          break;
51             case 5:modify_student_list(phead);    break;
52             case 0:break;
53         }
54         //system("clear");
55         if(key==0)
56         {
57             break;
58         }    
59     }
60 
61 }
View Code

创建login_teacher.c文件

 1 #include"stu.h"
 2 #include"teacher.h"
 3 
 4 
 5 void login_teacher()
 6 {
 7     char id[100],passwd[100];
 8     printf("请输入老师登录ID:");
 9     scanf("%s",id);
10     getchar();
11     printf("请输入老师登录密码:");
12     scanf("%s",passwd);
13     getchar();
14     PT Read=(PT)malloc(DD);
15     PB p=read_teacher();
16     Read=p->pbhead;
17     if(Read==NULL){printf("未注册老师信息!
");return;}
18     do
19     {
20     if(strcmp(Read->teacher.id,id)==0&&strcmp(Read->teacher.pawd,passwd)==0)
21     {       
22         printf("欢迎%s老师登录:
",Read->teacher.name);
23         printf("%-8s%-8s%-8s%-8s
",Read->teacher.name,Read->teacher.pawd,Read->teacher.id,Read->teacher.clss);
24         get_teacher_data();
25     }
26     Read=Read->next;
27     }while(Read!=NULL);
28     printf("按任意键退出:");
29     getchar();
30     return ;
31 }
32 
33 /*切屏*/
34 void get_teacher_data()
35 {
36     PB pbhead;
37     PF phead;
38     while(1)
39     {        
40             //system("clear");
41             printf(GREEN "********************     1:读取学生数据     *********************************
");
42             printf(CYAN  "********************     2:打印学生信息   *********************************
");
43             printf(PURPLE"********************     3:搜索学生数据     ********************************
");
44             printf(GREEN "********************     4:保存学生数据     *********************************
");
45             printf(BLUE "********************      5:修改学生成绩   **********************************
");                
46             printf(BLUE "********************      6:创建读取老师成绩的节点   **********************************
");
47             printf(GREEN "********************     7:修改老师自己信息     *********************************
");
48             printf(GREEN "********************     8:保存老师自己信息     *********************************
");
49             printf(BROWN"********************      0:退出        **********************************
");
50             int i;
51             printf(WHITE "



				请选择:");
52             scanf("%d",&i);
53             switch(i)
54             {
55             case 6:pbhead=read_teacher();               break;
56             case 2:prin_student(phead);                break;
57             case 3:search_student(phead);              break; 
58             case 4:save_student(phead);                break;
59             case 1:phead=read_student();               break;
60             case 5:modify_student_list(phead);         break;
61             case 7:modify_teacher_list(pbhead);        break;
62             case 8:save_teacher(pbhead);               break;
63             case 0:break;
64             }
65 
66         
67         if(i==0)
68         {
69             break;
70         }    
71 }
72 }
View Code

创建login_student.c文件

 1 #include"stu.h"
 2 void login_student()
 3 {
 4     char id[100],passwd[100];
 5     printf("请输入学生ID:");
 6     scanf("%s",id);
 7     getchar();
 8     printf("请输入密码:");
 9     scanf("%s",passwd);
10     getchar();
11     PF p=(PF)malloc(sizeof(Head));
12     PH Read=(PH)malloc(LL);
13     p=read_student();
14     Read->next=p->pfhead;
15     do 
16     {
17         if(strcmp(Read->student.id,id)==0&&strcmp(Read->student.pawd,passwd)==0)
18     {
19         printf("欢迎%s登录:
",Read->student.id);
20         edit_student();
21     }
22         Read=Read->next;
23     }while(Read!=NULL);
24     printf("按任意键退出:");
25     getchar();
26     return ;
27 }
28 
29 void edit_student()
30 {
31     PF phead;
32 
33     while(1)
34     {    
35         system("clear");
36         printf(CYAN  "********************     1:打印学生信息    *********************************
");
37         printf(GREEN "********************     2:保存数据     *********************************
");
38         printf(YELLOW"********************     3:读取数据    *********************************
");
39         printf(BLUE "********************      4:修改数据    **********************************
");
40          printf(BLUE "********************     5:搜索数据    **********************************
");
41         printf(BROWN"********************      0:退出        **********************************
");
42         int key;
43         printf(WHITE "



				请选择:");
44         scanf("%d",&key);
45         getchar();
46         switch(key)
47         {
48             case 1:prin_student(phead);           break;
49             case 2:save_student(phead);           break;
50             case 3:phead=read_student();          break;
51             case 4:modify_student_list(phead);    break;
52             case 5:search_student(phead);         break; 
53             case 0:break;
54         }
55 
56         if(key==0)
57         {
58             break;
59         }    
60     }
61 
62 }
View Code

  创建login_manger.c文件

  1 #include"main.h"
  2 void login_manger()
  3 {
  4         
  5     const char manger_name[]={"admin"};
  6     const char manger_passwd[]={"admin"};
  7     char id[100],passwd[100];
  8     printf("请输入管理员ID:");
  9     scanf("%s",id);
 10     getchar();
 11     printf("请输入管理员密码:");
 12     scanf("%s",passwd);
 13     getchar();
 14     if(strcmp(manger_name,id)==0&&strcmp(manger_passwd,passwd)==0)
 15     {
 16         printf("欢迎管理员:
");
 17         edit();
 18     }
 19     else
 20     {
 21         printf("无权进行此操作!
");
 22     }
 23     printf("按任意键退出:");
 24     getchar();
 25     return ;
 26 }
 27 
 28 /*切屏*/
 29 void edit()
 30 {
 31     PF phead;
 32     PB pbhead;
 33     PM plhead;
 34     while(1)
 35     {
 36         //system("clear");
 37         printf(GREEN"1:管理学生信息
");
 38         printf(GREEN"2:管理老师信息
");
 39         printf(GREEN"3:管理班主任信息
");
 40         printf(GREEN"0:退出
");
 41         int key;
 42         scanf("%d",&key);
 43         if(key==1)
 44         {    
 45             system("clear");
 46             printf(GREEN "********************     1:创建学生链表     *********************************
");
 47             printf(BLUE  "********************     2:创建学生信息     ********************************
");
 48             printf(CYAN  "********************     3:打印学生信息    *********************************
");
 49             printf(PURPLE"********************     4:搜索学生数据     ********************************
");
 50             printf(GREEN "********************     5:保存学生数据     *********************************
");
 51             printf(YELLOW"********************     6:读取学生数据    *********************************
");
 52             printf(WHITE  "********************    7:删除学生数据    ********************************
");
 53             printf(BLUE "********************      8:修改学生数据    **********************************
");
 54             printf(BROWN"********************      0:退出        **********************************
");
 55             int i;
 56             printf(WHITE "



				请选择:");
 57             scanf("%d",&i);
 58             switch(i)
 59             {
 60             case 1:phead=creat_student();               break;    
 61             case 2:insert_student(phead);               break;
 62             case 3:prin_student(phead);                break;
 63             case 4:search_student(phead);              break; 
 64             case 5:save_student(phead);                break;
 65             case 6:phead=read_student();               break;
 66             case 7:phead=delete_student(phead);        break;
 67             case 8:modify_student_list(phead);         break;
 68             case 0:break;
 69             }
 70         }
 71 
 72         if(key==2)
 73         {    
 74             system("clear");
 75             printf(GREEN "********************     1:创建老师链表     *********************************
");
 76             printf(BLUE  "********************     2:创建老师信息     ********************************
");
 77             printf(CYAN  "********************     3:打印老师信息    *********************************
");
 78             printf(PURPLE"********************     4:搜索老师数据     ********************************
");
 79             printf(GREEN "********************     5:保存老师数据     *********************************
");
 80             printf(YELLOW"********************     6:读取老师数据    *********************************
");
 81             printf(WHITE  "********************    7:删除老师数据    ********************************
");
 82             printf(BLUE "********************      8:修改老师数据    **********************************
");
 83             printf(BROWN"********************      0:退出        **********************************
");
 84             int i;
 85             printf(WHITE "



				请选择:");
 86             scanf("%d",&i);
 87             switch(i)
 88             {
 89             case 1:pbhead=creat_teacher();                 break;    
 90             case 2:insert_teacher(pbhead);                 break;
 91             case 3:prin_teacher(pbhead);                 break;
 92             case 4:search_teacher(pbhead);               break; 
 93             case 5:save_teacher(pbhead);                 break;
 94             case 6:pbhead=read_teacher();                break;
 95             case 7:pbhead=delete_teacher(pbhead);        break;
 96             case 8:modify_teacher_list(pbhead);          break;
 97             case 0:break;
 98             }
 99         }
100 
101         if(key==3)
102         {    
103             system("clear");
104             printf(GREEN "********************     1:创建班主任链表     *********************************
");
105             printf(BLUE  "********************     2:创建班主任信息     ********************************
");
106             printf(CYAN  "********************     3:打印班主任信息    *********************************
");
107             printf(PURPLE"********************     4:搜索班主任数据     ********************************
");
108             printf(GREEN "********************     5:保存班主任数据     *********************************
");
109             printf(YELLOW"********************     6:读取班主任数据    *********************************
");
110             printf(WHITE  "********************    7:删除班主任数据    ********************************
");
111             printf(BLUE "********************      8:修改班主任数据    **********************************
");
112             printf(BROWN"********************      0:退出        **********************************
");
113             int i;
114             printf(WHITE "



				请选择:");
115             scanf("%d",&i);
116             switch(i)
117             {
118              case 1:plhead=creat_Class_Tutor();              break;    
119              case 2:insert_Class_Tutor(plhead);              break;
120              case 3:prin_Class_Tutor(plhead);             break;
121              case 4:search_Class_Tutor(plhead);           break; 
122              case 5:save_Class_Tutor(plhead);             break;
123              case 6:plhead=read_Class_Tutor();            break;
124              case 7:plhead=delete_Class_Tutor(plhead);    break;
125              case 8:modify_Class_Tutor_list(plhead);      break;
126              case 0:break;
127             }
128         }
129         if(key==0)
130         {
131             break;
132         }    
133 }
134 }
View Code
原文地址:https://www.cnblogs.com/dog-and-cat/p/6672565.html