用C++语言写一个演讲比赛管理系统
时间: 2023-12-27 22:51:03 浏览: 36
好的,以下是一个简单的演讲比赛管理系统的代码,包括添加选手、评委打分、计算分数等功能:
```c
#include <stdio.h>
#define MAX_PARTICIPANTS 50
#define MAX_JUDGES 10
struct participant {
char name[30];
float scores[MAX_JUDGES];
float total_score;
};
int num_participants = 0;
struct participant participants[MAX_PARTICIPANTS];
int num_judges = 0;
float weights[MAX_JUDGES];
void add_participant() {
struct participant p;
printf("Enter participant name: ");
scanf("%s", &p.name);
for (int i = 0; i < num_judges; i++) {
printf("Enter judge %d score: ", i+1);
scanf("%f", &p.scores[i]);
}
participants[num_participants] = p;
num_participants++;
}
void add_judge() {
float weight;
printf("Enter judge weight: ");
scanf("%f", &weight);
weights[num_judges] = weight;
num_judges++;
}
void calculate_scores() {
for (int i = 0; i < num_participants; i++) {
float total_score = 0;
for (int j = 0; j < num_judges; j++) {
total_score += participants[i].scores[j] * weights[j];
}
participants[i].total_score = total_score;
}
}
void display_scores() {
printf("Participant scores:\n");
for (int i = 0; i < num_participants; i++) {
printf("%s: %.2f\n", participants[i].name, participants[i].total_score);
}
}
int main() {
int option;
do {
printf("\n1. Add participant\n");
printf("2. Add judge\n");
printf("3. Calculate scores\n");
printf("4. Display scores\n");
printf("5. Exit\n");
printf("Enter option: ");
scanf("%d", &option);
switch(option) {
case 1: add_participant(); break;
case 2: add_judge(); break;
case 3: calculate_scores(); break;
case 4: display_scores(); break;
case 5: break;
default: printf("Invalid option\n");
}
} while (option != 5);
return 0;
}
```
注意,这只是一个简单的示例代码,实际的演讲比赛管理系统可能需要更多的功能和错误处理。