当前位置:网站首页>Student achievement management
Student achievement management
2022-04-23 03:12:00 【A happy wild pointer D】
1. Problem description
Build a 4 A student's information registration form , Each student's information includes : Student number , full name , and 3 Results of courses Python,C++,Java).
When the program runs, it displays a simple menu , for example :
(1): Information input (INPUT)
(2): Total score statistics (COUNT)
(3): Total score sorting (SORT)
(4): Inquire about (QUERY)
among :(1) Yes 4 Input the information of students
(2) For each student 3 Statistical total score of courses
(3) Yes 4 The total scores of students are sorted in descending order and displayed
(4) Query and enter a student number , Display information about the student
data structure :
struct student
{
int num; // Student number
char name[20]; // full name
int javascore; //java achievement
int cscore; //C++ Language
int pythonscore; //python achievement
struct student *next;
};
2. Outline design
This program contains 7 A function , Its function definition and function are :
(1)void menu(): Show menu .
(2)void input(stuNode* list): Get the student information entered by the user , Create a new node and insert it into the list .
(3)void count(stuNode* list): Traverse each data node of the linked list , Calculate the sum of the three grades and assign it to... In the data field of the node count Variable .
(4)void sort(stuNode* list): Use the selective sorting method to sort the linked list in descending order according to the total score . Find the node with the highest total score among the unordered nodes , Put it in the position of the first data node , Then continue to find the node with the highest total score from the remaining unordered nodes , Put it at the second data node , So circular , Until all nodes are sorted .
(5)void query(stuNode* list): User input student number , Query the student information corresponding to the student number and print it out ; If there is no student number in the linked list , It will prompt that the student does not exist .
(6)void delete(stuNode* list): Delete the student information of the specified student number .
(7)void show(stuNode* list): Show all student information .
3. Program realization
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
int num;// Student number
char name[20];// full name
int javascore;//java achievement
int cscore;//c++ Language
int pythonscore;//python achievement
int count;// Total score
struct student* next;// Point to the next student
};
typedef struct student stuNode;
// Information input
void input(stuNode* list)
{
// Request memory space for nodes
stuNode* stu = (stuNode*)malloc(sizeof(stuNode));
// Application failed
if (stu==NULL)
{
printf("\n Out of memory , Add failure !\n\n");
return ;
}
printf(" Student number :");
scanf("%d",&stu->num);
printf(" full name :");
scanf("%s",stu->name);
printf("Java achievement :");
scanf("%d",&stu->javascore);
printf("C++ achievement :");
scanf("%d",&stu->cscore);
printf("Python achievement :");
scanf("%d",&stu->pythonscore);
// Insert the new node into the head node
stu->next=list->next;
list->next=stu;
printf("\n Add success !\n\n");
}
// Total score statistics
void count(stuNode* list)
{
stuNode* p = list->next;
if(list==NULL||list->next==NULL)
{
printf("\n No student information , Unable to statistics !\n\n");
return ;
}
// Traverse the entire list , Calculate the total score of each student
while(p!=NULL)
{
int count = p->pythonscore+p->javascore+p->cscore;
p->count = count;
p=p->next;
}
}
// Total score sorting
void sort(stuNode* list)
{
stuNode *p,*q,temp;
// If the linked list is empty or has only the head node , It's out of order
if(list==NULL||list->next==NULL)
{
printf("\n No student information , Unable to sort !\n\n");
return ;
}
for(p=list->next;p->next!=NULL;p=p->next)
{
for (q=p->next;q!=NULL;q=q->next)
{
if (q->count>p->count)
{
// Exchange the values of two nodes
temp = *p;
*p=*q;
*q=temp;
temp.next=p->next;
p->next=q->next;
q->next=temp.next;
}
}
}
}
// Inquire about
void query(stuNode* list)
{
stuNode *p=list;
int num;
if(list==NULL||list->next==NULL)
{
printf("\n No student information , Can't query !\n\n");
return ;
}
printf(" Student number :");
scanf("%d",&num);
p=p->next;
while(p!=NULL)
{
if (p->num == num)
{
printf("\n Student number \t full name \t\tJava\tC++\tPython\t\t Total score \n");
printf("%d\t%-10s\t%d\t%d\t%d\t\t%d\n\n",p->num,p->name,p->javascore,p->cscore,p->pythonscore,p->count);
return ;
}
p=p->next;
}
printf("\n There is no information about the student !\n\n");
}
// Delete
void delete(stuNode* list)
{
stuNode *p,*q;
int num;
if(list==NULL||list->next==NULL)
{
printf("\n No student information , Cannot delete !\n\n");
return ;
}
printf(" Student number :");
scanf("%d",&num);
p=list;
while(p->next!=NULL)
{
// If you find it , Let the of the previous node first next Point to the successor node , Then release the current node
if (p->next->num == num)
{
q=p->next;
p->next = p->next->next;
free(q);
printf("\n Delete successful !\n\n");
return ;
}
p=p->next;
}
printf("\n There is no information about the student , Cannot delete !\n\n");
}
// Show all
void show(stuNode* list)
{
stuNode* p = list;
if (list==NULL || list->next==NULL)
{
printf("\n No student information !\n\n");
return ;
}
p=list->next;
printf(" Student number \t full name \t\tJava\tC++\tPython\t\t Total score \n");
while(p!=NULL)
{
printf("%d\t%-10s\t%d\t%d\t%d\t\t%d\n",p->num,p->name,p->javascore,p->cscore,p->pythonscore,p->count);
p=p->next;
}
printf("\n\n");
}
// menu
void menu()
{
printf("************ Student achievement management system *************\n");
printf("* 1: Add student information *\n");
printf("* 2: Total statistical score *\n");
printf("* 3: In descending order of total score *\n");
printf("* 4: Search student information by student number *\n");
printf("* 5: Delete student information *\n");
printf("* 6: Show all student information *\n");
printf("* 0: Exit procedure *\n");
printf("*****************************************\n\n");
}
int main()
{
int code;// Option code
char over = 'Y';// Continue to add student logo
// Initialize linked list
stuNode* list = (stuNode*)malloc(sizeof(stuNode));
if (list == NULL)
{
printf("\n Out of memory , Program error !\n");
return -1;
}
list->count=0;
list->next=NULL;
menu();
do{
printf(" Please enter the option code (0-6):");
scanf("%d",&code);
printf("\n");
switch(code)
{
case 0:
return 0;
case 1:
do{
input(list);
printf(" Continue to add ?(Y or N):");
getchar();
over=getchar();
printf("\n");
}while(over!='N');
break;
case 2:
count(list);
show(list);
break;
case 3:
sort(list);
show(list);
break;
case 4:
query(list);
break;
case 5:
delete(list);
break;
case 6:
show(list);
break;
default:
printf("\n Input error , Please re-enter !\n\n");
break;
}
}while(code!=0);
return 0;
}
4. Implementation interface
版权声明
本文为[A happy wild pointer D]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627538216.html
边栏推荐
- Simple example of using redis in PHP
- If the deep replication of objects is realized through C #?
- Use of slice grammar sugar in C #
- TP5 customization in extend directory succeeded and failed. Return information
- MySQL port is occupied when building xampp
- Use of metagroup object tuple in C
- Source Generator实战
- Laravel's own paging query
- Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
- Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
猜你喜欢
Impact of AOT and single file release on program performance
类似Jira的十大项目管理软件
Laravel8- use JWT
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
2022g2 boiler stoker examination question bank and online simulation examination
A set of combination boxing to create an idea eye protection scheme
Recursion - outputs continuously increasing numbers
ASP. Net 6 middleware series - execution sequence
一文了解全面静态代码分析
2022t elevator repair test simulation 100 questions and online simulation test
随机推荐
利用栈的回溯来解决“文件的最长绝对路径”问题
2022年做跨境电商五大技巧小分享
C语言实现通讯录----(静态版本)
一套组合拳,打造一款 IDEA 护眼方案
PID debugging of coding motor (speed loop | position loop | follow)
Load view Caton
Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
Tips in MATLAB
TP5 inherits base and uses the variables in base
Flink实时数仓项目—DWS层设计与实现
MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?
ASP.NET 6 中间件系列 - 执行顺序
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
Xamarin effect Chapter 22 recording effect
2022年P气瓶充装培训试题及模拟考试
.NET7之MiniAPI(特别篇):.NET7 Preview3
2022g2 boiler stoker examination question bank and online simulation examination
Laravel's own paging query
2022 P cylinder filling training test questions and simulation test