用C语言写一个学生课表管理系统
时间: 2023-11-09 19:07:40 浏览: 67
好的,下面是一个简单的学生课表管理系统的C语言代码,供您参考:
```c
#include <stdio.h>
#include <string.h>
#define MAX_COURSES 10
#define MAX_NAME_LEN 50
struct course {
char name[MAX_NAME_LEN];
int credit;
};
struct student {
char name[MAX_NAME_LEN];
int id;
struct course courses[MAX_COURSES];
int num_courses;
};
void add_course(struct student *s) {
struct course c;
printf("请输入课程名称:");
scanf("%s", c.name);
printf("请输入课程学分:");
scanf("%d", &c.credit);
s->courses[s->num_courses++] = c;
printf("课程添加成功!\n");
}
void print_courses(struct student *s) {
int i;
printf("课程列表:\n");
for (i = 0; i < s->num_courses; i++) {
printf("%d. %s(%d学分)\n", i+1, s->courses[i].name, s->courses[i].credit);
}
}
void print_student(struct student *s) {
printf("学生姓名:%s\n", s->name);
printf("学生学号:%d\n", s->id);
print_courses(s);
}
int main() {
struct student s;
memset(&s, 0, sizeof(struct student));
printf("欢迎使用学生课表管理系统!\n");
printf("请输入学生姓名:");
scanf("%s", s.name);
printf("请输入学生学号:");
scanf("%d", &s.id);
while (1) {
int choice;
printf("请选择要进行的操作:\n");
printf("1. 添加课程\n");
printf("2. 查看课程列表\n");
printf("3. 查看学生信息\n");
printf("4. 退出系统\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_course(&s);
break;
case 2:
print_courses(&s);
break;
case 3:
print_student(&s);
break;
case 4:
printf("感谢使用学生课表管理系统!\n");
return 0;
default:
printf("输入错误,请重新输入!\n");
break;
}
}
}
```
这个学生课表管理系统可以让用户输入学生的姓名和学号,并提供了添加课程、查看课程列表和查看学生信息的功能。用户可以根据菜单进行选择。在这个代码中,我们使用了结构体来存储学生和课程的信息,使用了循环和switch语句来实现菜单功能。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)