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