用c语言写一个学生综合测评系统
时间: 2023-10-10 22:07:42 浏览: 453
好的,下面是一个简单的学生综合测评系统的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT 100
struct Student {
int id;
char name[20];
int score1;
int score2;
int score3;
float average;
};
int main() {
struct Student students[MAX_STUDENT];
int num = 0;
int option;
while (1) {
printf("\n\n");
printf("1. Add student record\n");
printf("2. Delete student record\n");
printf("3. View student record\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &option);
switch (option) {
case 1:
if (num >= MAX_STUDENT) {
printf("Error: Maximum number of students exceeded.\n");
break;
}
printf("Enter student ID: ");
scanf("%d", &students[num].id);
printf("Enter student name: ");
scanf("%s", students[num].name);
printf("Enter score 1: ");
scanf("%d", &students[num].score1);
printf("Enter score 2: ");
scanf("%d", &students[num].score2);
printf("Enter score 3: ");
scanf("%d", &students[num].score3);
students[num].average = (students[num].score1 + students[num].score2 + students[num].score3) / 3.0;
num++;
break;
case 2:
if (num == 0) {
printf("Error: No students in the system.\n");
break;
}
int delete_id;
printf("Enter student ID to be deleted: ");
scanf("%d", &delete_id);
int delete_index = -1;
for (int i = 0; i < num; i++) {
if (students[i].id == delete_id) {
delete_index = i;
break;
}
}
if (delete_index == -1) {
printf("Error: Student with ID %d not found.\n", delete_id);
break;
}
for (int i = delete_index; i < num - 1; i++) {
students[i] = students[i + 1];
}
num--;
printf("Student with ID %d deleted successfully.\n", delete_id);
break;
case 3:
if (num == 0) {
printf("Error: No students in the system.\n");
break;
}
printf("ID\tName\tScore 1\tScore 2\tScore 3\tAverage\n");
for (int i = 0; i < num; i++) {
printf("%d\t%s\t%d\t%d\t%d\t%.2f\n", students[i].id, students[i].name, students[i].score1, students[i].score2, students[i].score3, students[i].average);
}
break;
case 4:
printf("Goodbye!\n");
exit(0);
default:
printf("Error: Invalid option selected.\n");
}
}
return 0;
}
```
这个程序使用了一个结构体 `Student` 来存储学生的信息,包括学生ID、姓名、三门科目的成绩以及平均分。通过一个循环菜单,用户可以选择添加学生记录、删除学生记录、查看学生记录或退出程序。在每个选项中,程序都会有相应的输入和输出操作。
阅读全文