当前位置:网站首页>C language small project - student achievement management system
C language small project - student achievement management system
2022-07-23 12:33:00 【xiq1212】
System interface and related requirements
1) System operation , Open the following interface . List the system help menu ( Command menu ), Prompt for commands .

2) You haven't entered your grades at the beginning , So enter the command L And I can't list my grades . Should prompt “ The grade sheet is empty ! Please use the command first T Enter student scores .”
Empathy , When inputting other grade processing commands, it will also be processed accordingly .
3) Enter the command T, call Type Sub function entry score .
The interface prompts you to enter the number of students
Input 3 prompt 3 Students 3 Course results , List the header of the transcript “ Student number Chinese language and literature mathematics English ”, Prompt student number :1
Input 1 Student No 3 Course results , Use space between , End of carriage return . Prompt student number :2
Input 2 Student No 3 Course results , Use space between , End of carriage return . Prompt student number :3
Input 3 Student No 3 Course results , Use space between , End of carriage return .Type End of subfunction call , return . Prompt for commands .
4) Enter the command L , call List Sub function output score table .List End of subfunction call , return . Prompt for commands .
5) Enter the command A , call Average The subfunction calculates the average score , Tips “ The average score has been calculated . Please use the command L see .” Average End of subfunction call , return . Prompt for commands .
Enter the command L , call List Sub function output score table .List End of subfunction call , return . Prompt for commands .
6) Enter the command P , call Sort The sub function sorts the student records from high to low according to the average score , Tips “ To complete the order . Please use the command L see .” Sort End of subfunction call , return . Prompt for commands .
Enter the command L , call List Sub function output score table .List End of subfunction call , return . Prompt for commands .
7) Enter the command S , call Search Sub function queries student grades , Tips “ Enter the student number to query ”.
Input 2 find 2 Student No. and output .Search End of subfunction call , return . Prompt for commands .
8) Enter the command C Execute the clear screen function statement system(“clear”);
Clear everything on the screen . Prompt for commands .

