当前位置:网站首页>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;
}
边栏推荐
- RHCE - day one
- 7-17 crawling worms (15 points)
- Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
- Es entry series - 6 document relevance and sorting
- BGP advanced experiment
- Service developers publish services based on EDAs
- 今日睡眠质量记录78分
- Deep learning 500 questions
- Use the data to tell you where is the most difficult province for the college entrance examination!
- How to teach yourself to learn programming
猜你喜欢
DDL statement of MySQL Foundation
Introduction to extensible system architecture
Two way process republication + routing policy
Architecture introduction
Hands on deep learning (46) -- attention mechanism
Today's sleep quality record 78 points
Work order management system OTRs
DML statement of MySQL Foundation
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
Four characteristics and isolation levels of database transactions
随机推荐
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
leetcode842. Split the array into Fibonacci sequences
system design
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Rhcsa learning practice
Hands on deep learning (44) -- seq2seq principle and Implementation
Deep learning 500 questions
C language structure to realize simple address book
Evolution from monomer architecture to microservice architecture
DCL statement of MySQL Foundation
Native div has editing ability
Dos:disk operating system, including core startup program and command program
View CSDN personal resource download details
2021-08-10 character pointer
Collection of practical string functions
Talk about scalability
Work order management system OTRs
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
DML statement of MySQL Foundation
leetcode1-3