当前位置:网站首页>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;
}
边栏推荐
- 7-17 crawling worms (15 points)
- Use the data to tell you where is the most difficult province for the college entrance examination!
- C language - stack
- Hands on deep learning (44) -- seq2seq principle and Implementation
- What is an excellent architect in my heart?
- leetcode1229. Schedule the meeting
- Doris / Clickhouse / Hudi, a phased summary in June
- 【Day1】 deep-learning-basics
- 如果不知道這4種緩存模式,敢說懂緩存嗎?
- OSPF comprehensive experiment
猜你喜欢
Development guidance document of CMDB
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Reprint: summation formula of proportional series and its derivation process
RHCE - day one
Devop basic command
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Use the data to tell you where is the most difficult province for the college entrance examination!
PHP代码审计3—系统重装漏洞
Linked list operation can never change without its roots
Latex error: missing delimiter (. Inserted) {\xi \left( {p,{p_q}} \right)} \right|}}
随机推荐
Devop basic command
Talk about scalability
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
Basic data types of MySQL
Service developers publish services based on EDAs
Time complexity and space complexity
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
RHCE - day one
Sword finger offer 31 Stack push in and pop-up sequence
Basic principle of servlet and application of common API methods
What is devsecops? Definitions, processes, frameworks and best practices for 2022
今日睡眠质量记录78分
Summary of several job scheduling problems
Jianzhi offer 04 (implemented in C language)
Exercise 9-3 plane vector addition (15 points)
183 sets of free resume templates to help everyone find a good job
Check 15 developer tools of Alibaba
原生div具有编辑能力
DCL statement of MySQL Foundation