Student achievement management system based on C language
- 2020-06-01 10:36:28
- OfStack
In this paper, the example of C language to achieve student performance management system of the specific code, for your reference, the specific content is as follows
Here only paste code, specific introduction of ellipsis.
#include <stdio.h>
#include <io.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 200
struct student
{
char no[10]; // Student id
char name[50]; // The name
float score[3]; // score
float math;
float eng;
float phy;
};
struct data
{
int count; // The number of students in the current student array
struct student stu[MAX]; // Students array
}dd;
// Display main menu
void menu()
{
system("cls");// Clear the screen
printf("\n\n\n");
printf("\t\t\t *******************************\n");
printf("\t\t\t \n");
printf("\t\t\t Student grade management system \n");
printf("\t\t\t \n");
printf("\t\t\t [1] View all student information \n");
printf("\t\t\t [2] Enter student records \n");
printf("\t\t\t [3] Delete student records \n");
printf("\t\t\t [4] Revise student records \n");
printf("\t\t\t [5] Search student grades (student number) \n");
printf("\t\t\t [6] Search for student achievements (name) \n");
printf("\t\t\t [7] View grade ranking (student number) \n");
printf("\t\t\t [0] exit \n");
printf("\t\t\t \n");
}
// Wait for the user to press enter to return to the main menu
void to_menu()
{
char c1,c2;
printf("\n\n\n Press enter to return to the main menu ...");
scanf("%c%c",&c1,&c2);// The first 1 Absorb the last confirmation enter key
menu();
}
// statistics
void ren()
{
int A=0,B=0,C=0,D=0,E=0,s;
int i;
for(i=0;i<dd.count;i++)
{
s=(int)(dd.stu[i].math/10);
switch(s)
{
case 10:
case 9:
A++;
break;
case 8:
B++;
break;
case 7:
C++;
break;
case 6:
D++;
break;
default :
E++;
break;
}
}
printf(" The total number of: %d\n",dd.count);
printf(" Number of "excellent" applicants: %d\n",A);
printf(" Number of people who got "good" : %d\n",B);
printf(" Number of "medium" : %d\n",C);
printf(" Number of people who received a "pass" : %d\n",D);
printf(" Number of flunks: %d\n",E);
}
// View all student information
void view_data()
{
int i;
printf(" Student id \t The name \t mathematics \t English \t physical ");
printf("\n-------------------------------------------------------------------\n");
for(i=0;i<dd.count;i++)
printf("%s\t%s\t%-7.1f\t%-7.1f\t%-7.1f\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].math,dd.stu[i].eng,dd.stu[i].phy);
printf("\n-------------------------------------------------------------------\n");
ren();
}
// Saves the data from the struct array to a file
void save_data()
{
FILE *fp;// The file pointer
int i,k;
k = dd.count; // Actually, k There is no practical meaning in direct fwrite In the use of &dd.count That's it.
fp=fopen("D:\\data.txt","w");// File storage location: current folder
fwrite(&k,sizeof(int),1,fp);
for(i=0;i<dd.count;i++)
fwrite(&dd.stu[i],sizeof(struct student),1,fp);
fclose(fp);
}
// Enter student records
void add_data()
{
int b;
int k = dd.count;
while(k<MAX)
{
printf(" Please enter student id: "); scanf("%s",dd.stu[k].no);
printf(" Please enter student name: "); scanf("%s",dd.stu[k].name);
printf(" Please enter your math score: "); scanf("%f",&dd.stu[k].math);
printf(" Please enter your English score: "); scanf("%f",&dd.stu[k].eng);
printf(" Please enter your physics score: "); scanf("%f",&dd.stu[k].phy);
dd.count++; // You have to put it in advance 0 In the main function.
k = dd.count;
printf("\n\n Continue to add student information [1-yes 0-no]:");
scanf("%d",&b);
if(b==0) break;
}
save_data();
}
// Reads the data from the file into the struct array
void read_data()
{
FILE *fp;
int i,k;
k=0;
if((fp=fopen("D:\\data.txt","r"))==NULL) // If the file doesn't exist
{
dd.count = 0;
}
else
{
fread(&k,sizeof(int),1,fp);
dd.count = k;
for(i=0;i<k;i++)
{
fread(&dd.stu[i],sizeof(struct student),1,fp);
}
fclose(fp);
}
}
// Delete student records
void delete_data()
{
int i,k;
char no[10];
printf("\n Please enter the student's student number to delete :");
scanf("%s",no);
k = -1;
for(i=0;i<dd.count;i++)
{
if(strcmp(dd.stu[i].no,no)==0)
{
k = i;
break;
}
}
if(k==-1)
{
printf("\n\n The student was not found ( Student id -%s)!",no);
}
else
{
// You didn't write delete
for(i=k; i<dd.count-1; i++) // Move the following data forward 1 position
dd.stu[i] = dd.stu[i+1];
memset(&dd.stu[dd.count-1],0,sizeof(struct student)); // will dd.stu[dd.count-1] The data set 0
dd.count--;
save_data();
printf("\n\n Delete the student ( Student id -%s) Record of success !",no);
}
}
// Revise student records
void edit_data()
{
int i,k;
char no[10],name[50];
printf("\n Please enter the student's student number to modify :");
scanf("%s",no);
k=-1;
for(i=0;i<dd.count;i++)
{
if(strcmp(dd.stu[i].no,no)==0)
{
k=i;
break;
}
}
if(k==-1)
{
printf("\n\n The student was not found ( Student id -%s)!",no);
}
else
{
printf("\n Please enter the student data :");
printf("\n The name ");
printf("\n--------------------------------------------------------------------\n");
scanf("%s",name);
strcpy(dd.stu[k].name,name);
save_data();
printf("\n\n Revise student records ( Student id -%s) successful !",no);
}
}
// Search student grades (student number)
void query_data_no()
{
int i,k;
char no[10];
printf("\n Please enter the student's student number :");
scanf("%s",no);
k=-1;
for(i=0;i<dd.count;i++)
{
if(strcmp(dd.stu[i].no,no)==0)
{
printf("\n\n Student id \t The name \t mathematics \t English \t physical ");
printf("\n-----------------------------------------------------------------\n");
k=i;
printf("%s\t%s\t%-7.1f\t%-7.1f\t%-7.1f\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].math,dd.stu[i].eng,dd.stu[i].phy);
break; // Student id should be only 1 Yes, I found it 1 One represents nothing after that.
}
}
if(k==-1)
{
printf("\n\n The student was not found ( Student id -%s)!",no);
}
}
// Student results (name)
void query_data_name()
{
int i,k;
char name[10];
printf("\n Please enter the name of the student you want to inquire :");
scanf("%s",name);
k=-1;
for(i=0;i<dd.count;i++)
{
if(strcmp(dd.stu[i].name,name)==0)
{
printf("\n\n Student id \t The name \t mathematics \t English \t physical ");
printf("\n-----------------------------------------------------------------\n");
k=i;
printf("%s\t%s\t%-7.1f\t%-7.1f\t%-7.1f\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].math,dd.stu[i].eng,dd.stu[i].phy);
break;
}
}
if(k==-1)
{
printf("\n\n The student was not found ( The name -%s)!",name);
}
}
// Sorting (student number)
void sort_data_no(struct data Buff)
{
int i;
int j;
int k;
int h;
struct student temp;
FILE *fp;
if((fp=fopen("D:\\data.txt","w+"))==NULL)
{
printf("cannot open file!\n");
exit(0);
}
printf(" Please enter the subject to be inquired: 1- Mathematics, 2- English, 3- physical :");
scanf("%d",&k);
switch(k)
{
case 1:
for(i=0; i<Buff.count-1; i++)
for(j=i+1; j<Buff.count; j++)
if(Buff.stu[i].math > Buff.stu[j].math)
{
temp=Buff.stu[i];
Buff.stu[i]=Buff.stu[j];
Buff.stu[j]=temp;
}
printf(" ranking \t Student id \t The name \t mathematics \n");
for(i=0; i<Buff.count; i++)
printf("%d\t%s\t%s\t%-7.1f\n",i+1,Buff.stu[i].no,Buff.stu[i].name,Buff.stu[i].math);
break;
case 2:
for(i=0; i<Buff.count-1; i++)
for(j=i+1; j<Buff.count; j++)
if(Buff.stu[i].eng > Buff.stu[j].eng)
{
temp=Buff.stu[i];
Buff.stu[i]=Buff.stu[j];
Buff.stu[j]=temp;
}
printf(" ranking \t Student id \t The name \t English \n");
for(i=0; i<Buff.count; i++)
printf("%d\t%s\t%s\t%-7.1f\n",i+1,Buff.stu[i].no,Buff.stu[i].name,Buff.stu[i].eng);
break;
case 3:
for(i=0; i<Buff.count-1; i++)
for(j=i+1; j<Buff.count; j++)
if(Buff.stu[i].phy > Buff.stu[j].phy)
{
temp=Buff.stu[i];
Buff.stu[i]=Buff.stu[j];
Buff.stu[j]=temp;
}
printf(" ranking \t Student id \t The name \t physical \n");
for(i=0; i<Buff.count; i++)
printf("%d\t%s\t%s\t%-7.1f\n",i+1,Buff.stu[i].no,Buff.stu[i].name,Buff.stu[i].phy);
break;
default :
printf(" Input error !");
exit(0);
}
printf(" Please press any key to continue ....");
getch();
fclose(fp);
}
// The main function
int main(void)
{
int fun;
dd.count = 0;
read_data();
menu();
while(1)
{
printf(" Please enter the function number [0-7]:");// What's not needed here &fun .
scanf("%d",&fun);
switch(fun)
{
case 1: view_data();break; // View all student information
case 2: add_data(); break; // Enter student records
case 3: delete_data();break; // Delete student records
case 4: edit_data();break; // Revise student records
case 5: query_data_no();break; // Search student grades (student number)
case 6: query_data_name();break; // Search for student achievements (name)
case 7: sort_data_no(dd); break; // View grade ranking (student number) // I'm going to go straight to the structure dd Just send it over
case 0: break; // exit
}
if(fun==0) break;
to_menu();
}
return 0;
}
For more information, please refer to the topic "management system development".