本文实例为大家分享了C语言班级档案管理系统的具体代码,供大家参考,具体内容如下
做的挺长时间的课程设计,当作参考吧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20
struct student
{
long num;
char name[20];
char sex[10];
int age;
char bz[40];
struct student *next;
};
int i,j,n,num2,num3,age3,k,m;
char name3[20],sex3[20],bz3[20],ch;
FILE *fp;
int login() //登陆函数
{
char key[20];
printf ( "\t ********************请输入系统密码********************\n" );
do
{
scanf ( "%s" ,key);
if (( strcmp ( "a" ,key))==0)
{
printf ( "\t password correct ,welcome !\n" );
return 1; //当密码正确时,返回1,进入系统
}
printf ( "\t password incorrect,please input again!\n" );
} while (key!=1); //当返回值不为1时,重新输入密码,直到输入真确为止
system ( "cls" );
}
int menu() //菜单
{
int c;
printf ( "\t\t**********欢迎进入通讯客户端!************\n\n" );
printf ( "\t\t|—————1.录入学生的基本信息—————|\n" );
printf ( "\t\t|----------2.显示学生的基本信息----------|\n" );
printf ( "\t\t|----------3.保存学生的基本信息----------|\n" );
printf ( "\t\t|----------4.删除学生的基本信息----------|\n" );
printf ( "\t\t|----------5.修改学生的基本信息----------|\n" );
printf ( "\t\t|----------6.查询学生的基本信息----------|\n" );
printf ( "\t\t|—————7.退出系统——————————|\n" );
printf ( "\t\t请选择您要进行的功能(0~7) " );
scanf ( "%d" ,&c);
return c;
}
struct student *creat() //录入信息函数
{
struct student *head,*p1,*p2;
n=0;
p1=p2=( struct student *) malloc ( sizeof ( struct student));
head=NULL;
printf ( "请输入学生信息学号,姓名,性别,年龄,备注(键入学生学号为0时结束)\n" );
while (1) //为1表真,p2->next不为0;
{
scanf ( "%d" ,&p1->num);
if (p1->num==0) //判断学生的学号是否为0,如果为0则停止输入数据;
{
break ;
}
scanf ( "%s%s%d%s" ,p1->name,p1->sex,&p1->age,p1->bz);
n=n+1;
if (n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=( struct student *) malloc ( sizeof ( struct student));
}
p2->next=NULL;
system ( "cls" );
return (head);
}
void print( struct student *head) //输出信息函数
{
struct student *p;
printf ( "\t\t这里有 %d 个学生的数据信息\n" ,n);
p=head;
if (head!=NULL)
{
do
{
printf ( "\t\t学号:%d\t姓名:%s\t性别:%s\t年龄:%d\t备注:%s\n" ,p->num,p->name,p->sex,p->age,p->bz);
p=p->next;
} while (p!=NULL);
}
else
{
return 0;
}
printf ( "\n" );
}
int save( struct student *p) //保存信息函数
{
FILE *fp;
if ((fp= fopen ( "keshe.txt" , "wb" ))==NULL)
{
printf ( "open file fail\n" );
}
fp= fopen ( "stud" , "wb" );
do
{
fwrite (p, sizeof ( struct student),1,fp);
p=p->next;
} while (p!=NULL);
printf ( "\t\t\t保存成功!\n" );
fclose (fp);
return 0;
}
struct student *del( struct student *head)
{
struct student *p1,*p2;
printf ( "\t\t请输入要删除学生的学号\n" );
scanf ( "%d" ,&num2);
p1=head;
if (head->num==num2)
{
head=head->next;
free (p1);
n--;
}
else
{
p2=head;
while (p2->num!=num2&&p2->next!=NULL)
{
p1=p2;
p2=p2->next;
}
if (p2->num==num2)
{
p1->next=p2->next;
n--;
}
printf ( "delete:%ld\n" ,num2);
}
return (head);
}
int mod( struct student *head); //修改信息函数
struct student *modify( struct student *head)
{
if (login()==0)
{
return 0;
}
else
{
struct student *p1;
j=0;
p1=( struct student *) malloc ( sizeof ( struct student));
printf ( "\t\t\t请输入你要更改的学号\n" );
scanf ( "%d" ,&num2);
printf ( "\t\t\t学号\n" );
scanf ( "%d" ,&num3);
printf ( "\t\t\t姓名\n" );
scanf ( "%s" ,name3);
printf ( "\t\t\t性别\n" );
scanf ( "%s" ,sex3);
printf ( "\t\t\t年龄\n" );
scanf ( "%d" ,&age3);
printf ( "\t\t\t备注\n" );
scanf ( "%s" ,bz3);
p1=head;
if (head->num==num2)
{
head->num=num3;
strcpy (head->name,name3);
strcpy (head->sex,sex3);
head->age=age3;
strcpy (head->bz,bz3);
j=1;
}
else
{
p1=head->next;
if (p1!=NULL)
{
while (p1->num!=num2)
{
p1=p1->next;
}
p1->num=num2;
strcpy (p1->name,name3);
strcpy (p1->sex,sex3);
p1->age=age3;
strcpy (p1->bz,bz3);
j=1;
}
}
if (j==0)
{
printf ( "\t\t\t更改失败\n" );
}
else
{
printf ( "\t\t\t更改成功\n" );
}
}
system ( "cls" );
mod(head);
}
int mod( struct student *head)
{
printf ( "\t\t\t请选择\n" );
printf ( "\t\t\t1:按学号修改学生信息\n" );
printf ( "\t\t\t2:输出修改后的学生信息\n" );
printf ( "\t\t\t3:返回主菜单\n" );
scanf ( "%d" ,&m);
switch (m)
{
case 1:head=modify(head); break ;
case 2:print(head); break ;
case 3:menu(); break ;
default : printf ( "\t\t\tinput error!\n" );
mod(head);
}
}
int find( struct student *head);
int find1( struct student *head) //以学号方式查找
{
struct student *p1;
p1=( struct student *) malloc ( sizeof ( struct student));
printf ( "\t\t\t请输入你要查询的学生学号\n" );
scanf ( "%d" ,&num2);
p1=head;
while (p1!=NULL)
{
if (p1->num==num2)
{
k=1;
printf ( "\t\t\t学号:%d\t姓名:%s\t性别:%s\t年龄:%d\t备注:%s\n\n" ,p1->num,p1->name,p1->sex,p1->age,p1->bz);
break ;
}
p1=p1->next;
}
if (k==0)
{
printf ( "\t\t\t没有查询到您要找的学生信息\n\n" );
}
else
{
printf ( "\t\t\t这就是您要找的学生信息\n\n" );
}
find(head);
}
int find2( struct student *head) //以姓名方式查找
{
struct student *p1;
p1=( struct student *) malloc ( sizeof ( struct student));
printf ( "\t\t\t请输入您要查询的学生姓名\n" );
scanf ( "%s" ,name3);
p1=head;
while (p1!=NULL)
{
if (( strcmp (p1->name,name3))==0)
{
k=1;
printf ( "\t\t\t学号:%d\t姓名:%s\t性别:%s\t年龄:%d\t备注:%s\n\n" ,p1->num,p1->name,p1->sex,p1->age,p1->bz);
break ;
}
p1=p1->next;
}
if (k==0)
{
printf ( "\t\t\t没有找到该学生信息\n\n" );
}
else
{
printf ( "\t\t\t这就是您要查询的学生信息\n\n" );
}
find(head);
}
int find3( struct student *head) //以性别方式查找
{
struct student *p1;
p1=( struct student *) malloc ( sizeof ( struct student));
printf ( "\t\t\t请输入你要查询的学生的性别\n" );
scanf ( "%s" ,sex3);
p1=head;
while (p1!=NULL)
{
if (( strcmp (p1->sex,sex3))==0)
{
k=1;
printf ( "\t\t\t学号:%d\t姓名:%s\t性别:%s\t年龄:%d\t备注:%s\n\n" ,p1->num,p1->name,p1->sex,p1->age,p1->bz);
break ;
}
p1=p1->next;
}
if (k==0)
{
printf ( "\t\t\t没有找到该学生信息\n\n" );
}
else
{
printf ( "\t\t\t这就是您要查询的学生的信息\n\n" );
}
find(head);
}
int find4( struct student *head) //以年龄方式查找
{
struct student *p1;
p1=( struct student *) malloc ( sizeof ( struct student));
printf ( "\t\t\t请输入您要查询的学生的年龄\n" );
scanf ( "%d" ,&age3);
p1=head;
while (p1!=NULL)
{
if (p1->age==age3)
{
k=1;
printf ( "\t\t\t学号:%d\t姓名:%s\t性别:%s\t年龄:%d\t备注:%s\n\n" ,p1->num,p1->name,p1->sex,p1->age,p1->bz);
break ;
}
p1=p1->next;
}
if (k==0)
{
printf ( "\t\t\t没有找到该学生的信息\n\n" );
}
else
{
printf ( "\t\t\t这就是您要找的学生的信息\n\n" );
}
find(head);
}
int find( struct student *head)
{
printf ( "\t\t\t请选择您要查询学生信息的方式\n" );
printf ( "\t\t\t1:按学生学号查询\n" );
printf ( "\t\t\t2:按学生姓名查询\n" );
printf ( "\t\t\t3:按学生性别查询\n" );
printf ( "\t\t\t4:按学生年龄查询\n" );
printf ( "\t\t\t5:返回主菜单\n" );
scanf ( "%d" ,&m);
switch (m)
{
case 1:find1(head); break ;
case 2:find2(head); break ;
case 3:find3(head); break ;
case 4:find4(head); break ;
case 5: system ( "cls" );menu(); break ;
default : printf ( "\t\t\tinput error,please input again\n" );
}
}
int main() //主函数
{
struct student *phead;
if (login()==0)
{
return 0;
}
printf ( "\n" );
while (1)
{
switch (menu())
{
case 1: system ( "cls" );phead=creat(); break ;
case 2: system ( "cls" );print(phead); break ;
case 3: system ( "cls" );save(phead); break ;
case 4: system ( "cls" );phead=del(phead); break ;
case 5: system ( "cls" );mod(phead); break ;
case 6: system ( "cls" );find(phead); break ;
case 7: system ( "cls" ); printf ( "\t\t\t欢迎使用,再见!\n" ); return 0;
default : printf ( "\t\t\t输入有错,请重新输入\n" );
}
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_41722554/article/details/81151667