当前位置:网站首页>Student achievement management system (C language)
Student achievement management system (C language)
2022-07-04 10:27:00 【Lol only plays Timo】
This code and for reference , Can be used to cope with the school C The language course is set up , Structure array and file are used , There is no linked list , Just a relatively simple version .
If you need to modify or use the source code, take it away by yourself , It's rubbish , You'd better have a look .
There are few notes , For reference only !
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>
typedef struct stuInformation {
char name[20];
char sex[3];
char stuId[10];
int cScore;
}M;
M list[200]={
0};
int count=0;
void showmenu(); // Show menu bar
void showHead(); // Show the head of the list
void showStudentInformtion(); // Show the information of all students
void searchOneStudent(); // Find the information of a student by student name
void insertStudentInformation(); // Insert a student's information in the list ( Insert left )
void addInformation(); // Add student information
void deleteStudentInformation(); // Delete a student's information through the student's name
void changeStudentInformation(); // Change the information of a student
void rankScore(); // Sort students according to their grades
void readFILE(); // Read file data
void saveFILE(); // Save file data
void saveFILE() {
FILE *fp;
int index;
fp = fopen("infor.txt","w+");
if(fp == NULL) {
printf(" Error opening file !\n");
getchar();
exit(0);
}
fwrite(&count,sizeof(int),1,fp);
fwrite(list,sizeof(M),count,fp);
fclose(fp);
return;
}
void readFILE() {
FILE *fp;
int n=0;
fp = fopen("infor.txt","a+");
int index;
if(fp == NULL) {
printf(" Error opening file !\n");
getchar();
exit(0);
}
n=fread(&count,sizeof(int),1,fp);
if(n==0) {
count=0;
return;
}else{
fread(list,sizeof(M),count,fp);
}
fclose(fp);
return;
}
void showmenu() {
system("cls");
printf("*----------------------------------------------------*\n");
printf("* Welcome to use C Language achievement management system *\n");
printf("*----------------------------------------------------*\n");
printf("* 1: entry ( add to ) achievement *\n");
printf("* 2: Delete grades *\n");
printf("* 3: Revise grades *\n");
printf("* 4: Score inquiry *\n");
printf("* 5: Insert grade *\n");
printf("* 6: Score calculation and ranking *\n");
printf("* 7: Show grade information *\n");
printf("* 0: Save the information and exit the system *\n");
printf("*----------------------------------------------------*\n");
printf(" Select operation <0-7> \n");
return;
}
void showHead() {
printf("%-14s%-14s%-14s%-14s\n"," full name ",
" Gender ",
" Student number ",
"C language achievement " );
return;
}
void addInformation() {
int index;
int plus=0;
readFILE();
printf(" Please enter the number of students to be entered :");
scanf("%d",&plus);
showHead();
for(index = count;index < count+plus;index++) {
scanf("%s%s%s%d",list[index].name,list[index].sex,list[index].stuId,&list[index].cScore);
}
count=count+plus;
getchar();
printf(" Input succeeded !\n");
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
void showStudentInformtion() {
int index;
readFILE();
printf(" Student information is as follows :\n");
showHead();
for(index = 0;index < count;index++) {
printf("%-14s%-14s%-14s%-14d\n",list[index].name,list[index].sex,list[index].stuId,list[index].cScore);
}
getchar();
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
void searchOneStudent() {
int index;
int choiceNum;
int flag = 0;
char searchName[20];
char searchStuId[10];
readFILE();
printf(" To search by name, please press 1, Please press 2:");
scanf("%d",&choiceNum);
switch(choiceNum) {
case 1:
printf(" Please enter the name of the query student :");
scanf("%s",searchName);
for(index = 0;index < count;index++) {
if(strcmp(list[index].name,searchName) == 0) {
flag = 1;
printf(" The query is successful , The student's information is as follows :\n");
showHead();
printf("%-14s%-14s%-14s%-14d\n",list[index].name,list[index].sex,list[index].stuId,list[index].cScore);
}
}
if(flag == 0) {
printf(" The query fails , The student information does not exist !\n");
}
getchar();
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
case 2:
printf(" Please enter the student number of the query student :");
scanf("%s",searchStuId);
for(index = 0;index < count;index++) {
if(strcmp(list[index].stuId,searchStuId) == 0) {
flag = 1;
printf(" The query is successful , The student's information is as follows :\n");
showHead();
printf("%-14s%-14s%-14s%-14d\n",list[index].name,list[index].sex,list[index].stuId,list[index].cScore);
}
}
if(flag == 0) {
printf(" The query fails , The student information does not exist !\n");
}
getchar();
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
}
void insertStudentInformation() {
int index;
int insertNum;
M insertSTI;
readFILE();
printf(" Please enter the information of the student to be inserted :\n");
showHead();
scanf("%s%s%s%d",insertSTI.name,insertSTI.sex,insertSTI.stuId,&insertSTI.cScore);
printf(" Enter the position to insert ( Insert left ):\n");
scanf("%d",&insertNum);
insertNum--;
for(index = count;index > insertNum;index--) {
list[index] = list[index-1];
}
list[insertNum] =insertSTI;
count++;
getchar();
printf(" Insert the success !\n");
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
void deleteStudentInformation() {
char deleteName[20];
int index;
int flag = 0;
readFILE();
printf(" Please enter the name of the student to be deleted :\n");
do {
scanf("%s",deleteName);
for(index = 0;index < count;index++) {
if(strcmp(list[index].name,deleteName) == 0) {
flag = 1;
}
}
if(flag == 0) {
printf(" Input error , Please re-enter !\n");
}
if(flag == 1)
break;
}while(1);
for(index;index<count-1;index++) {
list[index] = list[index + 1];
}
count--;
getchar();
printf(" Delete successful !\n");
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
void rankScore() {
int index;
int i;
int j;
M temp;
readFILE();
for(i = 0;i < count;i++) {
for(j = 0;j < count - i - 1;j++) {
if(list[j].cScore < list[j + 1].cScore) {
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
getchar();
printf(" Sort success !\n");
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
void changeStudentInformation() {
char oldName[20];
int index;
M newInfo;
int flag = 0;
readFILE();
printf(" Please enter the name of the student to be modified :\n");
do {
scanf("%s",oldName);
for(index = 0;index < count;index++) {
if(strcmp(list[index].name,oldName) == 0) {
flag = 1;
}
}
if(flag == 0) {
printf(" Input error , Please re-enter !\n");
}
if(flag == 1)
break;
}while(1);
printf(" Please enter new student information :\n");
showHead();
scanf("%s%s%s%d",newInfo.name,newInfo.sex,newInfo.stuId,&newInfo.cScore);
for(index = 0;index < count;index++) {
if(strcmp(list[index].name,oldName) == 0) {
list[index] = newInfo;
}
}
getchar();
printf(" Modification successful !\n");
saveFILE();
printf(" Press any key to continue !\n");
getchar();
showmenu();
return;
}
int main() {
showmenu();
int flag;
do {
scanf("%d",&flag);
switch (flag) {
case 1:
addInformation();
break;
case 2:
deleteStudentInformation();
break;
case 3:
changeStudentInformation();
break;
case 4:
searchOneStudent();
break;
case 5:
insertStudentInformation();
break;
case 6:
rankScore();
break;
case 7:
showStudentInformtion();
break;
case 0:
saveFILE();
printf(" Saved successfully , Thank you for using. !\n");
break;
default:
printf(" Input error , Please re-enter !\n");
}
}while(flag != 0);
return 0;
}
边栏推荐
- From programmers to large-scale distributed architects, where are you (I)
- uniapp---初步使用websocket(长链接实现)
- Tables in the thesis of latex learning
- 原生div具有编辑能力
- Architecture introduction
- How to teach yourself to learn programming
- 5g/4g wireless networking scheme for brand chain stores
- Intelligent gateway helps improve industrial data acquisition and utilization
- Remove linked list elements
- Network disk installation
猜你喜欢
今日睡眠质量记录78分
The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
【Day1】 deep-learning-basics
Servlet基本原理与常见API方法的应用
Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
Basic data types of MySQL
用数据告诉你高考最难的省份是哪里!
RHCE day 3
随机推荐
OSPF comprehensive experiment
Histogram equalization
Sword finger offer 31 Stack push in and pop-up sequence
Devop basic command
How can Huawei online match improve the success rate of player matching
Static comprehensive experiment ---hcip1
对于程序员来说,伤害力度最大的话。。。
Exercise 9-1 time conversion (15 points)
Network disk installation
Application of safety monitoring in zhizhilu Denggan reservoir area
Ruby时间格式转换strftime毫秒匹配格式
Rhcsa day 9
Deep learning 500 questions
Exercise 7-3 store the numbers in the array in reverse order (20 points)
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
A little feeling
Exercise 8-10 output student grades (20 points)
Rhsca day 11 operation
AUTOSAR from getting started to mastering 100 lectures (106) - SOA in domain controllers
leetcode1-3