Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Student Management system based on C language

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to realize the student management system based on C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to implement a student management system based on C language".

1. Target requirements:

1. Student performance management system

two。 Can add, delete, change, check, browse

3. Data is saved in a file

2.C language code:

File 1: source fil

# include "mylist.h" / / menu design void menu () {/ / all files are synchronized to the file printf ("- [student management information] -\ n"); printf ("\ t\ t0. Exit the system\ n "); printf ("\ t\ T1. Enter information\ n "); printf ("\ t\ T2. Browse information\ n "); printf ("\ t\ T3. Modification information\ n "); printf ("\ t\ t4. Delete message\ n "); printf ("\ t\ t5. Find information\ n "); printf ("--\ n ");} struct Node* list;// user interaction / / according to the selected menu item, do the corresponding thing void keyDown () {int choice = 0; struct student data; struct Node* pMove = NULL Scanf ("% d", & choice); switch (choice) {case 0: printf ("exit normally! \ n "); system (" pause "); exit (0); break; case 1: printf ("-enter information -\ n "); / / insert linked list fflush (stdin) / / clear the buffer! Printf ("Please enter the student's name, age, gender, telephone number:\ n"); scanf ("% s%d%s%s", data.name,&data.age,data.sex,data.tel); insertNodeByHead (list,data); break Case 2: printf ("- browse information -\ n"); printList (list); / / print linked list break Case 3: printf ("- modify information -\ n"); printf ("Please enter the name of the student to modify the information:"); scanf ("% s", data.name); reviseInfoByData (list,data.name); break Case 4: printf ("- delete information -\ n"); printf ("Please enter the name of the deleted student:"); scanf ("% s", data.name); deleteNode (list,data.name); break Case 5: printf ("- find information -\ n"); printf ("Please enter the name of the student you want to find:"); scanf ("% s", data.name) If (pMove = searchInfoByData (list,data.name)) {printf ("name\ t age\ t gender\ t phone\ n"); printf ("% s\ t% d\ t% s\ t% s\ n", pMove- > data.name,pMove- > data.age,pMove- > data.sex,pMove- > data.tel);} break Default: printf ("choose wrong, re-enter\ n"); system ("pause"); break;} writeInfoToFile (list, "1.txt");} int main () {list = createList (); readInfoFromFile (list, "1.txt"); while (1) {menu (); keyDown (); system ("pause") System ("cls");} system ("pause"); return 0;}

File 2:mylist.h

# include#include # include / / data design-"the student information abstracts struct student {char name [20]; int age; char sex [5]; char tel [20]; / / int math;// int english;}; / / structure / / the structure of the test struct Node {struct student data; struct Node* next;} / / create header struct Node* createList () {struct Node* headNode = (struct Node*) malloc (sizeof (struct Node)); headNode- > next = NULL; return headNode;} / / create node struct Node* createNode (struct student data) {struct Node* newNode = (struct Node*) malloc (sizeof (struct Node)); newNode- > data = data; newNode- > next = NULL; return newNode } / / insert node (header method) void insertNodeByHead (struct Node* headNode, struct student data) {struct Node* newNode = createNode (data); newNode- > next = headNode- > next; headNode- > next = newNode;} / / Delete void deleteNode (struct Node* headNode,char* name) {struct Node* posFrontNode; struct Node* posNode; if (headNode- > next = = NULL) {printf ("the linked list is empty! \ n "); return;} posFrontNode = headNode; posNode = headNode- > next; while (posNode & & strcmp (posNode- > data.name,name)) {posFrontNode = posNode; posNode = posFrontNode- > next;} if (! posNode) {printf (" the data you want to delete does not exist! \ n "); return;} if (! strcmp (posNode- > data.name,name)) {posFrontNode- > next = posNode- > next; free (posNode);}} / / find function struct Node* searchInfoByData (struct Node* headNode,char* name) {struct Node* posNode; if (headNode- > next = = NULL) {printf (" linked list is empty! \ n "); return NULL;} posNode = headNode- > next; while (posNode & & strcmp (posNode- > data.name,name)) {; posNode = posNode- > next;} if (! posNode) {printf (" the data you are looking for does not exist! \ n "); return NULL;} return posNode;} / / modify function void reviseInfoByData (struct Node* headNode,char* name) {struct Node* posNode; if (headNode- > next = = NULL) {printf (" linked list is empty! \ n "); return;} posNode = headNode- > next; while (posNode & & strcmp (posNode- > data.name,name)) {; posNode = posNode- > next;} if (! posNode) {printf (" the data you want to modify does not exist! \ n "); return;} printf (" Please enter the age, sex, telephone number of student [% s], posNode- > data.name); scanf ("% d%s%s", & posNode- > data.age,posNode- > data.sex,posNode- > data.tel);} / / File read operation void readInfoFromFile (struct Node* headNode,char* fileName) {/ / 1. Open the file FILE * fp; struct student data; fp = fopen (fileName, "r"); if (fp = = NULL) {fopen (fileName, "w +"); / / Open the file with creation function} / / 2. Read file while (fscanf (fp, "% s\ t% d\ t% s\ t% s\ n", data.name,&data.age,data.sex,data.tel)! = EOF) {insertNodeByHead (headNode,data);} / / 3. Close the file fclose (fp);} / / File write operation void writeInfoToFile (struct Node* headNode,char* fileName) {/ / 1. Open the file FILE * fp; fp = fopen (fileName, "w"); struct Node* pMove = headNode- > next; / / 2. Write the file while (pMove) {fprintf (fp, "% s\ t% d\ t% s\ t% s\ n", pMove- > data.name,pMove- > data.age,pMove- > data.sex,pMove- > data.tel); pMove = pMove- > next;} / / 3. Close the file fclose (fp);} / print the linked list void printList (struct Node* headNode) {struct Node* pMove = headNode- > next; / / Design column data processing printf ("name\ t age\ t gender\ t phone\ n"); while (pMove) {printf ("% s\ t% d\ t% s\ t% s\ n", pMove- > data.name,pMove- > data.age,pMove- > data.sex,pMove- > data.tel) PMove = pMove- > next;} printf ("\ n");} 3. Running result:

At this point, I believe you have a deeper understanding of "how to realize the student management system based on C language". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report