当前位置:网站首页>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;
}
边栏推荐
- Rhcsa operation
- OSPF comprehensive experiment
- 转载:等比数列的求和公式,及其推导过程
- 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
- Hlk-w801wifi connection
- Use the data to tell you where is the most difficult province for the college entrance examination!
- Rhcsa12
- Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
- RHCE - day one
- 2021-08-11 function pointer
猜你喜欢
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
Software sharing: the best PDF document conversion tool and PDF Suite Enterprise version sharing | with sharing
Linked list operation can never change without its roots
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
How do microservices aggregate API documents? This wave of show~
From programmers to large-scale distributed architects, where are you (2)
Servlet基本原理与常见API方法的应用
Introduction to extensible system architecture
【Day1】 deep-learning-basics
随机推荐
A little feeling
Rhcsa day 9
Advanced technology management - how to design and follow up the performance of students at different levels
Servlet基本原理与常见API方法的应用
Use C to extract all text in PDF files (support.Net core)
转载:等比数列的求和公式,及其推导过程
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
Dynamic memory management
Legion is a network penetration tool
Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
Reprint: summation formula of proportional series and its derivation process
5g/4g wireless networking scheme for brand chain stores
Rhcsa learning practice
Use the data to tell you where is the most difficult province for the college entrance examination!
What is an excellent architect in my heart?
【Day2】 convolutional-neural-networks
Rhcsa operation
【Day2】 convolutional-neural-networks
183 sets of free resume templates to help everyone find a good job
Service developers publish services based on EDAs