|
|
@ -10,12 +10,14 @@ typedef struct {
|
|
|
|
float gaoshu;
|
|
|
|
float gaoshu;
|
|
|
|
float wuli;
|
|
|
|
float wuli;
|
|
|
|
float yingyu;
|
|
|
|
float yingyu;
|
|
|
|
|
|
|
|
int banji;
|
|
|
|
} Student;
|
|
|
|
} Student;
|
|
|
|
|
|
|
|
|
|
|
|
Student students[MAX_STUDENTS];
|
|
|
|
Student students[MAX_STUDENTS];
|
|
|
|
int studentCount = 0;
|
|
|
|
int studentCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void addStudent() {
|
|
|
|
void addStudent() {
|
|
|
|
|
|
|
|
char panduan;
|
|
|
|
printf("You are trying to Input info\n");
|
|
|
|
printf("You are trying to Input info\n");
|
|
|
|
if (studentCount >= MAX_STUDENTS) {
|
|
|
|
if (studentCount >= MAX_STUDENTS) {
|
|
|
|
printf("Cannot add more students. Maximum limit reached.\n");
|
|
|
|
printf("Cannot add more students. Maximum limit reached.\n");
|
|
|
@ -26,6 +28,8 @@ void addStudent() {
|
|
|
|
scanf("%d", &newStudent.id);
|
|
|
|
scanf("%d", &newStudent.id);
|
|
|
|
printf("Enter Name: ");
|
|
|
|
printf("Enter Name: ");
|
|
|
|
scanf("%s", newStudent.name);
|
|
|
|
scanf("%s", newStudent.name);
|
|
|
|
|
|
|
|
printf("Enter Class: ");
|
|
|
|
|
|
|
|
scanf("%d",&newStudent.banji);
|
|
|
|
printf("Enter 高数成绩: ");
|
|
|
|
printf("Enter 高数成绩: ");
|
|
|
|
scanf("%f", &newStudent.gaoshu);
|
|
|
|
scanf("%f", &newStudent.gaoshu);
|
|
|
|
printf("Enter 物理成绩: ");
|
|
|
|
printf("Enter 物理成绩: ");
|
|
|
@ -35,6 +39,8 @@ void addStudent() {
|
|
|
|
|
|
|
|
|
|
|
|
students[studentCount++] = newStudent;
|
|
|
|
students[studentCount++] = newStudent;
|
|
|
|
printf("Student added successfully!\n");
|
|
|
|
printf("Student added successfully!\n");
|
|
|
|
|
|
|
|
printf("continue?");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void deleteStudent() {
|
|
|
|
void deleteStudent() {
|
|
|
@ -57,16 +63,59 @@ void deleteStudent() {
|
|
|
|
printf("Student not found!\n");
|
|
|
|
printf("Student not found!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void displayStudents() {
|
|
|
|
void selectStudent(){
|
|
|
|
|
|
|
|
int xuan;
|
|
|
|
|
|
|
|
printf("Input Id or Class:");
|
|
|
|
|
|
|
|
scanf("%d",&xuan);
|
|
|
|
|
|
|
|
for (int i = 0; i < studentCount; i++) {
|
|
|
|
|
|
|
|
if(xuan==students[i].id||xuan==students[i].banji)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%d\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("continue?");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void orderStudents() {
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
Student temp;
|
|
|
|
|
|
|
|
for (i = 0; i < studentCount - 1; i++) {
|
|
|
|
|
|
|
|
for (j = i + 1; j < studentCount; j++) {
|
|
|
|
|
|
|
|
if (students[i].banji > students[j].banji) {
|
|
|
|
|
|
|
|
temp = students[i];
|
|
|
|
|
|
|
|
students[i] = students[j];
|
|
|
|
|
|
|
|
students[j] = temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (students[i].banji == students[j].banji) {
|
|
|
|
|
|
|
|
float totalScoreI = students[i].gaoshu + students[i].wuli + students[i].yingyu;
|
|
|
|
|
|
|
|
float totalScoreJ = students[j].gaoshu + students[j].wuli + students[j].yingyu;
|
|
|
|
|
|
|
|
if (totalScoreI < totalScoreJ) {
|
|
|
|
|
|
|
|
temp = students[i];
|
|
|
|
|
|
|
|
students[i] = students[j];
|
|
|
|
|
|
|
|
students[j] = temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("ID\tName\t班级\t高数成绩\t物理成绩\t英语成绩\t总成绩\n");
|
|
|
|
|
|
|
|
for (int i = 0; i < studentCount; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%d\t%s\t%d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void displayStudents()
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("You are trying to Make things ordered\n");
|
|
|
|
printf("You are trying to Make things ordered\n");
|
|
|
|
if (studentCount == 0) {
|
|
|
|
if (studentCount == 0) {
|
|
|
|
printf("No students to display.\n");
|
|
|
|
printf("No students to display.\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printf("ID\tName\t高数成绩\t物理成绩\t英语成绩\t总成绩\n");
|
|
|
|
printf("ID\tName\t班级\t高数成绩\t物理成绩\t英语成绩\t总成绩\n");
|
|
|
|
for (int i = 0; i < studentCount; i++) {
|
|
|
|
for (int i = 0; i < studentCount; i++)
|
|
|
|
printf("%d\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu);
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%d\t%s\t%d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -74,26 +123,58 @@ int main() {
|
|
|
|
int choice;
|
|
|
|
int choice;
|
|
|
|
int running = 1; // 控制循环的变量
|
|
|
|
int running = 1; // 控制循环的变量
|
|
|
|
|
|
|
|
|
|
|
|
while (running) { printf("输入1,2,3,4使用对应功能\n");
|
|
|
|
while (running) { printf("输入1,2,3,4, 5, 6使用对应功能\n");
|
|
|
|
printf(" 1. Input\n");
|
|
|
|
printf(" 1. Input\n");
|
|
|
|
printf(" 2. Output\n");
|
|
|
|
printf(" 2. Output\n");
|
|
|
|
printf(" 3. Order\n");
|
|
|
|
printf(" 3. select\n");
|
|
|
|
printf(" 4. Quit\n");
|
|
|
|
printf(" 4. order\n");
|
|
|
|
|
|
|
|
printf(" 5. output\n");
|
|
|
|
|
|
|
|
printf(" 6. Quit\n");
|
|
|
|
printf("Enter your choice: ");
|
|
|
|
printf("Enter your choice: ");
|
|
|
|
scanf("%d", &choice);
|
|
|
|
scanf("%d", &choice);
|
|
|
|
|
|
|
|
char panduan[3];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
switch (choice) {
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
addStudent();
|
|
|
|
addStudent();
|
|
|
|
|
|
|
|
loop:
|
|
|
|
|
|
|
|
scanf("%s",panduan);
|
|
|
|
|
|
|
|
if(strcmp(panduan,"yes")==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
addStudent();
|
|
|
|
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
deleteStudent();
|
|
|
|
deleteStudent();
|
|
|
|
|
|
|
|
scanf("%s",panduan);
|
|
|
|
|
|
|
|
if(strcmp(panduan,"yes")==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
deleteStudent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
displayStudents();
|
|
|
|
selectStudent();
|
|
|
|
|
|
|
|
loop3:
|
|
|
|
|
|
|
|
scanf("%s",panduan);
|
|
|
|
|
|
|
|
if(strcmp(panduan,"yes")==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
selectStudent();
|
|
|
|
|
|
|
|
goto loop3;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
running = 0; // 设置为0以退出循环
|
|
|
|
orderStudents();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
displayStudents();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
running = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
printf("Wrong input.\n");
|
|
|
|
printf("Wrong input.\n");
|
|
|
@ -102,3 +183,8 @@ int main() {
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|