高校学科竞赛管理系统设计C语言代码实现学生功能,学生有注册信息,查询竞赛信息,申报等功能
时间: 2023-12-06 08:05:30 浏览: 33
以下是一个简单的高校学科竞赛管理系统的学生功能的C语言代码实现:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
struct student {
char name[50]; // 学生姓名
char id[20]; // 学生学号
char major[50]; // 学生专业
char password[20]; // 学生密码
};
// 定义竞赛信息结构体
struct competition {
char name[50]; // 竞赛名称
char date[20]; // 竞赛时间
char organizer[50]; // 竞赛主办方
char prize[50]; // 竞赛奖项
};
// 定义学生申报竞赛结构体
struct declaration {
char student_id[20]; // 学生学号
char competition_name[50]; // 竞赛名称
};
// 定义学生数组
struct student students[100];
int students_count = 0;
// 定义竞赛信息数组
struct competition competitions[100];
int competitions_count = 0;
// 定义学生申报竞赛数组
struct declaration declarations[100];
int declarations_count = 0;
// 学生注册函数
void register_student() {
struct student s;
printf("请输入学生姓名:");
scanf("%s", s.name);
printf("请输入学生学号:");
scanf("%s", s.id);
printf("请输入学生专业:");
scanf("%s", s.major);
printf("请输入学生密码:");
scanf("%s", s.password);
students[students_count++] = s;
printf("注册成功!\n");
}
// 学生登录函数
int login_student(char *id, char *password) {
for (int i = 0; i < students_count; i++) {
if (strcmp(students[i].id, id) == 0 && strcmp(students[i].password, password) == 0) {
return i;
}
}
return -1;
}
// 学生查询竞赛信息函数
void query_competitions() {
printf("竞赛名称\t竞赛时间\t竞赛主办方\t竞赛奖项\n");
for (int i = 0; i < competitions_count; i++) {
printf("%s\t%s\t%s\t%s\n", competitions[i].name, competitions[i].date, competitions[i].organizer, competitions[i].prize);
}
}
// 学生申报竞赛函数
void declare_competition(char *id) {
struct declaration d;
strcpy(d.student_id, id);
printf("请输入要申报的竞赛名称:");
scanf("%s", d.competition_name);
declarations[declarations_count++] = d;
printf("申报成功!\n");
}
// 主函数
int main() {
while (1) {
printf("请选择功能:\n");
printf("1. 学生注册\n");
printf("2. 学生登录\n");
printf("3. 查询竞赛信息\n");
printf("4. 学生申报竞赛\n");
printf("0. 退出系统\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
register_student();
break;
case 2: {
char id[20];
char password[20];
printf("请输入学号:");
scanf("%s", id);
printf("请输入密码:");
scanf("%s", password);
int index = login_student(id, password);
if (index == -1) {
printf("登录失败!\n");
} else {
while (1) {
printf("请选择功能:\n");
printf("1. 查询竞赛信息\n");
printf("2. 申报竞赛\n");
printf("0. 返回上级菜单\n");
int choice2;
scanf("%d", &choice2);
switch (choice2) {
case 1:
query_competitions();
break;
case 2:
declare_competition(id);
break;
case 0:
goto END;
break;
default:
printf("无效的选择!\n");
break;
}
}
END:;
}
break;
}
case 3:
query_competitions();
break;
case 4:
printf("请先登录!\n");
break;
case 0:
printf("谢谢使用!\n");
exit(0);
default:
printf("无效的选择!\n");
break;
}
}
return 0;
}
```
这个程序实现了学生注册、登录、查询竞赛信息和申报竞赛等功能。在程序中,我们使用了结构体来存储学生、竞赛信息和申报竞赛的数据,使用数组来存储多个学生、竞赛信息和申报竞赛的数据,并使用循环和switch语句来实现菜单功能。