当前位置:网站首页>C language - student achievement management system
C language - student achievement management system
2022-06-30 07:24:00 【Three stinky ginger】
C Language - Student achievement management system
List of articles
Preface
I'm reviewing recently C Language and data structure , So use pure C Language single chain table to write a performance management system to practice .
Implemented function
The main interface of the system is as follows :

As shown in the interface , The main functions are as follows :
- Increase record
- Delete record
- Query log
- Modify the record
- Sort
- Sum and average
It's easy to write , But these basic functions have been realized , I hope it can play a role in attracting jade .
The system has a lot of room to optimize , For example, you can use the clear screen function system(“cls”); ( Its header file is stdlib.h) To get a better experience .
Add student information
The head inserting method is realized 、 Tail interpolation and global traversal .
// Add student
bool add_student(stu *L)
{
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
printf(" Please enter the following information in turn : Student number 、 full name 、 Chinese achievement 、 Math scores 、 English scores ( Press enter to enter the next item after each entry )\n");
scanf("%d",&number);
scanf("%s",name);
scanf("%d",&Chinese);
scanf("%d",&maths);
scanf("%d",&English);
// Apply for a new memory space
stu *p; // The pointer P Point to the currently scanned node
p = L; //L Point to the head node , The head node is the second node 0 Nodes ( No data )
stu *s = (stu *)malloc(sizeof(stu));
// Assign a value to the new node
s->number = number;
for(int i=0;i<sizeof(name);i++) // Array element assignment cannot make array equal to array directly
s->name[i] = name[i];
s->Chinese = Chinese;
s->maths = maths;
s->English = English;
// The change of the pointer
s->next = p->next;
p->next = s;
return true;
}
// Show all information , Global traversal
void show_all(stu *L)
{
printf(" All student information is as follows :\n");
printf(" Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
stu *p;
p = L->next;//p Point to the head node
while(p!=NULL)
{
printf("%4d %s %3d %3d %3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
p = p->next;
}
}
The above is realized according to the head insertion method , The tail interpolation Ideas : It is similar to the head inserting method ,p First equals the head pointer , Let it move all the way back , Until it points to the end , To insert nodes .
// Add student
bool add_student(stu *L)
{
// The first interpolation
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
printf(" Please enter the following information in turn : Student number 、 full name 、 Chinese achievement 、 Math scores 、 English scores ( Press enter to enter the next item after each entry )\n");
scanf("%d",&number);
scanf("%s",name);
scanf("%d",&Chinese);
scanf("%d",&maths);
scanf("%d",&English);
// Apply for a new memory space
stu *p; // The pointer P Point to the currently scanned node
p = L; //L Point to the head node , The head node is the second node 0 Nodes ( No data )
stu *s = (stu *)malloc(sizeof(stu));
// Assign a value to the new node
s->number = number;
for(int i=0;i<sizeof(name);i++) // Array element assignment cannot make array equal to array directly
s->name[i] = name[i];
s->Chinese = Chinese;
s->maths = maths;
s->English = English;
//------------ The tail interpolation ------------//
// The tail interpolation method mainly includes this while loop
while(p->next!=NULL)
{
p = p->next;
}
s->next = p->next;
p->next = s;
//------------ The tail interpolation ------------//
return true;
}
According to the student number
The idea of querying by student number is very simple , Just traverse with a pointer , Then compare whether the student number of the data pointed to by the pointer is consistent with the student number you query , If consistent, output , If not, continue the cycle .
// According to the student number
bool search_num(stu *L,int num)
{
stu *p;
p = L->next;
while(p!=NULL)
{
if(p->number == num)
{
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
return true;
}
p = p->next;
}
return false;
}
Delete student records according to student id
Deleting is a little different from querying . To delete, first find the node data you want to delete , But because this is a single linked list , So you need to find the previous node of the node to be deleted , Change the pointer of the previous node directly to the next node of the node you want to delete , Then release the node you want to delete .
// Delete... According to student number
bool del_student(stu *L,int num)
{
stu *p;
p = L;// Give Way p Start from scratch
while(p->next!=NULL)
{
stu *q = p->next; // q Point to the deleted node
if(q->number == num) //p If you want to delete the next node data
{
printf(" The node data you deleted is :\n%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",q->number,q->name,q->Chinese,q->maths,q->English);
p->next = q->next;// Delete
free(q);
return true;
}
p = p->next;
}
return false;
}
Query and modify the information according to the student number
It's easy to modify . You need to query before modifying , After finding the data , Make an assignment of the data .
// Query and modify the information according to the student number
bool verify_num(stu *L,int num)
{
stu *p;
p = L->next;
while(p!=NULL)
{
if(p->number == num)
{
printf(" The information you want to modify is :\n Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
printf(" Please re-enter the following information : Student number 、 full name 、 Chinese achievement 、 Math scores 、 English scores ( Press enter to enter the next item after each entry )\n");
scanf("%d",&number);
scanf("%s",name);
scanf("%d",&Chinese);
scanf("%d",&maths);
scanf("%d",&English);
// Assign a value to this node
p->number = number;
for(int i=0;i<sizeof(name);i++) // Array element assignment cannot make array equal to array directly
p->name[i] = name[i];
p->Chinese = Chinese;
p->maths = maths;
p->English = English;
return true;
}
p = p->next;
}
return false;
}
According to the Chinese scores from high to low
Sorting this is a little more complicated , Because there are many steps . It should be noted that , Sorting cannot change the structure of the original linked list , So I did an operation to take out the linked list data and put it into an array , Then sort the array .
// Sort according to Chinese scores
bool sort_Chinese(stu *L)
{
int numbers = 0;// Count the number of records first
stu *p;
p = L->next;
while(p!=NULL)
{
numbers++;
p = p->next;
}
printf(" A total of %d Student records !\n",numbers);
stu data[numbers]; // Put all the data into this array , Perform statistical operations on this array
p = L->next;// Give Way p Point back to the beginning
for(int i=0;i<numbers;i++)
{
if(p!=NULL)
{
data[i].number = p->number;
for(int j=0;j<sizeof(p->name);j++) // Array element assignment cannot make array equal to array directly
data[i].name[j] = p->name[j];
data[i].Chinese = p->Chinese;
data[i].maths = p->maths;
data[i].English = p->English;
p = p->next;
}
}
int temp_num;// Temporary student number
char temp_name[10];
int temp_Chinese;
int temp_maths;
int temp_English;
// Sort according to Chinese scores
for(int i=0;i<numbers-1;i++)
{
for(int j=0;j<numbers-1-i;j++)
{
if(data[j].Chinese<data[j+1].Chinese)
{
// Exchange student numbers
temp_num = data[j+1].number;
data[j+1].number = data[j].number;
data[j].number = temp_num;
// Exchange names
for(int k=0;k<sizeof(data[0].name);k++) // Array element assignment cannot make array equal to array directly
{
temp_name[k] = data[j+1].name[k];
data[j+1].name[k] = data[j].name[k];
data[j].name[k] = temp_name[k];
}
// Exchange Chinese scores
temp_Chinese = data[j+1].Chinese;
data[j+1].Chinese = data[j].Chinese;
data[j].Chinese = temp_Chinese;
// Exchange math grades
temp_maths = data[j+1].maths;
data[j+1].maths = data[j].maths;
data[j].maths = temp_maths;
// Exchange English scores
temp_English = data[j+1].English;
data[j+1].English = data[j].English;
data[j].English = temp_English;
}
}
}
// Output the sorted result
printf(" The result of sorting is as follows ( Chinese scores are ranked from high to low ):\n Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
for(int i=0;i<numbers;i++)
{
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",data[i].number,data[i].name,data[i].Chinese,data[i].maths,data[i].English);
}
}
All the code
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h> // according to C99 standard ,C Language use bool Type needs to add this header file
// Structure declaration part
typedef struct Student
{
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
struct Student *next; // Pointer to the next element
}stu,*stuList;
/*-------- Function declaration part --------*/
void MainMenu();// The main menu , Used for display
bool add_student(stu *L);// Add student records
void show_all(stu *L);// Show all student information
bool del_student(stu *L,int num);// Delete student information according to student number
bool search_num(stu *L,int num);// According to the student number
bool verify_num(stu *L,int num);// Query and modify the information according to the student number
bool sort_Chinese(stu *L);// Sort according to Chinese scores
bool InitList(stu *L);// Student list initialization
bool Empty(stu *L);// The linked list is empty
/*-------- Function declaration part --------*/
int main()
{
int ch;// Selected sequence number
int ch_num;// Query according to student number 、 Delete 、 Modification and other operations
stu L;
if(InitList(&L))
printf(" The linked list was initialized successfully !\n");// Prompt information , If not needed, delete , But you must initialize the linked list first !
else
printf(" Linked list initialization failed !\n");
while(1)
{
MainMenu();// Display main interface
printf("\n Please enter the sequence number of the operation you want to perform :");
scanf("%d",&ch);
switch(ch)
{
case 0: printf(" Thank you for using !"); exit(0); break;
case 1: add_student(&L); break;
case 2: printf(" Please enter the student number of the student you want to delete :");
scanf("%d",&ch_num);
if(del_student(&L,ch_num))
printf(" Delete successful !\n");
else
printf(" Delete failed , No such record !\n");
break;
case 3: printf(" Please enter the student number of the student you want to modify :");
scanf("%d",&ch_num);
if(verify_num(&L,ch_num))
printf(" Modification successful !\n");
else
printf(" Modification failed , No such record !\n");
break;
case 4:
printf(" Please enter the student number you want to query :");
scanf("%d",&ch_num);
if(search_num(&L,ch_num))
printf(" The query is successful !\n");
else
printf(" The query fails , No such record !\n");
break;
case 5:
sort_Chinese(&L); break;
case 6: show_all(&L); break;
default: printf(" The operation sequence number you entered is incorrect , Please re-enter !\n");
}
}
return 0;
}
// The main menu , Show
void MainMenu()
{
printf("\n\n\n");
printf("\t ********** Student achievement management system ***********\n");
printf("\t ------- 0. Exit the system \n\n");
printf("\t ------- 1. Enter student scores \n\n");
printf("\t ------- 2. Delete record \n\n");
printf("\t ------- 3. Modify student information \n\n");
printf("\t ------- 4. Search for student information \n\n");
printf("\t ------- 5. Sort by Chinese score \n\n");
printf("\t ------- 6. Show all student information \n\n");
printf("\t *************************************\n");
}
// Initialize single chain table ( Leading node )
bool InitList(stu *L)
{
L = (stu *)malloc(sizeof(stu)); // Assign a head node
if (L==NULL) // Out of memory , Allocation failed
return false;
L->next = NULL; // There is no node after the head node
return true;
}
// Add student
bool add_student(stu *L)
{
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
printf(" Please enter the following information in turn : Student number 、 full name 、 Chinese achievement 、 Math scores 、 English scores ( Press enter to enter the next item after each entry )\n");
scanf("%d",&number);
scanf("%s",name);
scanf("%d",&Chinese);
scanf("%d",&maths);
scanf("%d",&English);
// Apply for a new memory space
stu *p; // The pointer P Point to the currently scanned node
p = L; //L Point to the head node , The head node is the second node 0 Nodes ( No data )
stu *s = (stu *)malloc(sizeof(stu));
// Assign a value to the new node
s->number = number;
for(int i=0;i<sizeof(name);i++) // Array element assignment cannot make array equal to array directly
s->name[i] = name[i];
s->Chinese = Chinese;
s->maths = maths;
s->English = English;
//------------ The first interpolation ------------//
// The change of the pointer
// s->next = p->next;
// p->next = s;
//------------ The first interpolation ------------//
//------------ The tail interpolation ------------//
// notes : The tail interpolation method mainly includes this while loop , That is, first let the pointer point to the end of the linked list, and then insert
while(p->next!=NULL)
{
p = p->next;
}
s->next = p->next;
p->next = s;
//------------ The tail interpolation ------------//
return true;
}
// Show all information
void show_all(stu *L)
{
printf(" All student information is as follows :\n");
printf(" Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
stu *p;
p = L->next;
while(p!=NULL)
{
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
p = p->next;
}
}
// According to the student number
bool search_num(stu *L,int num)
{
stu *p;
p = L->next;
while(p!=NULL)
{
if(p->number == num)
{
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
return true;
}
p = p->next;
}
return false;
}
// Delete... According to student number
bool del_student(stu *L,int num)
{
stu *p;
p = L;// Give Way p Start from scratch
while(p->next!=NULL)
{
stu *q = p->next; // q Point to the deleted node
if(q->number == num) //p If you want to delete the next node data
{
printf(" The node data you deleted is :\n%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",q->number,q->name,q->Chinese,q->maths,q->English);
p->next = q->next;// Delete
free(q);
return true;
}
p = p->next;
}
return false;
}
// Query and modify the information according to the student number
bool verify_num(stu *L,int num)
{
stu *p;
p = L->next;
while(p!=NULL)
{
if(p->number == num)
{
printf(" The information you want to modify is :\n Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",p->number,p->name,p->Chinese,p->maths,p->English);
int number;// Student number
char name[10];// full name
int Chinese;// Chinese achievement
int maths;// Math scores
int English;// English scores
printf(" Please re-enter the following information : Student number 、 full name 、 Chinese achievement 、 Math scores 、 English scores ( Press enter to enter the next item after each entry )\n");
scanf("%d",&number);
scanf("%s",name);
scanf("%d",&Chinese);
scanf("%d",&maths);
scanf("%d",&English);
// Assign a value to this node
p->number = number;
for(int i=0;i<sizeof(name);i++) // Array element assignment cannot make array equal to array directly
p->name[i] = name[i];
p->Chinese = Chinese;
p->maths = maths;
p->English = English;
return true;
}
p = p->next;
}
return false;
}
// Sort according to Chinese scores
bool sort_Chinese(stu *L)
{
int numbers = 0;// Count the number of records first
stu *p;
p = L->next;
while(p!=NULL)
{
numbers++;
p = p->next;
}
printf(" A total of %d Student records !\n",numbers);
stu data[numbers]; // Put all the data into this array , Perform statistical operations on this array
p = L->next;// Give Way p Point back to the beginning
for(int i=0;i<numbers;i++)
{
if(p!=NULL)
{
data[i].number = p->number;
for(int j=0;j<sizeof(p->name);j++) // Array element assignment cannot make array equal to array directly
data[i].name[j] = p->name[j];
data[i].Chinese = p->Chinese;
data[i].maths = p->maths;
data[i].English = p->English;
p = p->next;
}
}
// printf(" After saving into the array :\n"); // You can check whether the saved results are correct
// for(int i=0;i<numbers;i++)
// {
// printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",data[i].number,data[i].name,data[i].Chinese,data[i].maths,data[i].English);
// }
int temp_num;// Temporary student number
char temp_name[10];
int temp_Chinese;
int temp_maths;
int temp_English;
// Sort according to Chinese scores
for(int i=0;i<numbers-1;i++)
{
for(int j=0;j<numbers-1-i;j++)
{
if(data[j].Chinese<data[j+1].Chinese)
{
// Exchange student numbers
temp_num = data[j+1].number;
data[j+1].number = data[j].number;
data[j].number = temp_num;
// Exchange names
for(int k=0;k<sizeof(data[0].name);k++) // Array element assignment cannot make array equal to array directly
{
temp_name[k] = data[j+1].name[k];
data[j+1].name[k] = data[j].name[k];
data[j].name[k] = temp_name[k];
}
// Exchange Chinese scores
temp_Chinese = data[j+1].Chinese;
data[j+1].Chinese = data[j].Chinese;
data[j].Chinese = temp_Chinese;
// Exchange math grades
temp_maths = data[j+1].maths;
data[j+1].maths = data[j].maths;
data[j].maths = temp_maths;
// Exchange English scores
temp_English = data[j+1].English;
data[j+1].English = data[j].English;
data[j].English = temp_English;
}
}
}
// Output the sorted result
printf(" The result of sorting is as follows ( Chinese scores are ranked from high to low ):\n Student number \t full name \t Chinese achievement \t Math scores \t English scores \t\n");
for(int i=0;i<numbers;i++)
{
printf("%-4d\t%s\t%-3d\t\t%-3d\t\t%-3d\n",data[i].number,data[i].name,data[i].Chinese,data[i].maths,data[i].English);
}
}
System function test





边栏推荐
- [resolved] MySQL exception: error 1045 (28000): unknown error 1045, forgetting the initial password
- 我今年毕业,但我不知道我要做什么
- Base64 encoding method implemented by native JS
- 【已解决】Failed! Error: Unknown error 1130
- Write and run the first go language program
- RT thread kernel application development message queue experiment
- SQL Server2005中SUM函数内嵌套IF语句
- Detailed methods for copying local computer files to virtual machine system
- Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
- 線程池——C語言
猜你喜欢
随机推荐
The simulation interface does not declare an exception and throws an exception
网络安全-路由原理
Qstring to const char*
Develop common dependency Libraries
Dynamic memory management
LabVIEW程序代码更新缓慢
网络安全-ARP协议和防御
Lt268 the most convenient TFT-LCD serial port screen chip in the whole network
QT signal slot alarm QObject:: connect:cannot connect (null)
grep命令用法
[resolved] MySQL exception: error 1045 (28000): unknown error 1045, forgetting the initial password
【已解决】Failed! Error: Unknown error 1130
嵌入式测试流程
Double click the idea to solve the problem of downloading again
【最全】linux服务器上安装Mysql
2021-07-02
B站首个UP主付费观看视频还是来了!价格“劝退”网友
03 - programming framework: Division of application layer, middle layer and driver layer in bare metal programming
神经网络计算量及参数量
Stm32g0 porting FreeRTOS







