#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
typedef struct student
{
char name[20];
long int id;
int score;
} STU;
STU stu1[100];
int main()
{
void List(); // Output list
void Input(STU stu[],int *n); // Enter student data
void Sumandave(STU stu[],int n); // Sum and average
void Hightolow(STU stu[],int n); // Score from big to small
void Smalltolarge(STU stu[],int n); // Student number from small to large
void Search(STU stu[],int n); // Find a student information
void Percentage(STU stu[],int n); // Number and percentage
void Outputinformation(STU stu[],int n); // Output all student information
int n=0;
while(1)
{
system("cls"); // Clear screen
List(); // Output list
char c=getch(); // Header file conio, When a character is pressed , Function auto read , No need to press enter .
switch(c)
{
case '1':
Input(&stu1,&n);
break;
case '2':
Sumandave(&stu1,n);
break;
case '3':
Hightolow(&stu1,n);
break;
case '4':
Smalltolarge(stu1,n);
break;
case '5':
Search(stu1,n);
break;
case '6':
Percentage(&stu1,n);
break;
case '7':
Outputinformation(&stu1,n);
break;
case '0':
exit(0);
break; //exit(0) Exit program
}
}
return 0;
}
// Output list
void List()
{
printf("*****************************************************************\t\t\t\n");
printf("*\t\t Welcome to the university student achievement management system ws edition \t\t*\n");
printf("*\t\t\t Please select a function \t\t\t\t*\n");
printf("*****************************************************************\t\t\t\n");
printf("*\t 1.Input record\t\t\t\t\t*\n");
printf("*\t 2.Caculate total and average socre of course\t\t*\n");
printf("*\t 3.Sort in descending older by score\t\t\t*\n");
printf("*\t 4.Sort in ascending older by number\t\t\t*\n");
printf("*\t 5.Search by number\t\t\t\t\t*\n");
printf("*\t 6.Statistic analysis\t\t\t\t\t*\n");
printf("*\t 7.List record\t\t\t\t\t\t*\n");
printf("*\t 0.Exit\t\t\t\t\t\t*\n");
printf("*****************************************************************\t\t\t\n");
}
// input n Student information
void Input(STU stu[],int *n) // take n address , Timely update the number of people , To update the data
{
int m;
static int i=0;
printf(" Please enter the number of students to enter :");
scanf("%d",&m);
for(; i<m+*n; i++)
{
printf(" Please enter student name :");
scanf("%s",stu[i].name);
printf(" Please enter student ID :");
scanf("%ld",&stu[i].id);
printf(" Please enter student score :");
scanf("%d",&stu[i].score);
printf("***********************\n");
}
*n+=m;
printf(" Student information entered successfully !!!\n");
system("pause");
}
// Calculate the total score and average score
void Sumandave(STU stu[],int n)
{
int i,sum=0;
float ave;
for(i=0; stu[i].score; i++)
{
sum+=stu[i].score;
}
ave=(float)sum/n;
printf("%d A classmate's sum:%d\n",i,sum);
printf("%d A classmate's ave:%.2f\n",i,ave);
system("pause");
}
// Scores are sorted from high to low
void Hightolow(STU stu[],int n)
{
char x[100];
int i,j;
long int t;
for(i=0; i<n-1; i++)
{
for(j=i; j<n; j++)
{
if(stu[i].score<stu[j].score)
{
t=stu[i].score;
stu[i].score=stu[j].score;
stu[j].score=t;
t=stu[i].id;
stu[i].id=stu[j].id;
stu[j].id=t;
strcpy(x,stu[i].name);
strcpy(stu[i].name,stu[j].name);
strcpy(stu[j].name,x);
}
}
}
printf("%d Students score from high to low :\n",n);
printf(" full name :");
for(int p=0; p<n; p++)
{
printf("%10s",stu[p].name);
}
printf("\n");
printf(" fraction :");
for(int p=0; p<n; p++)
{
printf("%10d",stu[p].score);
}
printf("\n");
printf(" Student number :");
for(int p=0; p<n; p++)
{
printf("%10ld",stu[p].id);
}
printf("\n");
system("pause");
}
// Student numbers are sorted from small to large
void Smalltolarge(STU stu[],int n)
{
char x[100];
int i,j;
long int t;
for(i=0; i<n-1; i++)
{
for(j=i; j<n; j++)
{
if(stu[i].id>stu[j].id)
{
t=stu[i].score;
stu[i].score=stu[j].score;
stu[j].score=t;
t=stu[i].id;
stu[i].id=stu[j].id;
stu[j].id=t;
strcpy(x,stu[i].name);
strcpy(stu[i].name,stu[j].name);
strcpy(stu[j].name,x);
}
}
}
printf("%d Students from low to high :\n",n);
printf(" full name :");
for(int p=0; p<n; p++)
{
printf("%10s",stu[p].name);
}
printf("\n");
printf(" fraction :");
for(int p=0; p<n; p++)
{
printf("%10d",stu[p].score);
}
printf("\n");
printf(" Student number :");
for(int p=0; p<n; p++)
{
printf("%10ld",stu[p].id);
}
printf("\n");
system("pause");
}
// Enter the student number, find the student, and output the corresponding information
void Search(STU stu[],int n)
{
int i;
long int p;
printf(" Please enter the student number to find :");
scanf("%ld",&p);
for(i=0; i<n; i++)
{
if(p==stu[i].id)
{
printf(" Name of the student :%s\n",stu[i].name);
printf(" Student number of the student :%d\n",stu[i].id);
printf(" The student's grades :%d",stu[i].score);
break;
}
}
if(i==n)
printf("Not found!\n");
printf("\n");
system("\npause");
}
// Percentage of people per level
void Percentage(STU stu[],int n)
{
int m;
static int a[5]= {0},i=0;
float b[i];
for(; i<n; i++) // Find the number of people at each level
{
m=stu[i].score;
m/=10;
switch(m) // Calculate the number of people at all levels
{
case 10:
case 9:
a[4]++;
break;
case 8:
a[3]++;
break;
case 7:
a[2]++;
break;
case 6:
a[1]++;
break;
default:
a[0]++;
break;
}
}
printf(" The total number is :%d people \n",n); // Percentage of people at all levels
printf(" The number of outstanding persons is %d people . Percentage :%.2f%%\n",a[4],(float)100*a[4]/n);
printf(" The number of good people is %d people . Percentage :%.2f%%\n",a[3],(float)100*a[3]/n);
printf(" The median number is %d people . Percentage :%.2f%%\n",a[2],(float)100*a[2]/n);
printf(" The number of qualified persons is %d people . Percentage :%.2f%%\n",a[1],(float)100*a[1]/n);
printf(" The number of failed students is %d people . Percentage :%.2f%%\n",a[0],(float)100*a[0]/n); //%% Hit %
system("pause");
}
// Output the student number and grade of each student
void Outputinformation(STU stu[],int n)
{
int i;
for(i=0; i<n; i++) // output n Student numbers and scores
{
printf("\n Student name :%s\n Student number :%ld\n fraction :%d\n****************",stu[i].name,stu[i].id,stu[i].score);
}
printf("\n");
system("pause");
}
Technology
Daily Recommendation