You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
6.0 KiB

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
char id[20];
char clas[20];
char name[20];
double score1;
double score2;
double score3;
double score;
} Student;
Student students[1000];
int studentCount=0;
//<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
void inputStudentInfo( ) {
printf("Id ");
scanf("%s", students[studentCount].id);
printf("Class ");
scanf("%s", &students[studentCount].clas);
printf("Name ");
scanf("%s", students[studentCount].name);
printf("Score1 ");
scanf("%lf", &students[studentCount].score1);
printf("Score2 ");
scanf("%lf", &students[studentCount].score2);
printf("Score3 ");
scanf("%lf", &students[studentCount].score3);
// <20><><EFBFBD><EFBFBD><EFBFBD>ܳɼ<DCB3>
students[studentCount].score = students[studentCount].score1 +
students[studentCount].score2 +
students[studentCount].score3;
studentCount++;
}
//<2F><>ʾ<EFBFBD><CABE>Ϣ
void displayAllStudents() {
if (studentCount == 0) {
printf("No students to display.\n");
return;
}
int i;
for (i=0; i < studentCount; i++) {
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n",
students[i].id, students[i].clas, students[i].name,
students[i].score1, students[i].score2, students[i].score3,
students[i].score);
}
}
void sortByClassAndScore() {
if (studentCount <= 1) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return;
}
// ʹ<>ü򵥵<C3BC>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int i;
for ( i = 0; i < studentCount - 1; i++) {
int j;
for ( j = 0; j < studentCount - 1 - i; j++) {
if (atoi(students[j].clas) > atoi(students[j + 1].clas) ||
(atoi(students[j].clas)== atoi(students[j + 1].clas)&&
students[j].score < students[j + 1].score)) {
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
for (i = 0; i < studentCount; i++) {
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n",
students[i].id, students[i].clas, students[i].name,
students[i].score1, students[i].score2, students[i].score3,
students[i].score);
}
}
//ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ id or name
void deleteStudent() {
if (studentCount <= 1) {
printf("No students to delete.\n");
return;
}
char dele[20];
printf("Enter the ID of the student you want to delete: ");
scanf("%s", dele);
int i,j;
int found = 0;
for (i = 0; i < studentCount; i++) {
if ((strcmp(students[i].id, dele) == 0) || (strcmp(students[i].name, dele) == 0)) {
found = 1;
// ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>ǰ<EFBFBD>ƶ<EFBFBD>
for ( j = i; j < studentCount - 1; j++) {
students[j] = students[j + 1];
}
studentCount--;
for ( i = 0; i < studentCount; i++) {
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n",
students[i].id, students[i].clas, students[i].name,
students[i].score1, students[i].score2, students[i].score3,
students[i].score);
/* printf("Student with ID %s deleted.\n", studentId);*/
}
break;
}
}
if (!found) {
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n",
students[i].id, students[i].clas, students[i].name,
students[i].score1, students[i].score2, students[i].score3,
students[i].score);
/*printf("Student with ID %s not found.\n", studentId);*/
}
}
//<2F><>ѯ id or cla
void queryStudent()
{
if (studentCount == 0) {
printf("No students to query.\n");
return;
}
char quer[20];
printf("Enter the ID of the student you want to query: ");
scanf("%s", quer);
int i;
int found = 0;
for (i = 0; i < studentCount; i++) {
if (strcmp(students[i].id, quer) == 0||strcmp(students[i].clas,quer)==0) {
found = 1;
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n",
students[i].id, students[i].clas, students[i].name,
students[i].score1, students[i].score2, students[i].score3,
students[i].score);
}
}
if (!found) {
printf("there is no eligible student");
}
}
int main()
{
while (1) {
printf("1.input\n2.delete\n3.select\n4.order\n5.output\n6.quit\nplease input your option\n");
int option;
scanf("%d", &option);
switch(option){
case 1:{
while(1)
{
inputStudentInfo();
printf("continue?\n");
char ch[20];
scanf("%s", ch);
if (strcmp(ch, "yes") != 0) {
break; // <20><><EFBFBD><EFBFBD>no<6E><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
}
}
break;
}
case 2:{
while(1)
{
deleteStudent();
printf("continue?\n");
char ch[20];
scanf("%s", ch);
if (strcmp(ch, "yes") != 0) {
break; // <20><><EFBFBD><EFBFBD>no<6E><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
}
}
break;
}
case 3:{
while(1)
{
queryStudent();
printf("continue?\n");
char ch[20];
scanf("%s", ch);
if (strcmp(ch, "yes") != 0) {
break; // <20><><EFBFBD><EFBFBD>no<6E><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
}
}
break;
}
case 4:{
if(studentCount>=3)
{
sortByClassAndScore();
}
break;
}
case 5:{
displayAllStudents();
break;
}
case 6:
exit(0);
}
}
return 0;
}