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
| #pragma warning(disable:4996) #include "StudentSystemManager.h"
int main() { Node* head = malloc(sizeof(Node)); head->next = NULL; loadStudent(head);
while (1) {
welcome();
char c = _getch();
switch (c) { case '1': inputStudent(head); break; case '2': printStudent(head); break; case '3': countStudent(head); break; case '4': findStudent(head); break; case '5': modifyStudent(head); break; case '6': deleteStudent(head); break; case '7': sortStudent(head); break; case '8': system("cls"); printf("Bye Bye!\n"); exit(0); break; default: printf("请重新输入\n"); break; } }
return 0; }
void welcome() { printf("*********************************\n"); printf("*\t学生成绩管理系统\t*\n"); printf("*********************************\n"); printf("*\t请选择功能列表\t\t*\n"); printf("*********************************\n"); printf("*\t1.录入学生信息\t\t*\n"); printf("*\t2.打印学生信息\t\t*\n"); printf("*\t3.统计学生人数\t\t*\n"); printf("*\t4.查找学生信息\t\t*\n"); printf("*\t5.修改学生信息\t\t*\n"); printf("*\t6.删除学生信息\t\t*\n"); printf("*\t7.按成绩排序\t\t*\n"); printf("*\t8.退出系统\t\t*\n"); printf("*********************************\n"); }
void inputStudent(Node* head) {
Node* fresh = malloc(sizeof(Node)); fresh->next = NULL; printf("请输入学生的学号,姓名,成绩 "); scanf("%d%s%d", &fresh->student.stuNum, fresh->student.name, &fresh->student.score);
Node* move = head; while (move->next != NULL) { move = move->next; } move->next = fresh;
saveStudent(head); system("pause"); system("cls"); }
void printStudent(Node* head) { Node* move = head->next; while (move != NULL) { printf("学号:%d 姓名:%s 成绩:%d\n", move->student.stuNum, move->student.name, move->student.score); move = move->next; } system("pause"); system("cls"); }
void countStudent(Node* head) { int count = 0; Node* move = head->next; while (move != NULL) { count++; move = move->next; } printf("学生的总人数为:%d\n", count); system("pause"); system("cls"); }
void findStudent(Node* head) { printf("请输入要查找的学生的学号: "); int stuNum; scanf("%d", &stuNum); Node* move = head->next; while (move != NULL) { if (stuNum == move->student.stuNum) { printf("学号: %d 姓名:%s 成绩:%d\n", move->student.stuNum, move->student.name, move->student.score); system("pause"); system("cls"); return; } move = move->next; } printf("未找到学生信息\n"); system("pause"); system("cls"); }
void saveStudent(Node* head) { FILE* file = fopen("./stu.info", "w"); Node* move = head->next; while (move != NULL) { if (fwrite(&move->student, sizeof(Student), 1, file) != 1) { printf("写入失败\n"); return; } move = move->next; } fclose(file); }
void loadStudent(Node* head) { FILE* file = fopen("./stu.info", "r"); if (!file) { printf("没有学生文件,跳过读取\n"); return; } Node* fresh = malloc(sizeof(Node)); fresh->next = NULL; Node* move = head; while (fread(&fresh->student, sizeof(Student), 1, file) == 1) { move->next = fresh; move = fresh; fresh = malloc(sizeof(Student)); fresh->next = NULL; } free(fresh); fclose(file); printf("读取成功\n"); }
void modifyStudent(Node* head) { printf("请输入要修改的学生的学号: "); int stuNum; scanf("%d", &stuNum); Node* move = head->next; while (move != NULL) { if (move->student.stuNum == stuNum) { printf("请输入学生姓名,成绩\n"); scanf("%s%d", move->student.name, &move->student.score); saveStudent(head); printf("修改成功\n"); system("pause"); system("cls"); return; } move = move->next; } printf("未找到学生信息\n"); system("pause"); system("cls"); }
void deleteStudent(Node* head) { printf("请输入要删除的学生学号 "); int stuNum = 0; scanf("%d", &stuNum);
Node* move = head; while (move->next != NULL) {
if (move->next->student.stuNum == stuNum) { Node* tmp = move->next; move->next = move->next->next; free(tmp); tmp = NULL; saveStudent(head); printf("删除成功\n"); system("pause"); system("cls"); return; }
move = move->next; } printf("未找到学生信息\n"); system("pause"); system("cls"); }
void sortStudent(Node* head) { Node* save = NULL; Node* move = NULL; for (Node* turn = head->next; turn->next != NULL; turn = turn->next) { for (move = head->next; move->next != save; move = move->next) { if (move->student.score > move->next->student.score) { Student temp = move->student; move->student = move->next->student; move->next->student = temp; } } save = move; } printStudent(head); }
|