ADD file via upload

main
pqzbgempc 2 days ago
parent c629c8c114
commit 6b8e6618d1

@ -0,0 +1,176 @@
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct
{
char id[20];
char mclass[20];
char name[20];
float score1, score2, score3;
} Student;
int numStudents=0; // ¼Ç¼µ±Ç°Ñ§ÉúµÄÊýÁ¿
Student students[MAX_STUDENTS];
void showMenu()
{
printf("%30s1.input\n", " ");
printf("%30s2.delete\n", " ");
printf("%30s3.select\n", " ");
printf("%30s4.order\n", " ");
printf("%30s5.output\n", " ");
printf("%30s6.quit\n", " ");
printf("%30splease input your option\n", " ");
}
void insertStudent()
{
printf("ID ");
scanf("%s", students[numStudents].id);
printf("class: ");
scanf("%s", &(students[numStudents].mclass));
printf("name: ");
scanf("%s", students[numStudents].name);
printf("score1: ");
scanf("%f", &(students[numStudents].score1));
printf("score2: ");
scanf("%f", &(students[numStudents].score2));
printf("score3: ");
scanf("%f", &(students[numStudents].score3));
numStudents++;
}
void deleteStudent()
{
char idOrName[20];
scanf("%s", idOrName);
int i, j;
int found = 0;
for (i = 0; i < numStudents; i++)
{
if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0)
{
found = 1;
for (j = i; j < numStudents - 1; j++)
{
students[j] = students[j + 1];
}
numStudents--;
break;
}
}
for ( i = 0; i < numStudents; i++)
{
printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3);
}
}
void selectStudent()
{
char idOrName[20];
scanf("%s", idOrName);
int i,j;
int f=0;
for (i = 0; i < numStudents; i++)
{
if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0)
{
f=1;
printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3);
}
}
if(f==0) printf("there is no eligible student\n");
}
void orderStudent()
{
int i,j;
for (i = 0; i < numStudents; i++)
{
for (j=i+1;j<numStudents;j++)
{
if (students[i].mclass > students[j].mclass || (students[i].mclass == students[j].mclass && students[i].score1 + students[i].score2 + students[i].score3 < students[j].score1 + students[j].score2 + students[j].score3))
{
Student temp = students[j];
students[j] = students[i];
students[i] = temp;
}
}
}
for ( i = 0; i < numStudents; i++)
{
printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3);
}
}
void printStudent()
{
int i=0;
for (i = 0; i < numStudents; i++)
{
printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3);
}
}
int main()
{
int choice;
char a[4];
while (1)
{
showMenu();
scanf("%d", &choice);
switch (choice)
{
case 1:
insertStudent();
while(1)
{
printf("continue?\n");
scanf("%s",&a);
if(strcmp(a,"yes")==0)
{
insertStudent();
continue;
}
else break;
}
break;
case 2:
deleteStudent();
while(1)
{
printf("continue?\n");
scanf("%s",&a);
if(strcmp(a,"yes")==0)
{
deleteStudent();
continue;
}
else break;
}
break;
case 3:
selectStudent();
while(1)
{
printf("continue?\n");
scanf("%s",&a);
if(strcmp(a,"yes")==0)
{
selectStudent();
continue;
}
else break;
}
break;
case 4:
orderStudent();
break;
case 5:
printStudent();
break;
case 6:
return 0;
}
//showMenu();
}
}
Loading…
Cancel
Save