Recently, many students need to complete their own C language course design because of the requirements of the school, so many people chat with me privately or ask me the most questions are "Student Performance Management System". In fact, when you write more items, you will find that: in fact, all kinds of management systems can not be separated from a core - chain list!
Yes, whether you want to write student achievement management system, dormitory management system, train ticket management system or tourism management system, you need to use our chain structure to write, so today, let's see how to use C language chain management system to write!
This issue of sharing is not to directly teach you to write this student achievement management system, but to take this as a starting point, leading to the core of our university project management system - the chain structure.
In a word, let's take a look at the core of this article - the core source of chain structure management system.Let you do it: I have a watch on my hand!
Source dedicatedFirst, let's look at the code for our singleList.h file, which is actually a specific operation on our data. Of course, the core is our chain structure:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct MM { char name[20]; int age; int num; char addr[20]; }; struct Node { //int data; struct MM data; struct Node* next; }; //All places that involve data need to be changed struct Node* createHead() { struct Node* headNode = (struct Node*)malloc(sizeof(struct Node)); headNode->next = NULL; return headNode; } struct Node* createNode(struct MM data) { struct Node * newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = NULL; return newNode; } void insertByHead(struct Node* headNode, struct MM data) { struct Node* newNode = createNode(data); newNode->next = headNode->next; headNode->next = newNode; } //Browse by Find void searchAllInfo(struct Node* headNode, char *name) { struct Node* pMove = headNode->next; while (pMove != NULL) { //!strcmp(pMove->data.name,name)Conditions can be changed to //strcmp(pMove->data.name,name)==0 //!:Negating True and False, False and True //!-1 Equal to 0 //Nonzero representation is valid in computers if (!strcmp(pMove->data.name, name)) printf("%s\t%d\t%d\t%s\n", pMove->data.name, pMove->data.age, pMove->data.num, pMove->data.addr); pMove = pMove->next; } } //Find by name struct Node* searchInfo(struct Node* headNode, char *name) { struct Node* pMove = headNode->next; while (pMove != NULL&&strcmp(pMove->data.name, name)) { pMove = pMove->next; } return pMove; //Return NULL Can't find } //Change to Name //Delete a way void deleteByAppoin(struct Node* headNode, char *name) { struct Node* posNodeLeft = headNode; struct Node* posNode = headNode->next; //string comparison+Data peeling onions while (posNode != NULL&&strcmp(posNode->data.name ,name)) { posNodeLeft = posNode; posNode = posNodeLeft->next; } if (posNode == NULL) { printf("The specified location was not found,Cannot Delete!\n"); } else { posNodeLeft->next = posNode->next; free(posNode); posNode = NULL; printf("Delete succeeded!\n"); } } //Delete all identical names void deleteAll(struct Node* headNode, char *name) { while (searchInfo(headNode, name) != NULL) { deleteByAppoin(headNode, name); } } //Modify all with the same name void modifyALL(struct Node* headNode, char *name,struct MM newInfo) { while (searchInfo(headNode, name) != NULL) { searchInfo(headNode, name)->data = newInfo; } } //Print-->Specific requirements:rise void printList(struct Node* headNode) { struct Node* pMove = headNode->next; //Headers of tabular data printf("name\tage\tnum\taddr\n"); while (pMove != NULL) { //Onion stripping is required to print structure data printf("%s\t%d\t%d\t%s\n", pMove->data.name, pMove->data.age, pMove->data.num, pMove->data.addr); pMove = pMove->next; } } //Bubble sort of chain list void BubbleSortList(struct Node*headNode) { //0---size for (struct Node* p = headNode->next; p != NULL; p = p->next) { for (struct Node* q = headNode->next; q->next != NULL; q = q->next) { if ((q->data.age > q->next->data.age)) { struct MM tempData = q->data; q->data = q->next->data; q->next->data = tempData; } } } printList(headNode); } void BubbleSortByName(struct Node*headNode) { //0---size for (struct Node* p = headNode->next; p != NULL; p = p->next) { for (struct Node* q = headNode->next; q->next != NULL; q = q->next) { if (strcmp(q->data.name, q->next->data.name)>0) { struct MM tempData = q->data; q->data = q->next->data; q->next->data = tempData; } } } printList(headNode); }
Okay, let's complete this interface again:
#define _CRT_SECURE_NO_WARNINGS #include "singleList.h" struct Node* list = NULL; //Container for storing data //1.menu void makeMenu() { printf("-----------[Miss Sister Management System)--------\n"); printf("\t0.Exit System\n"); printf("\t1.Enter Information\n"); printf("\t2.Browse System\n"); printf("\t3.Modify System\n"); printf("\t4.Find Display\n"); printf("\t5.Delete Information\n"); printf("\t6.Sort Display\n"); printf("-------------------------------------\n"); } //2.Make key interactions void keyDown() { int userKey = 0; struct MM tempData; //Store user's data struct Node* posNode = NULL; scanf("%d", &userKey); switch (userKey) { case 0: printf("Exit normally, welcome next time!\n"); system("pause"); exit(0); break; case 1: //Pass-through for current function //Increase global variables printf("Please enter information:(name,age,num,addr):"); scanf("%s%d%d%s", tempData.name, &tempData.age, &tempData.num, tempData.addr); insertByHead(list,tempData); break; case 2: printList(list); break; case 3: //modify --->Modify Job printf("Please enter a name to modify:"); scanf("%s", tempData.name); //The input information is stored in a temporary variable tempInfo //Loop to make changes: know posNode==NULL position posNode = searchInfo(list, tempData.name); if (posNode == NULL) { printf("The specified location was not found and cannot be modified!"); } else { printf("Please enter new information:(name,age,num,addr):"); scanf("%s%d%d%s", posNode->data.name, &posNode->data.age, &posNode->data.num, posNode->data.addr); //posNode->data=tempInfo; printf("Successful modification!"); } break; case 4: //lookup printf("Please enter the name you want to find:"); scanf("%s", tempData.name); searchAllInfo(list, tempData.name); break; case 5: //delete printf("Please enter a name to delete:"); scanf("%s", tempData.name); deleteByAppoin(list, tempData.name); break; case 6: BubbleSortList(list); break; // default: printf("Input error!,Re-enter!\n"); break; } } int main() { list = createHead(); //1.Create Container while (1) { makeMenu(); keyDown(); system("pause"); system("cls"); } system("pause"); return 0; }
Okay, that's it for this issue of sharing!Hope it will be helpful to you, and you can complete your own management system according to what you share in this article.
Actually, as a programming learner, it is very important to have a learning atmosphere and a communication circle. Here I recommend a C language C++ communication Q group 1108152000. Whether you are a little white or a transitioner, you can communicate and grow together.
WeChat Public Number: C Language Programming Learning Base, learning C/C++ programming knowledge, welcome to ~