码迷,mamicode.com
首页 > 其他好文 > 详细

[数据结构实验]学生成绩管理

时间:2014-11-25 12:27:30      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <malloc.h>
 4 #include <cstring>
 5 #define NULL 0
 6 #define LEN sizeof(Node)
 7 using namespace std;
 8 const char lesson[][12] = {"Math", "English", "Chinese", "physics", "Chemistry"};
 9 struct Node {
10         char ID[110];
11         int arr[5];
12         struct Node *next;
13         void clear() {
14                 memset(ID, 0, sizeof(ID));
15                 memset(arr, 0, sizeof(arr));
16                 next = NULL;
17         }
18 };
19 
20 struct StudentGradeManage {
21         Node *head = NULL;
22         void addStu() {
23                 Node *p = head;
24                 printf("%d\n", p->next);
25                 while(p->next != NULL) p = p->next;
26                 while(1) {
27                         Node *tmp;
28                         tmp = (Node*) malloc(LEN);
29                         tmp->next = NULL;
30                         cout<< "Input ID(exit, input 0): ";
31                         cin>> tmp->ID;
32                         if(strlen(tmp->ID) == 1 && tmp->ID[0] == 0) break;
33                         for(int i = 0; i < 5; i++) {
34                                 printf("Input %s grade: ", lesson[i]);
35                                 cin>> tmp->arr[i];
36                         }
37                         p->next = tmp;
38                 }
39         }
40         void deleteStu() {
41                 while(1) {
42                         char str[102];
43                         cout<< "Input ID(exit, input 0): ";
44                         cin>> str;
45                         if(strlen(str) == 1 && str[0] == 0) break;
46                         Node *p = head, *fa = NULL;
47                         int F = 0;
48                         while(p) {
49                                 if(strcmp(p->ID, str) == 0) {
50                                         if(fa == NULL) head = p->next;
51                                         else fa->next = p->next;
52                                         F = 1;
53                                         break;
54                                 }
55                                 fa = p;
56                                 p = p->next;
57                         }
58                         if(F) puts("successfully delete!");
59                         else puts("ID don‘t exist!");
60                 }
61         }
62         void displayStu() {
63                 cout<< "***********************************************************"<< endl;
64                 cout<< "ID        ";
65                 for(int i = 0; i < 5; i++) cout<< lesson[i]<< "        ";
66                 Node *p = head;
67                 while(p) {
68                         printf("%s        ", p->ID);
69                         for(int i = 0; i < 5; i++) printf("%d        ", p->arr);
70                         p = p->next;
71                 }
72                 cout<< "***********************************************************"<< endl;
73         }
74 };
75 int main()
76 {
77         StudentGradeManage G;
78         while(1) {
79                 G.addStu();
80                 G.deleteStu();
81                 G.displayStu();
82         }
83         return 0;
84 }
View Code

 

[数据结构实验]学生成绩管理

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/jklongint/p/4120584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!