├── StudentInfoSystem.pro
├── StudentInfoSystem.pro.user
├── cho.txt
├── choose.cpp
├── choose.h
├── code_convert.cpp
├── course.cpp
├── course.h
├── crs.txt
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── stu.txt
├── student.cpp
└── student.h
/StudentInfoSystem.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2017-08-16T16:09:20
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = StudentInfoSystem
12 | TEMPLATE = app
13 |
14 | # The following define makes your compiler emit warnings if you use
15 | # any feature of Qt which as been marked as deprecated (the exact warnings
16 | # depend on your compiler). Please consult the documentation of the
17 | # deprecated API in order to know how to port your code away from it.
18 | DEFINES += QT_DEPRECATED_WARNINGS
19 |
20 | # You can also make your code fail to compile if you use deprecated APIs.
21 | # In order to do so, uncomment the following line.
22 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24 |
25 |
26 | SOURCES += \
27 | main.cpp \
28 | mainwindow.cpp \
29 | student.cpp \
30 | course.cpp \
31 | choose.cpp \
32 | code_convert.cpp
33 |
34 | HEADERS += \
35 | mainwindow.h \
36 | student.h \
37 | course.h \
38 | choose.h
39 |
40 | FORMS += \
41 | mainwindow.ui
42 |
--------------------------------------------------------------------------------
/StudentInfoSystem.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {b1340b03-13ef-402c-9bc8-e19d6ae460e2}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 |
60 | ProjectExplorer.Project.Target.0
61 |
62 | Desktop Qt 5.9.1 MinGW 32bit
63 | Desktop Qt 5.9.1 MinGW 32bit
64 | qt.591.win32_mingw53_kit
65 | 0
66 | 0
67 | 0
68 |
69 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MinGW_32bit-Debug
70 |
71 |
72 | true
73 | qmake
74 |
75 | QtProjectManager.QMakeBuildStep
76 | true
77 |
78 | false
79 | false
80 | false
81 |
82 |
83 | true
84 | Make
85 |
86 | Qt4ProjectManager.MakeStep
87 |
88 | false
89 |
90 |
91 |
92 | 2
93 | 构建
94 |
95 | ProjectExplorer.BuildSteps.Build
96 |
97 |
98 |
99 | true
100 | Make
101 |
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 |
108 | 1
109 | 清理
110 |
111 | ProjectExplorer.BuildSteps.Clean
112 |
113 | 2
114 | false
115 |
116 | Debug
117 |
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 | true
121 |
122 |
123 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MinGW_32bit-Release
124 |
125 |
126 | true
127 | qmake
128 |
129 | QtProjectManager.QMakeBuildStep
130 | false
131 |
132 | false
133 | false
134 | false
135 |
136 |
137 | true
138 | Make
139 |
140 | Qt4ProjectManager.MakeStep
141 |
142 | false
143 |
144 |
145 |
146 | 2
147 | 构建
148 |
149 | ProjectExplorer.BuildSteps.Build
150 |
151 |
152 |
153 | true
154 | Make
155 |
156 | Qt4ProjectManager.MakeStep
157 |
158 | true
159 | clean
160 |
161 |
162 | 1
163 | 清理
164 |
165 | ProjectExplorer.BuildSteps.Clean
166 |
167 | 2
168 | false
169 |
170 | Release
171 |
172 | Qt4ProjectManager.Qt4BuildConfiguration
173 | 0
174 | true
175 |
176 |
177 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MinGW_32bit-Profile
178 |
179 |
180 | true
181 | qmake
182 |
183 | QtProjectManager.QMakeBuildStep
184 | true
185 |
186 | false
187 | true
188 | false
189 |
190 |
191 | true
192 | Make
193 |
194 | Qt4ProjectManager.MakeStep
195 |
196 | false
197 |
198 |
199 |
200 | 2
201 | 构建
202 |
203 | ProjectExplorer.BuildSteps.Build
204 |
205 |
206 |
207 | true
208 | Make
209 |
210 | Qt4ProjectManager.MakeStep
211 |
212 | true
213 | clean
214 |
215 |
216 | 1
217 | 清理
218 |
219 | ProjectExplorer.BuildSteps.Clean
220 |
221 | 2
222 | false
223 |
224 | Profile
225 |
226 | Qt4ProjectManager.Qt4BuildConfiguration
227 | 0
228 | true
229 |
230 | 3
231 |
232 |
233 | 0
234 | 部署
235 |
236 | ProjectExplorer.BuildSteps.Deploy
237 |
238 | 1
239 | 在本地部署
240 |
241 | ProjectExplorer.DefaultDeployConfiguration
242 |
243 | 1
244 |
245 |
246 | false
247 | false
248 | 1000
249 |
250 | true
251 |
252 | false
253 | false
254 | false
255 | false
256 | true
257 | 0.01
258 | 10
259 | true
260 | 1
261 | 25
262 |
263 | 1
264 | true
265 | false
266 | true
267 | valgrind
268 |
269 | 0
270 | 1
271 | 2
272 | 3
273 | 4
274 | 5
275 | 6
276 | 7
277 | 8
278 | 9
279 | 10
280 | 11
281 | 12
282 | 13
283 | 14
284 |
285 | 2
286 |
287 | StudentInfoSystem
288 |
289 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/LL/Documents/StudentInfoSystem/StudentInfoSystem.pro
290 | true
291 |
292 | StudentInfoSystem.pro
293 | false
294 |
295 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MinGW_32bit-Debug
296 | 3768
297 | false
298 | true
299 | false
300 | false
301 | true
302 |
303 | 1
304 |
305 |
306 |
307 | ProjectExplorer.Project.Target.1
308 |
309 | Desktop Qt 5.9.1 MSVC2017 64bit
310 | Desktop Qt 5.9.1 MSVC2017 64bit
311 | qt.591.win64_msvc2017_64_kit
312 | 0
313 | 0
314 | 0
315 |
316 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MSVC2017_64bit-Debug
317 |
318 |
319 | true
320 | qmake
321 |
322 | QtProjectManager.QMakeBuildStep
323 | true
324 |
325 | false
326 | false
327 | false
328 |
329 |
330 | true
331 | Make
332 |
333 | Qt4ProjectManager.MakeStep
334 |
335 | false
336 |
337 |
338 |
339 | 2
340 | 构建
341 |
342 | ProjectExplorer.BuildSteps.Build
343 |
344 |
345 |
346 | true
347 | Make
348 |
349 | Qt4ProjectManager.MakeStep
350 |
351 | true
352 | clean
353 |
354 |
355 | 1
356 | 清理
357 |
358 | ProjectExplorer.BuildSteps.Clean
359 |
360 | 2
361 | false
362 |
363 | Debug
364 |
365 | Qt4ProjectManager.Qt4BuildConfiguration
366 | 2
367 | true
368 |
369 |
370 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MSVC2017_64bit-Release
371 |
372 |
373 | true
374 | qmake
375 |
376 | QtProjectManager.QMakeBuildStep
377 | false
378 |
379 | false
380 | false
381 | false
382 |
383 |
384 | true
385 | Make
386 |
387 | Qt4ProjectManager.MakeStep
388 |
389 | false
390 |
391 |
392 |
393 | 2
394 | 构建
395 |
396 | ProjectExplorer.BuildSteps.Build
397 |
398 |
399 |
400 | true
401 | Make
402 |
403 | Qt4ProjectManager.MakeStep
404 |
405 | true
406 | clean
407 |
408 |
409 | 1
410 | 清理
411 |
412 | ProjectExplorer.BuildSteps.Clean
413 |
414 | 2
415 | false
416 |
417 | Release
418 |
419 | Qt4ProjectManager.Qt4BuildConfiguration
420 | 0
421 | true
422 |
423 |
424 | C:/Users/LL/Documents/build-StudentInfoSystem-Desktop_Qt_5_9_1_MSVC2017_64bit-Profile
425 |
426 |
427 | true
428 | qmake
429 |
430 | QtProjectManager.QMakeBuildStep
431 | true
432 |
433 | false
434 | true
435 | false
436 |
437 |
438 | true
439 | Make
440 |
441 | Qt4ProjectManager.MakeStep
442 |
443 | false
444 |
445 |
446 |
447 | 2
448 | 构建
449 |
450 | ProjectExplorer.BuildSteps.Build
451 |
452 |
453 |
454 | true
455 | Make
456 |
457 | Qt4ProjectManager.MakeStep
458 |
459 | true
460 | clean
461 |
462 |
463 | 1
464 | 清理
465 |
466 | ProjectExplorer.BuildSteps.Clean
467 |
468 | 2
469 | false
470 |
471 | Profile
472 |
473 | Qt4ProjectManager.Qt4BuildConfiguration
474 | 0
475 | true
476 |
477 | 3
478 |
479 |
480 | 0
481 | 部署
482 |
483 | ProjectExplorer.BuildSteps.Deploy
484 |
485 | 1
486 | 在本地部署
487 |
488 | ProjectExplorer.DefaultDeployConfiguration
489 |
490 | 1
491 |
492 |
493 | false
494 | false
495 | 1000
496 |
497 | true
498 |
499 | false
500 | false
501 | false
502 | false
503 | true
504 | 0.01
505 | 10
506 | true
507 | 1
508 | 25
509 |
510 | 1
511 | true
512 | false
513 | true
514 | valgrind
515 |
516 | 0
517 | 1
518 | 2
519 | 3
520 | 4
521 | 5
522 | 6
523 | 7
524 | 8
525 | 9
526 | 10
527 | 11
528 | 12
529 | 13
530 | 14
531 |
532 | -1
533 |
534 |
535 |
536 | %{buildDir}
537 | Custom Executable
538 |
539 | ProjectExplorer.CustomExecutableRunConfiguration
540 | 3768
541 | false
542 | true
543 | false
544 | false
545 | true
546 |
547 | 1
548 |
549 |
550 |
551 | ProjectExplorer.Project.TargetCount
552 | 2
553 |
554 |
555 | ProjectExplorer.Project.Updater.FileVersion
556 | 18
557 |
558 |
559 | Version
560 | 18
561 |
562 |
563 |
--------------------------------------------------------------------------------
/cho.txt:
--------------------------------------------------------------------------------
1 | 10000 英语 85
2 | 10001 英语 78
3 | 10002 英语 95
4 | 10001 语文 72
5 | 10002 语文 90
6 | 10003 语文 88
7 | 10002 历史 89
8 | 10003 历史 88
9 | 10004 历史 94
10 | 10005 历史 74
11 | 10001 地理 88
12 | 10002 地理 87
13 | 10003 地理 92
14 | 10004 地理 93
15 | 10005 地理 69
16 | 10003 数学 88
17 | 10002 数学 99
18 | 10005 计算机 82
19 | 10004 计算机 86
20 | 10003 计算机 88
21 | 10002 计算机 93
22 | 10001 计算机 87
23 |
--------------------------------------------------------------------------------
/choose.cpp:
--------------------------------------------------------------------------------
1 | #include "choose.h"
2 | #include
3 | #include
4 | #include
5 | choose::choose()
6 | {
7 | choose::count = 0;
8 | choose::head = NULL;
9 | }
10 |
11 | choose::~choose()
12 | {
13 |
14 | }
15 |
16 | bool choose::read(const char *filename)
17 | {
18 | FILE *fp = fopen(filename, "r");
19 | if(fp == NULL)
20 | return 0;
21 | char ch;
22 | int i = 0;
23 | int mode = 0;
24 | StuCrsInfo *p = new StuCrsInfo;
25 | p->next = NULL;
26 | char grade_temp[20];
27 | while((ch = fgetc(fp)) != EOF)
28 | {
29 | if(mode == 0 && ch != ' ' && ch != '\n')
30 | p->stu[i++]=ch;
31 | else if(mode == 1 && ch != ' ' && ch != '\n')
32 | p->crs[i++] = ch;
33 | else if(mode == 2 && ch != ' ' && ch != '\n')
34 | grade_temp[i++] = ch;
35 | else if(ch == '\n')
36 | {
37 | grade_temp[i] = '\0';
38 | i = 0;
39 | mode = 0;
40 | p->grade = atoi(grade_temp);
41 | if(choose::serh(p, 2) == NULL)
42 | {
43 | if(choose::head != NULL)
44 | p->next = choose::head;
45 | choose::head = p;
46 | ++choose::count;
47 | }
48 | p = new StuCrsInfo;
49 | p->next = NULL;
50 | }
51 | else if(ch == ' ')
52 | {
53 | if(mode == 0)
54 | {
55 | p->stu[i] = '\0';
56 | i = 0;
57 | }
58 | else if(mode == 1)
59 | {
60 | p->crs[i] = '\0';
61 | i = 0;
62 | }
63 | mode++;
64 | }
65 | }
66 | fclose(fp);
67 | return 1;
68 | }
69 |
70 | bool choose::save(const char *filename)
71 | {
72 | StuCrsInfo *p = choose::head;
73 | FILE *fp = fopen(filename, "w");
74 | while(p != NULL)
75 | {
76 | fprintf(fp, p->stu);
77 | fprintf(fp, " ");
78 | fprintf(fp, p->crs);
79 | fprintf(fp, " ");
80 | char buffer[20];
81 | itoa(p->grade, buffer, 10);
82 | fprintf(fp, buffer);
83 | fprintf(fp, "\n");
84 | p = p->next;
85 | }
86 | fclose(fp);
87 | return 1;
88 | }
89 |
90 | bool choose::add(StuCrsInfo *info)
91 | {
92 | if(choose::serh(info, 2) != NULL)
93 | return 0;
94 | choose::count += 1;
95 | info->next = choose::head;
96 | choose::head = info;
97 | return 1;
98 | }
99 |
100 | bool choose::del(StuCrsInfo *info, int type)
101 | {
102 | StuCrsInfo *point;
103 | StuCrsInfo *p = choose::head;
104 | if((point = choose::serh(info, type)) == NULL)
105 | return 0;
106 | choose::count -= 1;
107 | if(p == point)
108 | {
109 | choose::head = choose::head->next;
110 | return 1;
111 | }
112 | while(p->next != NULL)
113 | if(p->next == point)
114 | break;
115 | else
116 | p = p->next;
117 | p->next = p->next->next;
118 | return 1;
119 | }
120 |
121 | StuCrsInfo *choose::serh(StuCrsInfo *info, int type)
122 | {
123 | StuCrsInfo *p = choose::head;
124 | while(p != NULL)
125 | {
126 | if(type == 0 && strcmp(info->stu, p->stu) == 0)
127 | return p;
128 | else if(type == 1 && strcmp(info->crs, p->crs) == 0)
129 | return p;
130 | else if(type == 2 && strcmp(info->crs, p->crs) == 0 && strcmp(info->stu, p->stu) == 0)
131 | return p;
132 | else if(type == 3 && strcmp(info->stu, p->stu) == 0)
133 | {
134 | StuCrsInfo *temp = new StuCrsInfo;
135 | strcpy(temp->crs, p->crs);
136 | strcpy(temp->stu, p->stu);
137 | temp->grade = p->grade;
138 | temp->next = info;
139 | info = temp;
140 | }
141 | else if(type == 4 && strcmp(info->crs, p->crs) == 0)
142 | {
143 | StuCrsInfo *temp = new StuCrsInfo;
144 | strcpy(temp->crs, p->crs);
145 | strcpy(temp->stu, p->stu);
146 | temp->grade = p->grade;
147 | temp->next = info;
148 | info = temp;
149 | }
150 | p = p->next;
151 | }
152 | return (type < 3) ? NULL : info;
153 | }
154 |
155 | bool choose::addgrade(StuCrsInfo *p)
156 | {
157 | StuCrsInfo *node = choose::serh(p, 2);
158 | if(node == NULL)
159 | return 0;
160 | node->grade = p->grade;
161 | return 1;
162 | }
163 |
164 | bool choose::delgrade(StuCrsInfo *p)
165 | {
166 | StuCrsInfo *node = choose::serh(p, 2);
167 | if(node == NULL)
168 | return 0;
169 | node->grade = -1;
170 | return 1;
171 | }
172 |
--------------------------------------------------------------------------------
/choose.h:
--------------------------------------------------------------------------------
1 | #ifndef CHOOSE_H
2 | #define CHOOSE_H
3 |
4 | struct StuCrsInfo{
5 | char stu[20];
6 | char crs[20];
7 | int grade;
8 | StuCrsInfo *next;
9 | };
10 |
11 | class choose{
12 | public:
13 | choose();
14 | ~choose();
15 | int count;
16 | StuCrsInfo *head;
17 | bool read(const char *);
18 | bool save(const char *);
19 | StuCrsInfo *serh(StuCrsInfo *, int);
20 | bool add(StuCrsInfo *);
21 | bool del(StuCrsInfo *, int);
22 | bool addgrade(StuCrsInfo *);
23 | bool delgrade(StuCrsInfo *);
24 | };
25 | #endif // CHOOSE_H
26 |
--------------------------------------------------------------------------------
/code_convert.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Refer to : http://blog.csdn.net/denny97104/article/details/45443055
3 | */
4 | #include
5 | #include
6 | #include
7 |
8 | QByteArray AnsiToUtf8(QByteArray &ansi)
9 | {
10 | int len;
11 | QByteArray result;
12 | //ANSI转UNICODE
13 | len = MultiByteToWideChar(CP_ACP, NULL, ansi.data(), -1, NULL, 0);
14 | WCHAR * unicode = new WCHAR[len+1];
15 | memset(unicode, 0, len * 2 + 2);
16 | MultiByteToWideChar(CP_ACP, NULL, ansi.data(), -1, unicode, len);
17 | //UNICODE转utf8
18 | len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
19 | char *utf8=new char[len + 1];
20 | memset(utf8, 0, len + 1);
21 | WideCharToMultiByte (CP_UTF8, 0, unicode, -1, utf8, len, NULL,NULL);
22 | result = utf8;
23 | delete[] unicode;
24 | delete[] utf8;
25 | return result;
26 | }
27 |
--------------------------------------------------------------------------------
/course.cpp:
--------------------------------------------------------------------------------
1 | #include "course.h"
2 | #include
3 | #include
4 | #include
5 | course::course()
6 | {
7 | course::count = 0;
8 | course::head = NULL;
9 | }
10 |
11 | course::~course()
12 | {
13 |
14 | }
15 |
16 | bool course::read(const char *filename)
17 | {
18 | FILE *fp = fopen(filename, "r");
19 | if(fp == NULL)
20 | return 0;
21 | char ch;
22 | int i = 0;
23 | int mode = 0;
24 | char score_temp[20] = {'\0'};
25 | char type_temp;
26 | CourseInfo *p = new CourseInfo;
27 | p->next = NULL;
28 | while((ch = fgetc(fp)) != EOF)
29 | {
30 | if(mode == 0 && ch != ' ' && ch != '\n')
31 | p->name[i++]=ch;
32 | else if(mode == 1 && ch != ' ' && ch != '\n')
33 | score_temp[i++] = ch;
34 | else if(mode == 2 && ch != ' ' && ch != '\n')
35 | type_temp = ch;
36 | else if(ch == '\n')
37 | {
38 | score_temp[i] = '\0';
39 | p->score = atoi(score_temp);
40 | p->type = type_temp - '0';
41 | i = 0;
42 | mode = 0;
43 | CourseInfo *point;
44 | if((point = course::serh(p, 0, course::head)) != NULL)
45 | {
46 | strcpy(point->name, p->name);
47 | }
48 | else
49 | {
50 | if(course::head != NULL)
51 | p->next = course::head;
52 | course::head = p;
53 | ++course::count;
54 | }
55 | p = new CourseInfo;
56 | p->next = NULL;
57 | }
58 | else if(ch == ' ')
59 | {
60 | if(mode == 0)
61 | {
62 | p->name[i] = '\0';
63 | i = 0;
64 | }
65 | mode++;
66 | }
67 | }
68 | fclose(fp);
69 | return 1;
70 | }
71 |
72 | bool course::save(const char *filename, CourseInfo *head)
73 | {
74 | CourseInfo *p = head;
75 | FILE *fp = fopen(filename, "w");
76 | while(p != NULL)
77 | {
78 | fprintf(fp, p->name);
79 | fprintf(fp, " ");
80 | char buffer[20];
81 | itoa(p->score, buffer, 10);
82 | fprintf(fp, buffer);
83 | fprintf(fp, " ");
84 | itoa(p->type, buffer, 10);
85 | fprintf(fp, buffer);
86 | fprintf(fp, "\n");
87 | p = p->next;
88 | }
89 | fclose(fp);
90 | return 1;
91 | }
92 |
93 | bool course::add(CourseInfo *info)
94 | {
95 | if(!(course::serh(info, 0, head) == NULL))
96 | return 0;
97 | course::count += 1;
98 | info->next = course::head;
99 | course::head = info;
100 | return 1;
101 | }
102 |
103 | bool course::del(CourseInfo *info, bool type)
104 | {
105 | CourseInfo *point;
106 | CourseInfo *p = course::head;
107 | if((point = course::serh(info, type, course::head)) == NULL)
108 | return 0;
109 | course::count -= 1;
110 | if(p == point)
111 | {
112 | course::head = course::head->next;
113 | return 1;
114 | }
115 | while(p->next != NULL)
116 | if(p->next == point)
117 | break;
118 | else
119 | p = p->next;
120 | p->next = p->next->next;
121 | return 1;
122 | }
123 |
124 | CourseInfo *course::serh(CourseInfo *info, int type, CourseInfo *head)
125 | {
126 | CourseInfo *p = head;
127 | while(p != NULL)
128 | {
129 | if(type == 0 && strcmp(info->name, p->name) == 0)
130 | return p;
131 | else if(type == 1 && info->score == p->score)
132 | return p;
133 | p = p->next;
134 | }
135 | return NULL;
136 | }
137 |
--------------------------------------------------------------------------------
/course.h:
--------------------------------------------------------------------------------
1 | #ifndef COURSE_H
2 | #define COURSE_H
3 | #define COURSE_NAME_SIZE 20
4 |
5 | struct CourseInfo{
6 | char name[COURSE_NAME_SIZE];
7 | int score;
8 | int type;
9 | CourseInfo *next;
10 | };
11 |
12 | class course{
13 | public:
14 | course();
15 | ~course();
16 | int count;
17 | CourseInfo *head;
18 | bool read(const char *);
19 | bool save(const char *, CourseInfo *head);
20 | CourseInfo *serh(CourseInfo *, int, CourseInfo *head);
21 | bool add(CourseInfo *);
22 | bool del(CourseInfo *, bool);
23 | };
24 | #endif // COURSE_H
25 |
--------------------------------------------------------------------------------
/crs.txt:
--------------------------------------------------------------------------------
1 | 地理 2 0
2 | 语文 3 0
3 | 计算机 2 1
4 | 英语 3 1
5 | 数学 3 2
6 | 历史 2 2
7 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * 本程序中读取文件编码请使用ansi!
3 | */
4 |
5 | #include "mainwindow.h"
6 | #include
7 | int main(int argc, char *argv[])
8 | {
9 | QApplication a(argc, argv);
10 | MainWindow w;
11 | w.show();
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include "student.h"
20 | #include "course.h"
21 | #include "choose.h"
22 |
23 | student Student;
24 | course Course;
25 | choose Choose;
26 |
27 | extern QByteArray AnsiToUtf8(QByteArray &ansi);
28 |
29 | MainWindow::MainWindow(QWidget *parent) :
30 | QMainWindow(parent),
31 | ui(new Ui::MainWindow)
32 | {
33 | ui->setupUi(this);
34 | //预先读取文件
35 | Student.read("stu.txt");
36 | Course.read("crs.txt");
37 | Choose.read("cho.txt");
38 | MainWindow::display_course_info();
39 | MainWindow::display_choose_info();
40 | MainWindow::display_student_info();
41 | //窗口大小设置
42 | setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
43 | setFixedSize(this->width(), this->height());
44 | //右键菜单设置
45 | Act_Stu_Del = new QAction(tr("删除学生信息"), this);
46 | Act_Stu_Chg = new QAction(tr("修改学生信息"), this);
47 | Act_Stu_Add = new QAction(tr("添加学生信息"), this);
48 | Act_Crs_Del = new QAction(tr("删除课程"), this);
49 | Act_Crs_Add = new QAction(tr("添加课程"), this);
50 | Act_Cho_Del = new QAction(tr("退课"), this);
51 | Act_Cho_Add = new QAction(tr("选课"), this);
52 | Act_Srh_Stu = new QAction(tr("搜索当前学生所选的课程"), this);
53 | Act_Srh_Crs = new QAction(tr("搜索选择当前课程的学生"), this);
54 | Act_ADDGRADE = new QAction(tr("添加成绩"), this);
55 | Act_DELGRADE = new QAction(tr("删除成绩"), this);
56 | Act_Calc = new QAction(tr("计算学分绩"), this);
57 | connect(Act_Stu_Del, SIGNAL(triggered()), this, SLOT(on_stu_del_triggered()));
58 | connect(Act_Stu_Chg, SIGNAL(triggered()), this, SLOT(on_stu_chg_triggered()));
59 | connect(Act_Stu_Add, SIGNAL(triggered()), this, SLOT(on_stu_add_triggered()));
60 | connect(Act_Crs_Del, SIGNAL(triggered()), this, SLOT(on_class_del_triggered()));
61 | connect(Act_Crs_Add, SIGNAL(triggered()), this, SLOT(on_class_add_triggered()));
62 | connect(Act_Cho_Del, SIGNAL(triggered()), this, SLOT(on_delete_class_triggered()));
63 | connect(Act_Cho_Add, SIGNAL(triggered()), this, SLOT(on_choose_class_triggered()));
64 | connect(Act_Srh_Stu, SIGNAL(triggered()), this, SLOT(on_search_stu_triggered()));
65 | connect(Act_Srh_Crs, SIGNAL(triggered()), this, SLOT(on_search_class_triggered()));
66 | connect(Act_ADDGRADE, SIGNAL(triggered()), this, SLOT(on_add_grade_triggered()));
67 | connect(Act_DELGRADE, SIGNAL(triggered()), this, SLOT(on_del_grade_triggered()));
68 | connect(Act_Calc, SIGNAL(triggered()), this, SLOT(on_caculate_triggered()));
69 | }
70 |
71 | void MainWindow::contextMenuEvent(QContextMenuEvent *)
72 | {
73 | //qDebug()<tabWidget->currentIndex();
74 | QCursor cur=this->cursor();
75 | QMenu *menu = new QMenu;
76 | if(ui->tabWidget->currentIndex() == 0)
77 | {
78 | menu->addAction(Act_Stu_Del);
79 | menu->addAction(Act_Stu_Chg);
80 | menu->addAction(Act_Stu_Add);
81 | menu->addAction(Act_Srh_Stu);
82 | menu->addAction(Act_Calc);
83 | }
84 | else if(ui->tabWidget->currentIndex() == 1)
85 | {
86 | menu->addAction(Act_Crs_Del);
87 | menu->addAction(Act_Crs_Add);
88 | menu->addAction(Act_Srh_Crs);
89 | }
90 | else if(ui->tabWidget->currentIndex() == 2)
91 | {
92 | menu->addAction(Act_Cho_Del);
93 | menu->addAction(Act_Cho_Add);
94 | menu->addAction(Act_Srh_Stu);
95 | menu->addAction(Act_Srh_Crs);
96 | menu->addAction(Act_ADDGRADE);
97 | menu->addAction(Act_DELGRADE);
98 | menu->addAction(Act_Calc);
99 | }
100 | menu->exec(cur.pos());
101 | delete menu;
102 | }
103 |
104 | MainWindow::~MainWindow()
105 | {
106 | delete ui;
107 | }
108 |
109 | //============DisplayToTableWeight
110 | void MainWindow::display_student_info()
111 | {
112 | ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
113 | ui->tableWidget->clearContents();
114 | for(int loop = 0; loop < ui->tableWidget->rowCount();)
115 | ui->tableWidget->removeRow(loop);
116 | StuInfo *p = Student.head;
117 | while(p != NULL)
118 | {
119 | int rows = ui->tableWidget->rowCount();
120 | ui->tableWidget->insertRow(rows);
121 | ui->tableWidget->setItem(rows, 0, new QTableWidgetItem(p->name));
122 | ui->tableWidget->setItem(rows, 1, new QTableWidgetItem(p->id));
123 | p = p->next;
124 | }
125 | }
126 |
127 | void MainWindow::display_course_info()
128 | {
129 | ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
130 | ui->tableWidget_2->clearContents();
131 | for(int loop = 0; loop < ui->tableWidget_2->rowCount();)
132 | ui->tableWidget_2->removeRow(loop);
133 | CourseInfo *p = Course.head;
134 | while(p != NULL)
135 | {
136 | int rows = ui->tableWidget_2->rowCount();
137 | ui->tableWidget_2->insertRow(rows);
138 | ui->tableWidget_2->setItem(rows, 0, new QTableWidgetItem(p->name));
139 | ui->tableWidget_2->setItem(rows, 1, new QTableWidgetItem(QString::number(p->score)));
140 | ui->tableWidget_2->setItem(rows, 2, new QTableWidgetItem((p->type == 0)?"通过型":((p->type == 1)?"等级型":"分数型")));
141 | p = p->next;
142 | }
143 | }
144 |
145 | void MainWindow::display_choose_info()
146 | {
147 | ui->tableWidget_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
148 | ui->tableWidget_3->clearContents();
149 | for(int loop = 0; loop < ui->tableWidget_3->rowCount();)
150 | ui->tableWidget_3->removeRow(loop);
151 | StuCrsInfo *p = Choose.head;
152 | while(p != NULL)
153 | {
154 | StuInfo *ps = new StuInfo;
155 | ps->next = NULL;
156 | strcpy(ps->id, p->stu);
157 | char name_tmp[20] = {'\0'};
158 | StuInfo *pss = Student.serh(ps, 1);
159 | strcpy(name_tmp, (pss == NULL)?"":pss->name);
160 | delete ps;
161 |
162 | CourseInfo *pc = new CourseInfo;
163 | pc->next = NULL;
164 | strcpy(pc->name, p->crs);
165 | int score_tmp;
166 | CourseInfo *pcs = Course.serh(pc, 0, Course.head);
167 | score_tmp = (pcs == NULL)?-1:pcs->score;
168 | delete pc;
169 |
170 | int rows = ui->tableWidget_3->rowCount();
171 | ui->tableWidget_3->insertRow(rows);
172 | ui->tableWidget_3->setItem(rows, 0, new QTableWidgetItem(p->stu));
173 | ui->tableWidget_3->setItem(rows, 1, new QTableWidgetItem(name_tmp));
174 | ui->tableWidget_3->setItem(rows, 2, new QTableWidgetItem(p->crs));
175 | ui->tableWidget_3->setItem(rows, 3, new QTableWidgetItem(QString::number(score_tmp)));
176 | ui->tableWidget_3->setItem(rows, 4, new QTableWidgetItem(((p->grade)==-1)?"":QString::number(p->grade)));
177 | p = p->next;
178 | }
179 | }
180 |
181 | //============StudentInfos
182 | void MainWindow::on_stu_read_triggered()
183 | {
184 | QStringList fileNames = QFileDialog::getOpenFileNames(this, "打开文件", ".", ("文本文件(*.txt)"));
185 | if(fileNames.size() == 0) return;
186 | for(int i = 0; i < fileNames.size(); ++i)
187 | {
188 | QByteArray bytearray = fileNames[i].toLocal8Bit();
189 | char *temp = bytearray.data();
190 | if(temp == NULL) continue;
191 | Student.read(temp);
192 | }
193 | char buffer[20];
194 | itoa(Student.count, buffer,10);
195 | char output[100];
196 | strcat(output, "导入完成,当前一共有");
197 | strcat(output, buffer);
198 | strcat(output, "个数据");
199 | QMessageBox::information(NULL, "导入完成", output, QMessageBox::Ok, QMessageBox::Ok);
200 | MainWindow::display_student_info();
201 | MainWindow::display_choose_info();
202 | }
203 |
204 | void MainWindow::on_stu_save_triggered()
205 | {
206 | QString fileName = QFileDialog::getOpenFileName(this, "另存为...", ".", ("文本文件(*.txt)"));
207 | if(fileName.length() == 0) return;
208 | QByteArray bytearray = fileName.toLocal8Bit();
209 | char *temp = bytearray.data();
210 | Student.save(temp);
211 | QMessageBox::information(NULL, "保存完成", "保存完成", QMessageBox::Ok, QMessageBox::Ok);
212 | MainWindow::display_student_info();
213 | }
214 |
215 | void MainWindow::on_stu_del_triggered()
216 | {
217 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
218 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
219 | ui->tableWidget_3->selectedItems());
220 | char temp[20] = {'\0'};
221 | QString text;
222 | if(!items.count() || ui->tabWidget->currentIndex() == 1)
223 | {
224 | text = QInputDialog::getText(NULL, tr("删除学生数据"), tr("请输入学号信息"));
225 | }
226 | else
227 | {
228 | QTableWidgetItem *item=(ui->tabWidget->currentIndex() == 0)?items.at(1):items.at(0);
229 | text = item->text();
230 | }
231 | if(text == NULL)
232 | return;
233 | QByteArray bytearray = text.toLocal8Bit();
234 | bytearray = AnsiToUtf8(bytearray);
235 | strcpy(temp, bytearray.data());
236 | StuInfo *p = new StuInfo;
237 | p->next = NULL;
238 | strcpy(p->id, temp);
239 | if(Student.del(p, 1))
240 | {
241 | StuCrsInfo *ps = new StuCrsInfo;
242 | ps->next = NULL;
243 | strcpy(ps->stu, p->id);
244 | while(Choose.del(ps, 0));
245 | delete ps;
246 | QMessageBox::information(NULL, "删除结果", "删除成功", QMessageBox::Ok, QMessageBox::Ok);
247 | }
248 | else
249 | QMessageBox::information(NULL, "删除结果", "删除失败-不存在此学号", QMessageBox::Ok, QMessageBox::Ok);
250 | delete p;
251 | MainWindow::display_student_info();
252 | MainWindow::display_choose_info();
253 | }
254 |
255 | void MainWindow::on_stu_add_triggered()
256 | {
257 | QString text = QInputDialog::getText(NULL, tr("添加学生数据"), tr("请输入学号信息"));
258 | if(text == NULL)
259 | return;
260 | QByteArray bytearray = text.toLocal8Bit();
261 | bytearray = AnsiToUtf8(bytearray);
262 | char *stuid = bytearray.data();
263 |
264 | QString text2 = QInputDialog::getText(NULL, tr("添加学生数据"), tr("请输入姓名信息"));
265 | if(text2 == NULL)
266 | return;
267 | QByteArray bytearray2 = text2.toLocal8Bit();
268 | bytearray2 = AnsiToUtf8(bytearray2);
269 | char *stuname = bytearray2.data();
270 |
271 | StuInfo *p = new StuInfo;
272 | p->next = NULL;
273 | strcpy(p->id, stuid);
274 | strcpy(p->name, stuname);
275 |
276 | if(Student.add(p))
277 | QMessageBox::information(NULL, "添加结果", "添加成功", QMessageBox::Ok, QMessageBox::Ok);
278 | else
279 | QMessageBox::information(NULL, "添加结果", "添加失败-学号重复", QMessageBox::Ok, QMessageBox::Ok);
280 | MainWindow::display_student_info();
281 | MainWindow::display_choose_info();
282 | }
283 |
284 | void MainWindow::on_stu_chg_triggered()
285 | {
286 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
287 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
288 | ui->tableWidget_3->selectedItems());
289 | char stuid[20] = {'\0'};
290 | QString text;
291 | if(!items.count() || ui->tabWidget->currentIndex() == 1)
292 | {
293 | text = QInputDialog::getText(NULL, tr("修改学生数据"), tr("请输入学号信息"));
294 | }
295 | else
296 | {
297 | QTableWidgetItem *item=(ui->tabWidget->currentIndex() == 0)?items.at(1):items.at(0);
298 | text = item->text();
299 | }
300 | if(text == NULL)
301 | return;
302 | QByteArray bytearray = text.toLocal8Bit();
303 | bytearray = AnsiToUtf8(bytearray);
304 | strcpy(stuid, bytearray.data());
305 |
306 | QString text2 = QInputDialog::getText(NULL, tr("修改学生数据"), tr("请输入新姓名信息"));
307 | if(text2 == NULL)
308 | return;
309 | QByteArray bytearray2 = text2.toLocal8Bit();
310 | bytearray2 = AnsiToUtf8(bytearray2);
311 | char *stunewname = bytearray2.data();
312 | StuInfo *p = new StuInfo;
313 | p->next = NULL;
314 | strcpy(p->id, stuid);
315 | strcpy(p->name, stunewname);
316 | if(Student.chg(p, 0))
317 | QMessageBox::information(NULL, "修改结果", "修改成功", QMessageBox::Ok, QMessageBox::Ok);
318 | else
319 | QMessageBox::information(NULL, "修改结果", "修改失败-学号不存在", QMessageBox::Ok, QMessageBox::Ok);
320 | delete p;
321 | MainWindow::display_student_info();
322 | MainWindow::display_choose_info();
323 | }
324 |
325 | //============CourseInfos
326 | void MainWindow::on_class_read_triggered()
327 | {
328 | QStringList fileNames = QFileDialog::getOpenFileNames(this, "打开文件", ".", ("文本文件(*.txt)"));
329 | if(fileNames.size() == 0) return;
330 | for(int i = 0; i < fileNames.size(); ++i)
331 | {
332 | QByteArray bytearray = fileNames[i].toLocal8Bit();
333 | char *temp = bytearray.data();
334 | if(temp == NULL) continue;
335 | Course.read(temp);
336 | }
337 | char buffer[20];
338 | itoa(Course.count, buffer,10);
339 | char output[100];
340 | strcat(output, "导入完成,当前一共有");
341 | strcat(output, buffer);
342 | strcat(output, "个课程信息");
343 | QMessageBox::information(NULL, "导入完成", output, QMessageBox::Ok, QMessageBox::Ok);
344 | MainWindow::display_course_info();
345 | MainWindow::display_choose_info();
346 | }
347 |
348 | void MainWindow::on_class_save_triggered()
349 | {
350 | QString fileName = QFileDialog::getOpenFileName(this, "另存为...", ".", ("文本文件(*.txt)"));
351 | if(fileName.length() == 0) return;
352 | QByteArray bytearray = fileName.toLocal8Bit();
353 | char *temp = bytearray.data();
354 | Course.save(temp, Course.head);
355 | QMessageBox::information(NULL, "保存完成", "保存完成", QMessageBox::Ok, QMessageBox::Ok);
356 | MainWindow::display_course_info();
357 | }
358 |
359 | void MainWindow::on_class_del_triggered()
360 | {
361 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
362 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
363 | ui->tableWidget_3->selectedItems());
364 | char temp[20] = {'\0'};
365 | QString text;
366 | if(!items.count() || ui->tabWidget->currentIndex() == 0)
367 | {
368 | text = QInputDialog::getText(NULL, tr("删除课程数据"), tr("请输入课程名"));
369 | }
370 | else
371 | {
372 | QTableWidgetItem *item=(ui->tabWidget->currentIndex() == 1)?items.at(0):items.at(2);
373 | text = item->text();
374 | }
375 | if(text == NULL)
376 | return;
377 | QByteArray bytearray = text.toLocal8Bit();
378 | bytearray = AnsiToUtf8(bytearray);
379 | strcpy(temp, bytearray.data());
380 | CourseInfo *p = new CourseInfo;
381 | p->next = NULL;
382 | strcpy(p->name, temp);
383 | if(Course.del(p, 0))
384 | {
385 | StuCrsInfo *ps = new StuCrsInfo;
386 | ps->next = NULL;
387 | strcpy(ps->crs, p->name);
388 | while(Choose.del(ps, 1));
389 | delete ps;
390 | QMessageBox::information(NULL, "删除结果", "删除成功", QMessageBox::Ok, QMessageBox::Ok);
391 | }
392 | else
393 | QMessageBox::information(NULL, "删除结果", "删除失败-不存在此课程", QMessageBox::Ok, QMessageBox::Ok);
394 | delete p;
395 | MainWindow::display_course_info();
396 | MainWindow::display_choose_info();
397 | }
398 |
399 | void MainWindow::on_class_add_triggered()
400 | {
401 | QString text = QInputDialog::getText(NULL, tr("添加课程数据"), tr("请输入课程名"));
402 | if(text == NULL)
403 | return;
404 | QByteArray bytearray = text.toLocal8Bit();
405 | bytearray = AnsiToUtf8(bytearray);
406 | char *coursename = bytearray.data();
407 |
408 | QString text2 = QInputDialog::getText(NULL, tr("添加课程数据"), tr("请输入该课程的学分"));
409 | if(text2 == NULL)
410 | return;
411 | QByteArray bytearray2 = text2.toLocal8Bit();
412 | char *coursescore = bytearray2.data();
413 |
414 | CourseInfo *p = new CourseInfo;
415 | p->next = NULL;
416 | p->score = atoi(coursescore);
417 | strcpy(p->name, coursename);
418 | if(Course.add(p))
419 | QMessageBox::information(NULL, "添加结果", "添加成功", QMessageBox::Ok, QMessageBox::Ok);
420 | else
421 | QMessageBox::information(NULL, "添加结果", "添加失败-课程重复", QMessageBox::Ok, QMessageBox::Ok);
422 | MainWindow::display_course_info();
423 | MainWindow::display_choose_info();
424 | }
425 |
426 | //============ChooseInfos
427 | void MainWindow::on_choose_class_triggered()
428 | {
429 | QString text = QInputDialog::getText(NULL, tr("添加选课数据"), tr("请输入学号"));
430 | if(text == NULL)
431 | return;
432 | QByteArray bytearray = text.toLocal8Bit();
433 | bytearray = AnsiToUtf8(bytearray);
434 | char *stuid = bytearray.data();
435 |
436 | QString text2 = QInputDialog::getText(NULL, tr("添加选课数据"), tr("请输入课程名"));
437 | if(text2 == NULL)
438 | return;
439 | QByteArray bytearray2 = text2.toLocal8Bit();
440 | bytearray2 = AnsiToUtf8(bytearray2);
441 | char *coursename = bytearray2.data();
442 |
443 | StuCrsInfo *p = new StuCrsInfo;
444 | p->next = NULL;
445 | strcpy(p->stu, stuid);
446 | strcpy(p->crs, coursename);
447 | CourseInfo *pc = new CourseInfo;
448 | strcpy(pc->name, coursename);
449 | StuInfo *ps = new StuInfo;
450 | strcpy(ps->id, stuid);
451 | if(Student.serh(ps, 1) == NULL)
452 | QMessageBox::information(NULL, "选课结果", "选课失败-学生不存在", QMessageBox::Ok, QMessageBox::Ok);
453 | else if(Course.serh(pc, 0, Course.head) == NULL)
454 | QMessageBox::information(NULL, "选课结果", "选课失败-课程不存在", QMessageBox::Ok, QMessageBox::Ok);
455 | else if(Choose.add(p))
456 | QMessageBox::information(NULL, "选课结果", "选课成功", QMessageBox::Ok, QMessageBox::Ok);
457 | else
458 | QMessageBox::information(NULL, "选课结果", "选课失败-已选过", QMessageBox::Ok, QMessageBox::Ok);
459 | delete ps;
460 | delete pc;
461 | MainWindow::display_choose_info();
462 | }
463 |
464 | void MainWindow::on_delete_class_triggered()
465 | {
466 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
467 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
468 | ui->tableWidget_3->selectedItems());
469 | char stuid[20] = {'\0'};
470 | char coursename[20] = {'\0'};
471 | QString text, text2;
472 | if(!items.count() || ui->tabWidget->currentIndex() != 2)
473 | {
474 | text = QInputDialog::getText(NULL, tr("输入退课数据"), tr("请输入学号"));
475 | if(text == NULL)
476 | return;
477 |
478 | text2 = QInputDialog::getText(NULL, tr("输入退课数据"), tr("请输入课程名"));
479 | if(text2 == NULL)
480 | return;
481 | }
482 | else
483 | {
484 | QTableWidgetItem *item=items.at(0);
485 | text = item->text();
486 | item = items.at(2);
487 | text2 = item->text();
488 | }
489 | QByteArray bytearray = text.toLocal8Bit();
490 | bytearray = AnsiToUtf8(bytearray);
491 | strcpy(stuid, bytearray.data());
492 | QByteArray bytearray2 = text2.toLocal8Bit();
493 | bytearray2 = AnsiToUtf8(bytearray2);
494 | strcpy(coursename, bytearray2.data());
495 |
496 | StuCrsInfo *p = new StuCrsInfo;
497 | p->next = NULL;
498 | strcpy(p->stu, stuid);
499 | strcpy(p->crs, coursename);
500 | CourseInfo *pc = new CourseInfo;
501 | strcpy(pc->name, coursename);
502 | StuInfo *ps = new StuInfo;
503 | strcpy(ps->id, stuid);
504 | if(Student.serh(ps, 1) == NULL)
505 | QMessageBox::information(NULL, "退课结果", "退课失败-学生不存在", QMessageBox::Ok, QMessageBox::Ok);
506 | else if(Course.serh(pc, 0, Course.head) == NULL)
507 | QMessageBox::information(NULL, "退课结果", "退课失败-课程不存在", QMessageBox::Ok, QMessageBox::Ok);
508 | else if(Choose.del(p, 2))
509 | QMessageBox::information(NULL, "退课结果", "退课成功", QMessageBox::Ok, QMessageBox::Ok);
510 | else
511 | QMessageBox::information(NULL, "退课结果", "退课失败-未选课", QMessageBox::Ok, QMessageBox::Ok);
512 | delete p;
513 | delete ps;
514 | delete pc;
515 | MainWindow::display_choose_info();
516 | }
517 |
518 | void MainWindow::on_choose_read_triggered()
519 | {
520 | QStringList fileNames = QFileDialog::getOpenFileNames(this, "打开文件", ".", ("文本文件(*.txt)"));
521 | if(fileNames.size() == 0) return;
522 | for(int i = 0; i < fileNames.size(); ++i)
523 | {
524 | QByteArray bytearray = fileNames[i].toLocal8Bit();
525 | char *temp = bytearray.data();
526 | if(temp == NULL) continue;
527 | Choose.read(temp);
528 | }
529 | char buffer[20];
530 | itoa(Choose.count, buffer,10);
531 | char output[100];
532 | strcat(output, "导入完成,当前一共有");
533 | strcat(output, buffer);
534 | strcat(output, "个数据");
535 | QMessageBox::information(NULL, "导入完成", output, QMessageBox::Ok, QMessageBox::Ok);
536 | MainWindow::display_choose_info();
537 | }
538 |
539 | void MainWindow::on_choose_save_triggered()
540 | {
541 | QString fileName = QFileDialog::getOpenFileName(this, "另存为...", ".", ("文本文件(*.txt)"));
542 | if(fileName.length() == 0) return;
543 | QByteArray bytearray = fileName.toLocal8Bit();
544 | char *temp = bytearray.data();
545 | Choose.save(temp);
546 | QMessageBox::information(NULL, "保存完成", "保存完成", QMessageBox::Ok, QMessageBox::Ok);
547 | MainWindow::display_choose_info();
548 | }
549 |
550 | void MainWindow::on_search_stu_triggered()
551 | {
552 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
553 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
554 | ui->tableWidget_3->selectedItems());
555 | char stuid[20] = {'\0'};
556 | QString text;
557 | if(!items.count() || ui->tabWidget->currentIndex() == 1)
558 | {
559 | text = QInputDialog::getText(NULL, tr("搜索"), tr("请输入学号"));
560 | }
561 | else
562 | {
563 | QTableWidgetItem *item = (ui->tabWidget->currentIndex() == 0)?items.at(1):items.at(0);
564 | text = item->text();
565 | }
566 | if(text == NULL)
567 | return;
568 | QByteArray bytearray = text.toLocal8Bit();
569 | bytearray = AnsiToUtf8(bytearray);
570 | strcpy(stuid, bytearray.data());
571 |
572 | StuCrsInfo *p = new StuCrsInfo;
573 | strcpy(p->stu, stuid);
574 | p->next = NULL;
575 |
576 | StuInfo *ps = new StuInfo;
577 | strcpy(ps->id, stuid);
578 | ps->next = NULL;
579 | if(Student.serh(ps,1) == NULL)
580 | {
581 | QMessageBox::information(NULL, "搜索完成", "不存在该学生", QMessageBox::Ok, QMessageBox::Ok);
582 | delete ps;
583 | return;
584 | }
585 | delete ps;
586 | p = Choose.serh(p, 3);
587 | char output[1000];
588 | strcpy(output, "该学生选择的课程有:\n");
589 | while(p->next != NULL)
590 | {
591 | strcat(output, p->crs);
592 | strcat(output, "\n");
593 | p = p->next;
594 | }
595 | QMessageBox::information(NULL, "搜索完成", output, QMessageBox::Ok, QMessageBox::Ok);
596 | delete p;
597 | }
598 |
599 | void MainWindow::on_search_class_triggered()
600 | {
601 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
602 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
603 | ui->tableWidget_3->selectedItems());
604 | char coursename[20] = {'\0'};
605 | QString text;
606 | if(!items.count() || ui->tabWidget->currentIndex() == 0)
607 | {
608 | text = QInputDialog::getText(NULL, tr("搜索"), tr("请输入课程名"));
609 | }
610 | else
611 | {
612 | QTableWidgetItem *item = (ui->tabWidget->currentIndex() == 1)?items.at(0):items.at(2);
613 | text = item->text();
614 | }
615 | if(text == NULL)
616 | return;
617 | QByteArray bytearray = text.toLocal8Bit();
618 | bytearray = AnsiToUtf8(bytearray);
619 | strcpy(coursename, bytearray.data());
620 |
621 | StuCrsInfo *p = new StuCrsInfo;
622 | strcpy(p->crs, coursename);
623 | p->next = NULL;
624 |
625 | CourseInfo *pc = new CourseInfo;
626 | strcpy(pc->name, coursename);
627 | pc->next = NULL;
628 | if(Course.serh(pc, 0, Course.head) == NULL)
629 | {
630 | QMessageBox::information(NULL, "搜索完成", "不存在该课程", QMessageBox::Ok, QMessageBox::Ok);
631 | delete pc;
632 | return;
633 | }
634 | delete pc;
635 | p = Choose.serh(p, 4);
636 | char output[1000];
637 | strcpy(output, "选择该课程的学生有:\n");
638 | while(p->next != NULL)
639 | {
640 | strcat(output, p->stu);
641 | strcat(output, "\n");
642 | p = p->next;
643 | }
644 | QMessageBox::information(NULL, "搜索完成", output, QMessageBox::Ok, QMessageBox::Ok);
645 | delete p;
646 | }
647 |
648 | void MainWindow::on_add_grade_triggered()
649 | {
650 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
651 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
652 | ui->tableWidget_3->selectedItems());
653 | QString text, text2;
654 | if(!items.count() || ui->tabWidget->currentIndex() != 2)
655 | {
656 | text = QInputDialog::getText(NULL, tr("添加成绩"), tr("请输入学号"));
657 | text2 = QInputDialog::getText(NULL, tr("添加成绩"), tr("请输入课程名"));
658 | }
659 | else
660 | {
661 | QTableWidgetItem *item = items.at(0);
662 | text = item->text();
663 | item = items.at(2);
664 | text2 = item->text();
665 | }
666 | if(text == NULL)
667 | return;
668 | QByteArray bytearray = text.toLocal8Bit();
669 | bytearray = AnsiToUtf8(bytearray);
670 | char *stuid = bytearray.data();
671 | if(text2 == NULL)
672 | return;
673 | QByteArray bytearray2 = text2.toLocal8Bit();
674 | bytearray2 = AnsiToUtf8(bytearray2);
675 | char *coursename = bytearray2.data();
676 |
677 | QString text3 = QInputDialog::getText(NULL, tr("添加成绩"), tr("请输入成绩"));
678 | if(text3 == NULL)
679 | return;
680 | QByteArray bytearray3 = text3.toLocal8Bit();
681 | bytearray3 = AnsiToUtf8(bytearray3);
682 | int score = atoi(bytearray3.data());
683 |
684 | StuCrsInfo *p = new StuCrsInfo;
685 | p->next = NULL;
686 | strcpy(p->stu, stuid);
687 | strcpy(p->crs, coursename);
688 | p->grade = score;
689 | CourseInfo *pc = new CourseInfo;
690 | strcpy(pc->name, coursename);
691 | StuInfo *ps = new StuInfo;
692 | strcpy(ps->id, stuid);
693 | if(Student.serh(ps, 1) == NULL)
694 | QMessageBox::information(NULL, "添加结果", "登记成绩失败-学生不存在", QMessageBox::Ok, QMessageBox::Ok);
695 | else if(Course.serh(pc, 0, Course.head) == NULL)
696 | QMessageBox::information(NULL, "添加结果", "登记成绩失败-课程不存在", QMessageBox::Ok, QMessageBox::Ok);
697 | else if(Choose.addgrade(p))
698 | QMessageBox::information(NULL, "添加结果", "登记成绩成功", QMessageBox::Ok, QMessageBox::Ok);
699 | else
700 | QMessageBox::information(NULL, "添加结果", "登记成绩失败-未选课", QMessageBox::Ok, QMessageBox::Ok);
701 | delete ps;
702 | delete pc;
703 | MainWindow::display_choose_info();
704 | }
705 |
706 | void MainWindow::on_del_grade_triggered()
707 | {
708 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
709 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
710 | ui->tableWidget_3->selectedItems());
711 | QString text, text2;
712 | if(!items.count() || ui->tabWidget->currentIndex() != 2)
713 | {
714 | text = QInputDialog::getText(NULL, tr("删除成绩"), tr("请输入学号"));
715 | text2 = QInputDialog::getText(NULL, tr("删除成绩"), tr("请输入课程名"));
716 | }
717 | else
718 | {
719 | QTableWidgetItem *item = items.at(0);
720 | text = item->text();
721 | item = items.at(2);
722 | text2 = item->text();
723 | }
724 | if(text == NULL)
725 | return;
726 | QByteArray bytearray = text.toLocal8Bit();
727 | bytearray = AnsiToUtf8(bytearray);
728 | char *stuid = bytearray.data();
729 | if(text2 == NULL)
730 | return;
731 | QByteArray bytearray2 = text2.toLocal8Bit();
732 | bytearray2 = AnsiToUtf8(bytearray2);
733 | char *coursename = bytearray2.data();
734 |
735 | StuCrsInfo *p = new StuCrsInfo;
736 | p->next = NULL;
737 | strcpy(p->stu, stuid);
738 | strcpy(p->crs, coursename);
739 | CourseInfo *pc = new CourseInfo;
740 | strcpy(pc->name, coursename);
741 | StuInfo *ps = new StuInfo;
742 | strcpy(ps->id, stuid);
743 | if(Student.serh(ps, 1) == NULL)
744 | QMessageBox::information(NULL, "删除结果", "删除成绩失败-学生不存在", QMessageBox::Ok, QMessageBox::Ok);
745 | else if(Course.serh(pc, 0, Course.head) == NULL)
746 | QMessageBox::information(NULL, "删除结果", "删除成绩失败-课程不存在", QMessageBox::Ok, QMessageBox::Ok);
747 | else if(Choose.delgrade(p))
748 | QMessageBox::information(NULL, "删除结果", "删除成绩成功", QMessageBox::Ok, QMessageBox::Ok);
749 | else
750 | QMessageBox::information(NULL, "删除结果", "删除成绩失败-未选课", QMessageBox::Ok, QMessageBox::Ok);
751 | delete ps;
752 | delete pc;
753 | MainWindow::display_choose_info();
754 | }
755 |
756 | void MainWindow::on_caculate_triggered()
757 | {
758 | QListitems = (ui->tabWidget->currentIndex() == 0) ? ui->tableWidget->selectedItems() :
759 | ((ui->tabWidget->currentIndex() == 1) ? ui->tableWidget_2->selectedItems() :
760 | ui->tableWidget_3->selectedItems());
761 | char stuid[20] = {'\0'};
762 | QString text;
763 | if(!items.count() || ui->tabWidget->currentIndex() == 1)
764 | {
765 | text = QInputDialog::getText(NULL, tr("计算学分绩"), tr("请输入学号"));
766 | }
767 | else
768 | {
769 | QTableWidgetItem *item = (ui->tabWidget->currentIndex() == 0)?items.at(1):items.at(0);
770 | text = item->text();
771 | }
772 | if(text == NULL)
773 | return;
774 | QByteArray bytearray = text.toLocal8Bit();
775 | bytearray = AnsiToUtf8(bytearray);
776 | strcpy(stuid, bytearray.data());
777 |
778 | StuCrsInfo *p = new StuCrsInfo;
779 | strcpy(p->stu, stuid);
780 | p->next = NULL;
781 |
782 | StuInfo *ps = new StuInfo;
783 | strcpy(ps->id, stuid);
784 | ps->next = NULL;
785 | if(Student.serh(ps,1) == NULL)
786 | {
787 | QMessageBox::information(NULL, "计算学分绩", "不存在该学生", QMessageBox::Ok, QMessageBox::Ok);
788 | delete ps;
789 | return;
790 | }
791 | delete ps;
792 |
793 | p = Choose.serh(p, 3);
794 |
795 | double gpa = 0;
796 | int score_cnt = 0;
797 | while(p->next != NULL)
798 | {
799 | if(p->grade >= 0)
800 | {
801 | CourseInfo *pc = new CourseInfo;
802 | strcpy(pc->name, p->crs);
803 | CourseInfo *tmp = Course.serh(pc, 0, Course.head);
804 | delete pc;
805 | score_cnt += tmp->score;
806 | gpa += (tmp->score * p->grade);
807 | }
808 | p = p->next;
809 | }
810 | if(score_cnt == 0)
811 | gpa = 0;
812 | else
813 | gpa /= (20 * score_cnt);
814 | char output[20];
815 | sprintf(output, "%lf", gpa);
816 | QMessageBox::information(NULL, "计算完成", output, QMessageBox::Ok, QMessageBox::Ok);
817 | delete p;
818 |
819 | }
820 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class MainWindow;
9 | }
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit MainWindow(QWidget *parent = 0);
17 | ~MainWindow();
18 | void display_student_info();
19 | void display_course_info();
20 | void display_choose_info();
21 | void contextMenuEvent(QContextMenuEvent *);
22 |
23 | private slots:
24 | void on_stu_read_triggered();
25 | void on_stu_save_triggered();
26 | void on_stu_del_triggered();
27 | void on_stu_add_triggered();
28 | void on_stu_chg_triggered();
29 | void on_class_read_triggered();
30 | void on_class_save_triggered();
31 | void on_class_del_triggered();
32 | void on_class_add_triggered();
33 | void on_choose_class_triggered();
34 | void on_delete_class_triggered();
35 | void on_choose_read_triggered();
36 | void on_choose_save_triggered();
37 | void on_search_stu_triggered();
38 | void on_search_class_triggered();
39 | void on_add_grade_triggered();
40 | void on_del_grade_triggered();
41 | void on_caculate_triggered();
42 |
43 | private:
44 | Ui::MainWindow *ui;
45 | QAction *Act_Stu_Del;
46 | QAction *Act_Stu_Chg;
47 | QAction *Act_Stu_Add;
48 | QAction *Act_Crs_Del;
49 | QAction *Act_Crs_Add;
50 | QAction *Act_Cho_Del;
51 | QAction *Act_Cho_Add;
52 | QAction *Act_Srh_Stu;
53 | QAction *Act_Srh_Crs;
54 | QAction *Act_ADDGRADE;
55 | QAction *Act_DELGRADE;
56 | QAction *Act_Calc;
57 | };
58 |
59 | #endif // MAINWINDOW_H
60 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 547
10 | 348
11 |
12 |
13 |
14 | 学生信息管理系统
15 |
16 |
17 |
18 |
19 |
20 | 0
21 | 0
22 | 551
23 | 321
24 |
25 |
26 |
27 | 0
28 |
29 |
30 |
31 | 学生信息
32 |
33 |
34 |
35 |
36 | 10
37 | 10
38 | 511
39 | 251
40 |
41 |
42 |
43 | QAbstractItemView::NoEditTriggers
44 |
45 |
46 | QAbstractItemView::SingleSelection
47 |
48 |
49 | QAbstractItemView::SelectRows
50 |
51 |
52 | true
53 |
54 |
55 | 240
56 |
57 |
58 | 25
59 |
60 |
61 |
62 | 姓名
63 |
64 |
65 |
66 |
67 | 学号
68 |
69 |
70 |
71 |
72 |
73 |
74 | 课程信息
75 |
76 |
77 |
78 |
79 | 10
80 | 10
81 | 511
82 | 251
83 |
84 |
85 |
86 | QAbstractItemView::NoEditTriggers
87 |
88 |
89 | QAbstractItemView::SingleSelection
90 |
91 |
92 | QAbstractItemView::SelectRows
93 |
94 |
95 | true
96 |
97 |
98 | 160
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 | 10
125 | 10
126 | 511
127 | 251
128 |
129 |
130 |
131 | QAbstractItemView::NoEditTriggers
132 |
133 |
134 | QAbstractItemView::SingleSelection
135 |
136 |
137 | QAbstractItemView::SelectRows
138 |
139 |
140 | true
141 |
142 |
143 | 96
144 |
145 |
146 | 25
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 |
229 |
230 |
231 | 读取文件
232 |
233 |
234 | 读取文件
235 |
236 |
237 | O
238 |
239 |
240 |
241 |
242 | 保存为
243 |
244 |
245 | 保存到文件中
246 |
247 |
248 | S
249 |
250 |
251 |
252 |
253 | 删除信息
254 |
255 |
256 | 手动删除学生信息
257 |
258 |
259 | D
260 |
261 |
262 |
263 |
264 | 添加信息
265 |
266 |
267 | 手动添加学生信息
268 |
269 |
270 | A
271 |
272 |
273 |
274 |
275 | 读取文件
276 |
277 |
278 | 读取文件
279 |
280 |
281 | O
282 |
283 |
284 |
285 |
286 | 保存为
287 |
288 |
289 | 保存到文件中
290 |
291 |
292 | S
293 |
294 |
295 |
296 |
297 | 删除课程
298 |
299 |
300 | 手动删除课程信息
301 |
302 |
303 | D
304 |
305 |
306 |
307 |
308 | 添加课程
309 |
310 |
311 | 手动添加课程信息
312 |
313 |
314 | A
315 |
316 |
317 |
318 |
319 | 修改信息
320 |
321 |
322 | 修改学生信息
323 |
324 |
325 | M
326 |
327 |
328 |
329 |
330 | 选择课程
331 |
332 |
333 | C
334 |
335 |
336 |
337 |
338 | 退选课程
339 |
340 |
341 | D
342 |
343 |
344 |
345 |
346 | 查询单个学生
347 |
348 |
349 | B
350 |
351 |
352 |
353 |
354 | 查询单个课程
355 |
356 |
357 | A
358 |
359 |
360 |
361 |
362 | 读取文件
363 |
364 |
365 | O
366 |
367 |
368 |
369 |
370 | 保存为
371 |
372 |
373 | S
374 |
375 |
376 |
377 |
378 | 添加成绩
379 |
380 |
381 |
382 |
383 | 删除成绩
384 |
385 |
386 |
387 |
388 | 计算学分绩
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
--------------------------------------------------------------------------------
/stu.txt:
--------------------------------------------------------------------------------
1 | bob 10000
2 | alice 10001
3 | 赵六 10002
4 | 王五 10003
5 | 李四 10004
6 | 张三 10005
7 |
--------------------------------------------------------------------------------
/student.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | #include
3 | #include
4 | #include
5 | student::student()
6 | {
7 | student::count = 0;
8 | student::head = NULL;
9 | }
10 |
11 | student::~student()
12 | {
13 |
14 | }
15 |
16 | bool student::read(const char *filename)
17 | {
18 | FILE *fp = fopen(filename, "r");
19 | if(fp == NULL)
20 | return 0;
21 | char ch;
22 | int i = 0;
23 | bool mode = 0;
24 | StuInfo *p = new StuInfo;
25 | p->next = NULL;
26 | while((ch = fgetc(fp)) != EOF)
27 | {
28 | if(mode == 0 && ch != ' ' && ch != '\n')
29 | p->name[i++]=ch;
30 | else if(mode == 1 && ch != ' ' && ch != '\n')
31 | p->id[i++] = ch;
32 | else if(ch == '\n')
33 | {
34 | p->id[i] = '\0';
35 | i = 0;
36 | mode = 0;
37 | StuInfo *point;
38 | if((point = student::serh(p, 1)) != NULL)
39 | {
40 | strcpy(point->name, p->name);
41 | }
42 | else
43 | {
44 | if(student::head != NULL)
45 | p->next = student::head;
46 | student::head = p;
47 | ++student::count;
48 | }
49 | p = new StuInfo;
50 | p->next = NULL;
51 | }
52 | else if(ch == ' ')
53 | {
54 | p->name[i] = '\0';
55 | i = 0;
56 | mode = 1;
57 | }
58 | }
59 | fclose(fp);
60 | return 1;
61 | }
62 |
63 | /*
64 | //when read Chinese from a unicode file
65 | bool student::read(const char *filename)
66 | {
67 | QFile file(filename);
68 | file.open(QIODevice::ReadOnly | QIODevice::Text);
69 | while (!file.atEnd())
70 | {
71 | QByteArray line = file.readLine();
72 | char *info = line.data();
73 |
74 | if(strcmp("", info) == 0)
75 | break;
76 | int flag = 0;
77 | char name[20], id[20];
78 | for(int i = 0; i < 20; ++i)
79 | {
80 | name[i] = '\0';
81 | id[i] = '\0';
82 | }
83 | for(int i = 0; i < (int)strlen(info); ++i)
84 | if(flag == 0 && info[i] != ' ' && info[i] != '\n')
85 | name[i] = info[i];
86 | else if(flag != 0 && info[i] != ' ' && info[i] != '\n')
87 | id[i - flag] = info[i];
88 | else if(info[i] == ' ')
89 | flag = i+1;
90 | else if(info[i] == '\n')
91 | break;
92 | StuInfo *p = new StuInfo;
93 | p->next = NULL;
94 | strcpy(p->id, id);
95 | strcpy(p->name, name);
96 | StuInfo *point;
97 | if((point = student::serh(p, 1)) != NULL)
98 | {
99 | strcpy(point->name, p->name);
100 | }
101 | else
102 | {
103 | if(student::head != NULL)
104 | p->next = head;
105 | head = p;
106 | ++student::count;
107 | }
108 | }
109 | file.close();
110 | return 1;
111 | }
112 | */
113 |
114 | bool student::save(const char *filename)
115 | {
116 | StuInfo *p = student::head;
117 | FILE *fp = fopen(filename, "w");
118 | while(p != NULL)
119 | {
120 | fprintf(fp, p->name);
121 | fprintf(fp, " ");
122 | fprintf(fp, p->id);
123 | fprintf(fp, "\n");
124 | p = p->next;
125 | }
126 | fclose(fp);
127 | return 1;
128 | }
129 |
130 | bool student::add(StuInfo *info)
131 | {
132 | if(!(student::serh(info, 1) == NULL))
133 | return 0;
134 | student::count += 1;
135 | info->next = student::head;
136 | student::head = info;
137 | return 1;
138 | }
139 |
140 | bool student::del(StuInfo *info, bool type)
141 | {
142 | StuInfo *point;
143 | StuInfo *p = student::head;
144 | if((point = student::serh(info, type)) == NULL)
145 | return 0;
146 | student::count -= 1;
147 | if(p == point)
148 | {
149 | student::head = student::head->next;
150 | return 1;
151 | }
152 | while(p->next != NULL)
153 | if(p->next == point)
154 | break;
155 | else
156 | p = p->next;
157 | p->next = p->next->next;
158 | return 1;
159 | }
160 |
161 | bool student::chg(StuInfo *info, bool type)
162 | {
163 | StuInfo *point;
164 | if((point = student::serh(info, 1)) == NULL)
165 | return 0;
166 | if(type == 0)
167 | strcpy(point->name, info->name);
168 | else if(type == 1)
169 | strcpy(point->id, info->id);
170 | return 1;
171 | }
172 |
173 | StuInfo *student::serh(StuInfo *info, int type)
174 | {
175 | StuInfo *p = student::head;
176 | while(p != NULL)
177 | {
178 | if(type == 0 && strcmp(info->name, p->name) == 0)
179 | return p;
180 | else if(type == 1 && strcmp(info->id, p->id) == 0)
181 | return p;
182 | p = p->next;
183 | }
184 | return NULL;
185 | }
186 |
--------------------------------------------------------------------------------
/student.h:
--------------------------------------------------------------------------------
1 | #ifndef STUDENT_H
2 | #define STUDENT_H
3 |
4 | #define STU_INFO_SIZE 20
5 | struct StuInfo{
6 | char name[STU_INFO_SIZE];
7 | char id[STU_INFO_SIZE];
8 | StuInfo *next;
9 | };
10 |
11 | class student{
12 | public:
13 | student();
14 | ~student();
15 | int count;
16 | StuInfo *head;
17 | bool read(const char *);
18 | bool save(const char *);
19 | StuInfo *serh(StuInfo *, int);
20 | bool add(StuInfo *);
21 | bool del(StuInfo *, bool);
22 | bool chg(StuInfo *, bool);
23 | };
24 |
25 | #endif // STUDENT_H
26 |
--------------------------------------------------------------------------------