Easy to use C language to achieve student achievement management system (source code attached)

image I believe that most beginners have to do such a program, that is to use C language to realize a student performance management system, which re...
image

I believe that most beginners have to do such a program, that is to use C language to realize a student performance management system, which requires the realization of student information, the addition, deletion, modification and check of performance. Although it's not difficult, but for the students who just learned to play knowledge, it's just one head and two beats, unable to start! SO, I'm here to attach the source code (with notes), and I can do it by myself!

[article welfare]: Xiaobian has its own learning exchange group 627819188! You can get the basic C language to the actual combat materials for free

If you don't say much, go to the source code directly:

Rendering:

image

Source code display:

#define _CRT_SECURE_NO_WARNINGS /******************************** Project Name: student achievement management system By Maye WeChat public address: C language Plus ********************************/ #include <stdio.h> #include <stdlib.h> #include <conio.h> typedef struct tagStudent { char szName[10]; //Full name int nAge; //Gender int nStuNum; //Student ID int nScore; //achievement }Student; typedef struct tagNode { Student stu; //Student information struct tagNode* pNext; //Point to the next student }Node; Node *g_pHead = NULL; //Define the first student //Enter student information void InputStudent(); //Print student information void PrintStudent(); //Save student information void SaveStudent(); //Read student information void ReadStudent(); //Count all students int CountStudent(); //Find student information Node* FindStudent(); //Modify a student's information void ModifyStudent(); //Delete student information void DeleteStudent(); int main() { while (1) { printf("==============Welcome to the university student achievement management system V1.0==============\n"); printf("\t=======Please select function list=======\n"); printf("\t\t1.Enter student information\n"); printf("\t\t2.Print student information\n"); printf("\t\t3.Save student information\n"); printf("\t\t4.Read student information\n"); printf("\t\t5.Count all students\n"); printf("\t\t6.Find student information\n"); printf("\t\t7.Modify student information\n"); printf("\t\t8.Delete student information\n"); printf("\t\t0.Exit system\n"); char ch; //scanf("%c", &ch); ch = _getch(); switch (ch) { case '1'://Enter student information InputStudent(); break; case '2'://Print student information PrintStudent(); break; case '3'://Save student information SaveStudent(); break; case '4'://Read student information ReadStudent(); break; case '5'://Count all students printf("The current total number of students is:%d\n", CountStudent()); break; case '6'://Find student information { Node *pNode = FindStudent(); if (pNode != NULL) { printf("Student ID:%d\t Full name:%s\t Age:%d\t achievement:%d\n", pNode->stu.nStuNum, pNode->stu.szName, pNode->stu.nAge, pNode->stu.nScore); } break; } case '7'://Modify a student's information ModifyStudent(); break; case '8'://Delete student information DeleteStudent(); break; case '0': printf("Welcome to use again!\n"); return 0; break; default: printf("Your input is wrong, please input again!\n"); break; } // } return 0; } //Enter student information void InputStudent() { printf("\n Please input student information:Name Student ID age grade\n"); Node* p; p = g_pHead; while (g_pHead != NULL && p->pNext != NULL) { p = p->pNext; } //Allocate a space for new students Node* pNewNode = (Node*)malloc(sizeof(Node)); pNewNode->pNext = NULL; if (g_pHead == NULL) { g_pHead = pNewNode; p = g_pHead; } else { p->pNext = pNewNode;//The next node of p is pNewNode } //Enter new student data scanf("%s %d %d %d", pNewNode->stu.szName, &pNewNode->stu.nStuNum, &pNewNode->stu.nAge, &pNewNode->stu.nScore); system("cls"); printf("\n Data added successfully....\n"); } //Print student information void PrintStudent() { system("cls"); printf("Print all student information\n"); Node* p; p = g_pHead; while (p != NULL) { printf("Student ID:%d\t Full name:%s\t Age:%d\t achievement:%d\n", p->stu.nStuNum, p->stu.szName, p->stu.nAge, p->stu.nScore); p = p->pNext; } } //Save student information void SaveStudent() { system("cls"); FILE *pFile = fopen("C:\\stuinfo.data", "w"); if (pFile == 0) { printf("fail to open file\n"); return; } //Write data Node *p; p = g_pHead; while (p != NULL) { fprintf(pFile, "%d %s %d %d\n", p->stu.nStuNum, p->stu.szName, p->stu.nAge, p->stu.nScore); p = p->pNext; } printf("Data saved successfully\n"); //Close file fclose(pFile); } //Read student information void ReadStudent() { system("cls"); //First delete the linked list data, and then read the data from the file Node *p, *p2; p = p2 = g_pHead; while (p2 != NULL) { //Delete data in linked list p = p->pNext; free(p2); p2 = p; } g_pHead = NULL; //Open file FILE *pFile = fopen("C:\\stuinfo.data", "r"); if (pFile == 0) { printf("fail to open file\n"); return; } //Read data while (!feof(pFile)) { //Allocate space to store data Node *pTemp = (Node*)malloc(sizeof(Node)); //Read from file fscanf(pFile, "%d %s %d %d\n", &pTemp->stu.nStuNum, &pTemp->stu.szName, &pTemp->stu.nAge, &pTemp->stu.nScore); //Create linked list if (g_pHead == NULL) { g_pHead = pTemp; p = g_pHead; } else { p->pNext = pTemp;//The next node of p is temp p = p->pNext; p->pNext = NULL; } } //Close file fclose(pFile); } //Count all students int CountStudent() { system("cls"); int nCount = 0; //First, read the data in the file into the linked list ReadStudent(); Node *p; p = g_pHead; while (p != NULL) { nCount++; p = p->pNext; } return nCount; } //Find student information Node* FindStudent() { system("cls"); int nStuNum; printf("Please enter the student ID of the student you want to find:\n"); scanf("%d", &nStuNum); //Read from the file to the linked list first ReadStudent(); Node* p; p = g_pHead; while (p != NULL) { if (p->stu.nStuNum == nStuNum) { return p; } p = p->pNext; } //No information found after traversing the list if (p == NULL) { printf("No information about the student\n"); return NULL; } return NULL; } //Modify a student's information void ModifyStudent() { system("cls"); int nStuNum; printf("Please enter the student number to modify the student information:\n"); scanf("%d", &nStuNum); //First, read the data in the file into the linked list ReadStudent(); Node* p; p = g_pHead; while (p != NULL) { if (p->stu.nStuNum == nStuNum) { printf("Please enter the information to be modified: name, student number, age, grade\n"); scanf("%s %d %d %d", p->stu.szName, &p->stu.nStuNum, &p->stu.nAge, &p->stu.nScore); printf("Modified success!\n"); break; } p = p->pNext; } if (p == NULL) { printf("No information about the student!\n"); } } //Delete student information void DeleteStudent() { system("cls"); int nStuNum; printf("Please enter the student number to delete the student information:\n"); scanf("%d", &nStuNum); //First read the data in the file to the linked list ReadStudent(); Node *p, *p2; p = g_pHead; //Determine whether it is a header node if (g_pHead->stu.nStuNum == nStuNum) { p2 = g_pHead; g_pHead = g_pHead->pNext;//The head pointer points to the first element after the element is deleted free(p2);//Release node return; } //Not the head node while (p->pNext != NULL) { if (p->pNext->stu.nStuNum == nStuNum) { p2 = p->pNext; p->pNext = p->pNext->pNext;//Delete this node pointer skip this node free(p2); return; } p = p->pNext;//Point to next node if (p->pNext == NULL) { //Determine whether the end of the list is reached break; } } if (p->pNext == NULL) { printf("No information about the student\n"); } }

[article welfare]: Xiaobian has its own learning exchange group 627819188! You can get the basic C language to the actual combat materials for free


Data.png

4 December 2019, 18:13 | Views: 8058

Add new comment

For adding a comment, please log in
or create account

0 comments