preface
I finished the student management system this week. I met many problems in the process of completion. Today I will summarize some difficult modules of the management system written last week.
login interface
When writing the student management system, I first write the login interface. The student management system has three identity IDS: administrator, teacher and student. My idea is to enter the account number, and the system can automatically identify the identity of the account, so my structure design is as follows:
struct personid { // Account data structure char id[20]; char cypher1[20]; char quanxian[20]; char classnum[20]; struct personid *next; };
Use string to store account, password, permission, student number or class.
Before logging in, you should first use the linked list to extract the account in the file. The code is as follows:
struct personid *Create(char name[]) { //Read the account from the file; FILE *fp = fopen(name, "r"); if (fp == NULL) { printf("File does not exist%s\n", name); exit(1); } struct personid *head = (struct personid*)malloc(sizeof(struct personid)); head->next = NULL; while (!(feof(fp))) { struct personid *p = (struct personid*)malloc(sizeof(struct personid)); fscanf(fp, "%s %s %s %s\n", p->id, p->cypher1, p->quanxian, p->classnum); p->next = head->next; head->next = p; } fclose(fp); return head; }
The following is the code of the login interface:
void menu() { //Initial interface printf("--------[Welcome to the student management system]--------\n"); printf("1.Login account\n"); printf("2.Registered account\n"); printf("3.Change Password\n"); printf("4.Retrieve password\n"); printf("0.Exit the system\n"); printf("----------------------------------\n"); setbuf(stdin, NULL); keydown(); } void keydown() { char choice[50]; scanf("%s", choice); setbuf(stdin, NULL); if (choice[1] == '\0') { switch (choice[0]) { case '0': exit(0); break; case '1': denglu(); break; case '2': zhuce(); break; case '3': xiugai(); break; case '4': zhaohui(); break; default: printf("invalid input\n"); menu(); break; } } else { printf("invalid input\n"); menu(); } }
When writing the system, we must pay attention to the stability of the program. My program operates through continuous input. At the beginning, when I write the code, I use the getchar function for input, resulting in the problem that the program will collapse after inputting multiple characters. In later modification, replace all getchar functions with scanf for input, so as to ensure the stability of the program, When judging, you only need to judge whether the input is a character and have this operation.
In macOS system, setbuf(stdin, NULL) can be used to clear the buffer.
Registration operation
If a new user enters the program, the first operation is the registration operation. When I first wrote the registration operation, I asked the user to enter his own identity. This writing method is very unsuccessful. If students operate, they can also register as an administrator, which is very lax!
Later, when modifying, different invitation codes are used to register different identities. Users do not need to enter identities. Students only need to enter their own student number, and teachers need to choose their own corresponding class.
The code is as follows:
void zhuce() { printf("Please enter the invitation code:\n"); int yaoqingma1 = 111; int yaoqingma2 = 222; int yaoqingma3 = 333; int x; scanf("%d", &x); if (x != yaoqingma1 && x != yaoqingma2 && x != yaoqingma3) { printf("Invalid invitation code, please contact the guide:\n"); setbuf(stdin, NULL); menu(); } if (x == 111 || x ==222 || x == 333) { printf("please input the id with number:"); char id[20]; char id1[20]; char id2[20]; char id3[20] = "\n"; char id4[20] = "0"; char id6[20]; scanf("%s", id); printf("please input the password:"); scanf("%s", id1); next1: if (x == 111) { strcpy(id2, qx1); printf("Please enter student number\n"); scanf("%s", id4); struct personid *p = Create(zhroad); while (p) { if (!strcmp(id4, p->classnum)) { printf("The student number has been registered,Press 0 to return to the previous level, and re-enter with any key\n"); setbuf(stdin, NULL); char a; a = getchar(); if (a == '0') { menu(); } setbuf(stdin, NULL); goto next1; } p = p->next; } } else if (x == 222) { printf("Please select your class\n"); printf("1.Network class 1\n"); printf("2.Network class 2\n"); printf("3.Network class 3\n"); printf("4.Network class 4\n"); printf("5.Network class 5\n"); scanf("%s", id6); if (id6[1] == '\0') { if (id6[0] == '1' || id6[0] == '2' || id6[0] == '3' || id6[0] == '4' || id6[0] == '5') { setbuf(stdin, NULL); strcpy(id4, id6); } else { setbuf(stdin, NULL); printf("The class does not exist.\n"); menu(); } } else { printf("The class does not exist\n"); setbuf(stdin, NULL); menu(); } strcpy(id2, qx2); } else if (x == 333) { strcpy(id2, qx3); } AppendDataToFile(zhroad, id); AppendDataToFile(zhroad, kong); AppendDataToFile(zhroad, id1); AppendDataToFile(zhroad, kong); AppendDataToFile(zhroad, id2); AppendDataToFile(zhroad, kong); AppendDataToFile(zhroad, id4); AppendDataToFile(zhroad, id3); printf("Registration succeeded, please login again!\n"); setbuf(stdin, NULL); menu(); } }
During student registration, the student number entered by the student should be judged to judge whether the student number is registered. If it is registered, it should be re entered.
During teacher registration, the teacher should be asked to select the existing class. If not, re-enter it.
After successful registration, use the file to store the registered account
Some operations of student interface
Students can mainly carry out the following operations:
void studentmenu() { //Student operation interface printf("-----[good afternoon student ]-----\n"); printf("1.Query results\n"); printf("2.Query the grade of this class\n"); printf("3.Performance analysis\n"); printf("4.Achievement appeal\n"); printf("5.Return to the previous level:\n"); printf("0.Exit the system\n"); printf("----------------------------------\n"); studentkeydown(); }
When I first wrote the code, I asked the students to input their student number for score query. If it is to enter their student number for examination, then I can also enter others' scores and query the scores of other classes. If I write this way, the students' operation is the same as that of Teachers and even administrators.
When I finally modify the code, I bind the student's student number and account number. When I perform score query and other operations, I don't need to enter my own student number,
Some operations of teacher interface
The main functions of the teacher interface are as follows
void teachermenu() { //Teacher operation interface printf("-----[good afternoon teacher]-----\n"); printf("1.Add new student information\n"); printf("2.Delete student information\n"); printf("3.Modify student information\n"); printf("4.Query student information\n"); printf("5.Output the grade of the class\n"); printf("6.Performance analysis\n"); printf("7.Remind the administrator to update the score\n"); printf("8.Return to the previous level:\n"); printf("0.Exit the system\n"); printf("----------------------------------\n"); setbuf(stdin, NULL); teacherkeydown(); }
At the beginning of writing the code, similar to the above student operations, I asked the teacher to enter the class or the teacher to enter the student number for relevant operations. In this way, the teacher will become a universal teacher and can query all the student information stored in the file. In reality, there is no teacher who teaches the whole school, and this conflicts with the function of the administrator.
Later, when modifying the code, I asked the teacher to select the class when registering with the teacher. We bound this class to the teacher's account, and stipulated that the teacher can only query the scores of students in his own class. If the scores of other classes are entered, corresponding error reminders will be given.
The teacher operation interface code is as follows:
void teacherkeydown() { //Teacher input and selection interface char *x; char *a; x = allclassnum; struct student *temp1 = NULL; char str2[200]; char str1[100]; setbuf(stdin, NULL); scanf("%s", str1); if (str1[1] == '\0') { switch (str1[0]) { case '0': exit(0); break; case '1': a = classnum(x); temp1 = mescreate(a); temp1 = addnode(temp1); writetoclassfile(temp1, a); teachermenu(); break; case '2': a = classnum(x); temp1 = mescreate(a); temp1 = delnode(temp1); writetoclassfile(temp1, a); teachermenu(); break; case '3': a = classnum(x); temp1 = mescreate(a); temp1 = changenode(temp1); writetoclassfile(temp1, a); teachermenu(); break; case '4': printf("please input student studyid:\n"); char studyid[20]; scanf("%s", studyid); if (studyid[1] == allclassnum[0] && studyid[0] == '0' && strlen(studyid) < 6) { printpersonnalsocre(studyid); teachermenu(); } else { printf("Not your student or student number does not exist\n"); teachermenu(); } break; case '5': a = classnum(x); temp1 = mescreate(a); temp1 = sort4(temp1); Printall(temp1); setbuf(stdin, NULL); teachermenu(); break; case '6': a = classnum(x); temp1 = mescreate(a); chengjifenxi(temp1); teachermenu(); break; case '7': FILE *fp1; fp1 = fopen(shensu, "w"); printf("please input the wrong\n"); scanf("%s", str2); fprintf(fp1, "%s\n", str2); printf("Your reminder has been sent!"); break; case '8': menu(); break; default: printf("Error in input, please re-enter\n"); teachermenu(); break; } } else { printf("Error in input, please re-enter\n"); teachermenu(); } }
Some operations of administrator
The main functions of the administrator are as follows:
void guanlidaiban() { printf("-----[good afternoon manager ]----\n"); printf("1.Password registration\n"); printf("2.Password modification\n"); printf("3.Password retrieval\n"); printf("4.Achievement appeal\n"); printf("5.Update grade Library\n"); printf("0.Exit the system\n"); printf("----------------------------------\n"); keydowmdaiban(); } void guanlimenu() { printf("-----[good afternoon manager ]----\n"); printf("1.Agency options\n"); printf("2.Add account and password\n"); printf("3.Delete account and password\n"); printf("4.Modify account and password\n"); printf("5.Output all accounts and passwords\n"); printf("6.Enter all accounts and passwords\n"); printf("7.Enter the teacher client\n"); printf("a.Return to the previous level\n"); printf("0.Exit the system\n"); printf("----------------------------------\n"); guanlikeydown(); }
Compared with teachers, administrators can operate accounts and query the scores of all classes. At the beginning of the design, I wrote the operation of administrators in conflict with students and teachers, especially entering the teacher client. The code of entering the teacher client is as follows.
printf("Please select the class you want to operate\n"); printf("1.Network class 1\n"); printf("2.Network class 2\n"); printf("3.Network class 3\n"); printf("4.Network class 4\n"); printf("5.Network class 5\n"); scanf("%s", choice1); if (choice1[1] != '\0') { printf("Class does not exist, please re-enter\n"); goto next1; } else if (choice1[0] == '1' || choice1[0] == '2' || choice1[0] == '3' || choice1[0] == '4' || choice1[0] == '5') { allclassnum[0] = choice1[0]; teachermenu(); } else { printf("Class does not exist, please re-enter\n"); goto next1; }
The administrator can select the class to view. When the administrator selects it, I change the global variable allclassnum (record teacher class) to the corresponding class, and then enter the teacher side.
summary
At the beginning of writing the management system, I didn't pay attention to many details, and the logic is very unreasonable, which leads to the collapse when I just finished writing. The next time I write the program, I should comply with the most basic logic problem.