9) Enter the command H call Help The sub function displays the help menu .Help End of subfunction call , return . Prompt for commands .
10) Enter the command Q , Exit the system .
Be careful :
1) When outputting array elements , The student number should be handled separately , The output is an integer ( Namely reservation 0 Decimal place ). Empathy , When calculating grades, you should also put the number 1 Put aside the student number in the column , Only the second 2 After column . Achievement retention 1 Decimal place .
2) Number of students n Throughout , adopt n The value of determines whether the sub function of the current command can be called and executed . for example : When n=0 when , Note that the score has not been entered . And once you enter a command T, That is to call Type The sub function has entered the score , be n The value of is no longer 0. When n!=0 when , You can perform other performance operations , But you can no longer perform the operation of employment results . So when the command entered by the user cannot be executed , Prompt should be given .
Code
#include <stdio.h>
#include <stdlib.h>
//#include "hs.h"
struct student
{
int id;
float yw;
float sx;
float wy;
float pj;
};
void help(void);
int type(struct student *p);
void list(struct student *p,int n);
void average(struct student *p,int n);
void search (struct student *p);
void sort(struct student *p,int n);
int main(int argc, const char *argv[])
{
char ch;
struct student stu[32];
int n=0;
while(1)
{
printf(" Please enter a command = ");
//getchar();
scanf("%c",&ch);
putchar(10);
if(ch=='T')
{
n=type(stu);
}
else if(ch=='L')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
list(stu,n);
}
else if(ch=='A')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
average(stu,n);
printf(" The average score has been calculated , Please use the command L see !\n");
putchar(10);
}
}
else if(ch=='H')
help();
else if(ch=='C')
system("clear");
else if(ch=='S')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
search(stu);
putchar(10);
}
}
else if(ch=='P')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
sort(stu,n);
putchar(10);
}
}
else if(ch=='Q')
{
printf("Press any key to continue!\n");
return -1;
}
getchar();
}
return 0;
}
int type(struct student *p)
{
int n=0;
printf(" Please input the number of students :");
scanf("%d",&n);
printf(" Please enter the student's grades in three courses :\n");
printf(" Student number Chinese language and literature mathematics Foreign Languages \n");
for(int i=0;i<n;i++)
{
printf("%d ",i+1);
struct student stu[i];
scanf("%f %f %f",&(p+i)->yw,&(p+i)->sx,&(p+i)->wy);
}
return n;
}
void list(struct student *p,int n)
{
printf(" The students' grades are as follows :\n");
printf(" Student number Chinese language and literature mathematics Foreign Languages average \n");
for(int i=0;i<n;i++)
{
printf("%d ",i+1);
printf("%.1f %.1f %.1f %.1f",p->yw,p->sx,p->wy,p->pj);
p++;
putchar(10);
}
}
void average(struct student *p,int n)
{
for(int i=0;i<n;i++)
{
(p->pj)=((p->yw)+(p->sx)+(p->wy))/3;
p++;
}
}
void help(void)
{
printf("**********************************\n");
printf(" * Student achievement management system —— In the help menu * \n");
printf("**********************************\n");
printf(" * H = Show help menu * \n");
printf(" * T = Score entry * \n");
printf(" * A = Calculate the student average * \n");
printf(" * L = List the transcript * \n");
printf(" * P = Sort by GPA from high to low * \n");
printf(" * S = Inquire the student's grade by student number * \n");
printf(" * C = Clear the screen * \n");
printf(" * Q = Exit the system * \n");
printf("**********************************\n");
printf(" *Copyright(c) 2022.3.15 By liq* \n");
printf("**********************************\n");
}
void search(struct student *p)
{
int s=0;
printf(" Please enter the student number to be queried :");
scanf("%d",&s);
printf(" Student number Chinese language and literature mathematics Foreign Languages average \n");
printf("%d %.1f %.1f %.1f %.1f",s,(p+s-1)->yw,(p+s-1)->sx,(p+s-1)->wy,(p+s-1)->pj);
putchar(10);
}
void sort(struct student *p,int n)
{
struct student temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(p[j].pj<p[j+1].pj)
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
printf(" Sort complete , Please use the command L see !\n");
}
Be careful
If it needs to be written in separate documents .
Just take out the function part of the above code , Create two new files :fun.c、fun.h. among fun.c File is used to store the structure declaration and function part of the above code ( Add the corresponding header file ).fun.h Used to store structure declaration and function declaration ( Add the corresponding header file ).
Add the corresponding header file to the main function :#include “fun.h”( Double quotes , No <>).
When compiling, the main function and the newly created fun.c Compile files together , The operation is the same as before , use ./a.out Can run .
The details are shown in the following figure :
1. Create two new files ( The same name , Different suffixes ), Compile and run ( You need to compile multiple files at the same time ).
2.hs.c Store the structure declaration and the corresponding function ( The functions in this can also be split into other files , I won't split it here ).
#include <stdio.h>
#include <stdlib.h>
struct student
{
int id;
float yw;
float sx;
float wy;
float pj;
};
int type(struct student *p)
{
int n=0;
printf(" Please input the number of students :");
scanf("%d",&n);
putchar(10);
printf(" Please enter the student's grades in three courses :\n");
putchar(10);
printf(" Student number Chinese language and literature mathematics Foreign Languages \n");
for(int i=0;i<n;i++)
{
printf("%d ",i+1);
struct student stu[i];
scanf("%f %f %f",&(p+i)->yw,&(p+i)->sx,&(p+i)->wy);
}
putchar(10);
return n;
}
void list(struct student *p,int n)
{
printf(" The students' grades are as follows :\n");
printf(" Student number Chinese language and literature mathematics Foreign Languages average \n");
for(int i=0;i<n;i++)
{
printf("%d ",i+1);
printf("%.1f %.1f %.1f %.1f",p->yw,p->sx,p->wy,p->pj);
p++;
putchar(10);
}
putchar(10);
}
void average(struct student *p,int n)
{
for(int i=0;i<n;i++)
{
(p->pj)=((p->yw)+(p->sx)+(p->wy))/3;
p++;
}
}
void help(void)
{
printf("**********************************\n");
printf(" * Student achievement management system —— In the help menu * \n");
printf("**********************************\n");
printf(" * H = Show help menu * \n");
printf(" * T = Score entry * \n");
printf(" * A = Calculate the student average * \n");
printf(" * L = List the transcript * \n");
printf(" * P = Sort by GPA from high to low * \n");
printf(" * S = Inquire the student's grade by student number * \n");
printf(" * C = Clear the screen * \n");
printf(" * Q = Exit the system * \n");
printf("**********************************\n");
printf(" *Copyright(c) 2022.3.15 By liq* \n");
printf("**********************************\n");
}
void search(struct student *p)
{
int s=0;
printf(" Please enter the student number to be queried :");
scanf("%d",&s);
putchar(10);
printf(" Student number Chinese language and literature mathematics Foreign Languages average \n");
printf("%d %.1f %.1f %.1f %.1f",s,(p+s-1)->yw,(p+s-1)->sx,(p+s-1)->wy,(p+s-1)->pj);
putchar(10);
}
void sort(struct student *p,int n)
{
struct student temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(p[j].pj<p[j+1].pj)
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
printf(" Sort complete , Please use the command L see !\n");
}
3.hs.h Storage structure declaration and hs.c The function declaration corresponding to the function inside .
#include <stdio.h>
#include <stdlib.h>
struct student
{
int id;
float yw;
float sx;
float wy;
float pj;
};
int type(struct student *p);
void list(struct student *p,int n);
void average(struct student *p,int n);
void help(void);
void search(struct student *p);
void sort(struct student *p,int n);
4.main function
#include <stdio.h>
#include <stdlib.h>
#include "hs.h"
int main(int argc, const char *argv[])
{
char ch;
struct student stu[32];
int n=0;
while(1)
{
printf(" Please enter a command = ");
scanf("%c",&ch);
putchar(10);
if(ch=='T')
{
n=type(stu);
}
else if(ch=='L')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
list(stu,n);
}
else if(ch=='A')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
average(stu,n);
printf(" The average score has been calculated , Please use the command L see !\n");
putchar(10);
}
}
else if(ch=='H')
help();
else if(ch=='C')
system("clear");
else if(ch=='S')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
search(stu);
putchar(10);
}
}
else if(ch=='P')
{
if(n==0)
{
printf(" The grade sheet is empty ! Please use first. T Enter the score !\n");
putchar(10);
}
else
{
sort(stu,n);
putchar(10);
}
}
else if(ch=='Q')
{
printf("Press any key to continue!\n");
return -1;
}
getchar();
}
return 0;
}
边栏推荐
- 3.2daydayup举一反三:三天打鱼两天晒网式学习
- Importance of data analysis
- Interpretation of the paper: develop a prediction model based on multi-layer deep learning to identify DNA N4 methylcytosine modification
- 《高分子合成工艺》简答题答案
- 博客搭建三:评论系统选择
- Analysis of 100 questions and answers in Higher Algebra
- Analyze the pre integration of vio with less rigorous but logical mathematical theory
- 5.4 Pyinstaller库安装与使用
- [AUTOSAR cantp 1. learn the network layer protocol of UDS diagnosis]
- 高分子物理考研概念及要点、考点总结
猜你喜欢

