学校运动会管理系统c语言
时间: 2023-06-20 12:06:23 浏览: 106
学校运动会管理系统是一个较为复杂的系统,需要涉及到多个模块,包括用户登录、报名管理、比赛分组、比赛成绩管理等。下面是一个简单的C语言程序框架,可以作为开发学校运动会管理系统的参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义运动员结构体
typedef struct {
char name[20];
int age;
char sex[10];
char event[20];
float score;
} Athlete;
// 定义用户结构体
typedef struct {
char username[20];
char password[20];
int type; // 1表示管理员,2表示运动员
} User;
// 全局变量
Athlete athletes[100]; // 最多可容纳100名运动员
int athleteCount = 0; // 已经报名的运动员数
User users[10]; // 最多可容纳10个用户
int userCount = 0; // 用户数
// 函数声明
void menu(); // 显示菜单
void login(); // 用户登录
void registerUser(); // 用户注册
void addAthlete(); // 添加运动员
void viewAthlete(); // 查看所有运动员信息
void groupAthlete(); // 进行比赛分组
void enterScore(); // 输入比赛成绩
void viewScore(); // 查看比赛成绩
int main() {
menu(); // 显示菜单
return 0;
}
void menu() {
int choice;
do {
printf("====================\n");
printf("1. 用户登录\n");
printf("2. 用户注册\n");
printf("3. 添加运动员\n");
printf("4. 查看所有运动员信息\n");
printf("5. 进行比赛分组\n");
printf("6. 输入比赛成绩\n");
printf("7. 查看比赛成绩\n");
printf("0. 退出\n");
printf("====================\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
login();
break;
case 2:
registerUser();
break;
case 3:
addAthlete();
break;
case 4:
viewAthlete();
break;
case 5:
groupAthlete();
break;
case 6:
enterScore();
break;
case 7:
viewScore();
break;
case 0:
printf("感谢使用,再见!\n");
break;
default:
printf("输入有误,请重新输入!\n");
break;
}
} while (choice != 0);
}
void login() {
char username[20];
char password[20];
printf("请输入用户名:");
scanf("%s", username);
printf("请输入密码:");
scanf("%s", password);
// 遍历用户列表,查找是否有匹配的用户
for (int i = 0; i < userCount; i++) {
if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) {
printf("登录成功!\n");
// 根据用户类型进行不同的操作
if (users[i].type == 1) {
printf("管理员操作...\n");
// 管理员操作
} else if (users[i].type == 2) {
printf("运动员操作...\n");
// 运动员操作
}
return;
}
}
printf("用户名或密码错误!\n");
}
void registerUser() {
// 判断用户数量是否已满
if (userCount >= 10) {
printf("用户数量已满,无法注册!\n");
return;
}
char username[20];
char password[20];
int type;
printf("请输入用户名:");
scanf("%s", username);
printf("请输入密码:");
scanf("%s", password);
printf("请选择用户类型(1表示管理员,2表示运动员):");
scanf("%d", &type);
// 检查用户名是否已经存在
for (int i = 0; i < userCount; i++) {
if (strcmp(users[i].username, username) == 0) {
printf("用户名已存在!\n");
return;
}
}
// 添加新用户
strcpy(users[userCount].username, username);
strcpy(users[userCount].password, password);
users[userCount].type = type;
userCount++;
printf("注册成功!\n");
}
void addAthlete() {
// 判断运动员数量是否已满
if (athleteCount >= 100) {
printf("运动员数量已满,无法添加!\n");
return;
}
char name[20];
int age;
char sex[10];
char event[20];
printf("请输入姓名:");
scanf("%s", name);
printf("请输入年龄:");
scanf("%d", &age);
printf("请输入性别:");
scanf("%s", sex);
printf("请输入参加项目:");
scanf("%s", event);
// 添加新运动员
strcpy(athletes[athleteCount].name, name);
athletes[athleteCount].age = age;
strcpy(athletes[athleteCount].sex, sex);
strcpy(athletes[athleteCount].event, event);
athleteCount++;
printf("添加成功!\n");
}
void viewAthlete() {
printf("姓名\t年龄\t性别\t参加项目\n");
printf("==================================\n");
for (int i = 0; i < athleteCount; i++) {
printf("%s\t%d\t%s\t%s\n", athletes[i].name, athletes[i].age, athletes[i].sex, athletes[i].event);
}
}
void groupAthlete() {
// 按照参加项目进行分组
// 省略具体实现
printf("分组成功!\n");
}
void enterScore() {
// 输入比赛成绩
// 省略具体实现
printf("输入成功!\n");
}
void viewScore() {
// 查看比赛成绩
// 省略具体实现
printf("查看成功!\n");
}
```
上述程序框架只是一个简单的示例,实际开发中还需要根据具体需求进行修改和完善。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)