当前位置:网站首页>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;
}
边栏推荐
- VLAN part of switching technology
- Custom type: structure, enumeration, union
- DDL statement of MySQL Foundation
- Batch distribution of SSH keys and batch execution of ansible
- Machine learning -- neural network (IV): BP neural network
- Leetcode48. Rotate image
- PHP代码审计3—系统重装漏洞
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- Architecture introduction
- leetcode1-3
猜你喜欢
【OpenCV 例程200篇】218. 多行倾斜文字水印
Reasons and solutions for the 8-hour difference in mongodb data date display
Basic data types of MySQL
转载:等比数列的求和公式,及其推导过程
Remove linked list elements
IPv6 comprehensive experiment
Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
MySQL develops small mall management system
If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display
Online troubleshooting
随机推荐
Press the button wizard to learn how to fight monsters - identify the map, run the map, enter the gang and identify NPC
Occasional pit compiled by idea
Hands on deep learning (44) -- seq2seq principle and Implementation
Exercise 9-3 plane vector addition (15 points)
Some summaries of the third anniversary of joining Ping An in China
DML statement of MySQL Foundation
转载:等比数列的求和公式,及其推导过程
Use C to extract all text in PDF files (support.Net core)
View CSDN personal resource download details
Rhcsa - day 13
C language - stack
BGP ---- border gateway routing protocol ----- basic experiment
按键精灵跑商学习-商品数量、价格提醒、判断背包
If you don't know these four caching modes, dare you say you understand caching?
system design
Dos:disk operating system, including core startup program and command program
按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
Exercise 8-7 string sorting (20 points)
原生div具有编辑能力
Exercise 7-3 store the numbers in the array in reverse order (20 points)