Data analysis of time series (II): Calculation of data trend
![[physical layer of CAN bus] 1. Content sharing of can/canfd sampling points](/img/e4/0b709a6ed5e639a75e0506f6eac9fd.png)
[physical layer of CAN bus] 1. Content sharing of can/canfd sampling points

输入三角形边长,求面积

单片机学习笔记9--串口通信(基于百问网STM32F103系列教程)

Use pyod to detect outliers

单片机学习笔记8--按键和外部中断(基于百问网STM32F103系列教程)

高等代数知识结构

Review of basic principles of steel structure

博客搭建四:将自己的博客加入百度和谷歌收录的方法

Data analysis of time series (III): decomposition of classical time series
随机推荐
嵌入式从入门到精通(入土)——超详细知识点分享1
Tencent cloud client command line tool tccli main process analysis
《高分子合成工艺》简答题答案
【分清楚常量指针与指针常量 Const int *与Int * Const的含义与用法】
单片机学习笔记8--按键和外部中断(基于百问网STM32F103系列教程)
高电压技术考题附答案
Data analysis (II)
钢结构基本原理试题及答案
博客搭建四:将自己的博客加入百度和谷歌收录的方法
输入三角形边长,求面积
[AUTOSAR com 3. signal sending and receiving process tx/rx]
钢结构基本原理复习
How to develop the liquid cooled GPU server in the data center under the "east to West calculation"?
Interpretation of the paper: "i4mc deep: intelligent prediction of N4 methylcytosine sites using deep learning methods with chemical properties"
Data analysis of time series (III): decomposition of classical time series
Uni native plug-in development -- Youmeng one click login
switch实现表达式计算
ARM架构与编程3--按键控制LED(基于百问网ARM架构与编程教程视频)
Interpretation of the paper: develop a prediction model based on multi-layer deep learning to identify DNA N4 methylcytosine modification
(1)ASIO