帮我用C++写一个成绩管理系统
时间: 2023-05-25 13:03:54 浏览: 93
抱歉,作为AI语言模型,我无法为您编写完整的软件程序,但我可以提供以下伪代码作为参考:
#include <stdio.h>
#define SIZE 50 // 定义最大存储数量
struct Student { // 定义学生结构体
char name[20];
int id;
float score;
};
void addStudent(struct Student* students, int* count) { // 添加学生信息
printf("请输入学生姓名、学号、成绩(用空格分隔):");
scanf("%s %d %f", &students[*count].name, &students[*count].id, &students[*count].score);
(*count)++; // 增加学生数量
}
void showStudents(struct Student* students, int count) { // 显示学生信息
printf("学生姓名\t学号\t成绩\n");
for (int i = 0; i < count; i++) {
printf("%s\t\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score);
}
}
float calculateAverageScore(struct Student* students, int count) { // 计算平均成绩
float sum = 0;
for (int i = 0; i < count; i++) {
sum += students[i].score;
}
return sum / count;
}
void showMenu() { // 显示菜单
printf("\n");
printf("******************\n");
printf(" 成绩管理系统\n");
printf("******************\n");
printf("1. 添加学生信息\n");
printf("2. 显示学生信息\n");
printf("3. 计算平均成绩\n");
printf("4. 退出\n");
printf("请选择操作:");
}
int main() {
struct Student students[SIZE]; // 存储学生信息
int choice = 0, count = 0;
while (1) {
showMenu();
scanf("%d", &choice);
switch (choice) {
case 1: addStudent(students, &count); break;
case 2: showStudents(students, count); break;
case 3: printf("平均成绩为:%.2f\n", calculateAverageScore(students, count)); break;
case 4: return 0;
default: printf("输入有误,请重新选择操作!\n");
}
}
return 0;
}
阅读全文