c语言校运动会管理系统,建立系统储存结构,录入运动会项目信息,修改项目信息,删除项目信息,计算每个项目的院排名,对所有项目统计每个院总成绩并排名
时间: 2024-01-18 21:03:03 浏览: 106
好的,这是一个比较复杂的问题。根据你的需求,我会给出一个简单的C语言校运动会管理系统的设计方案,供你参考。
首先,我们需要定义以下数据结构:
```c
#define MAX_NAME_LEN 50
#define MAX_TEAM_NUM 10
#define MAX_EVENT_NUM 20
// 队伍信息
typedef struct {
char name[MAX_NAME_LEN]; // 队名
int score; // 得分
} Team;
// 项目信息
typedef struct {
char name[MAX_NAME_LEN]; // 项目名
int team_num; // 参赛队伍数
Team teams[MAX_TEAM_NUM]; // 队伍信息
} Event;
// 运动会信息
typedef struct {
int event_num; // 项目数
Event events[MAX_EVENT_NUM];// 项目信息
} SportsMeeting;
```
然后,我们需要实现以下功能:
1. 录入运动会项目信息
```c
void add_event(SportsMeeting* sm, const char* name, int team_num, const char** team_names) {
if (sm->event_num >= MAX_EVENT_NUM) {
printf("Error: too many events\n");
return;
}
Event* event = &sm->events[sm->event_num++];
strncpy(event->name, name, MAX_NAME_LEN);
event->team_num = team_num;
for (int i = 0; i < team_num; i++) {
strncpy(event->teams[i].name, team_names[i], MAX_NAME_LEN);
event->teams[i].score = 0;
}
}
```
2. 修改项目信息
```c
void modify_event(SportsMeeting* sm, int event_idx, const char* name, int team_num, const char** team_names) {
if (event_idx < 0 || event_idx >= sm->event_num) {
printf("Error: invalid event index\n");
return;
}
Event* event = &sm->events[event_idx];
strncpy(event->name, name, MAX_NAME_LEN);
event->team_num = team_num;
for (int i = 0; i < team_num; i++) {
strncpy(event->teams[i].name, team_names[i], MAX_NAME_LEN);
}
}
```
3. 删除项目信息
```c
void remove_event(SportsMeeting* sm, int event_idx) {
if (event_idx < 0 || event_idx >= sm->event_num) {
printf("Error: invalid event index\n");
return;
}
for (int i = event_idx; i < sm->event_num - 1; i++) {
sm->events[i] = sm->events[i + 1];
}
sm->event_num--;
}
```
4. 计算每个项目的院排名
```c
void calc_rank(Event* event) {
int team_num = event->team_num;
Team* teams = event->teams;
for (int i = 0; i < team_num; i++) {
for (int j = i + 1; j < team_num; j++) {
if (teams[i].score < teams[j].score) {
Team temp = teams[i];
teams[i] = teams[j];
teams[j] = temp;
}
}
}
}
```
5. 对所有项目统计每个院总成绩并排名
```c
void print_sports_meeting_rank(const SportsMeeting* sm) {
int team_num = 0;
Team teams[MAX_TEAM_NUM];
memset(teams, 0, sizeof(teams));
for (int i = 0; i < sm->event_num; i++) {
const Event* event = &sm->events[i];
for (int j = 0; j < event->team_num; j++) {
const Team* team = &event->teams[j];
int k;
for (k = 0; k < team_num; k++) {
if (strcmp(teams[k].name, team->name) == 0) {
break;
}
}
if (k == team_num) {
strncpy(teams[team_num].name, team->name, MAX_NAME_LEN);
team_num++;
}
teams[k].score += team->score;
}
}
for (int i = 0; i < team_num; i++) {
for (int j = i + 1; j < team_num; j++) {
if (teams[i].score < teams[j].score) {
Team temp = teams[i];
teams[i] = teams[j];
teams[j] = temp;
}
}
}
printf("Rank\tName\tScore\n");
for (int i = 0; i < team_num; i++) {
printf("%d\t%s\t%d\n", i + 1, teams[i].name, teams[i].score);
}
}
```
以上就是这个简单的校运动会管理系统的设计方案,你可以根据需要进行修改和完善。
阅读全文