没有合适的资源?快使用搜索试试~ 我知道了~
首页C语言实现简单学生选课管理系统
资源详情
资源评论
资源推荐
C语言实现简单学生选课管理系统语言实现简单学生选课管理系统
主要为大家详细介绍了C语言实现简单学生选课管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C语言实现学生选课管理系统的具体代码,供大家参考,具体内容如下
这是我们大一C语言课程设计的最终作品,涉及文件读写操作、链表的一系列操作。
源代码由头文件all.h、主函数文件main.cpp以及功能函数文件student.cpp、manager.cpp、common.cpp组成。
涉及的文件读写操作需要先手动创建文件,文件路径可以在all.h的宏定义中更改
使用vs2017的c++编译器,兼容c语言,现贴上源代码和运行截图,供感兴趣的童鞋参考,水平有限还望多多包涵。
运行截图
all.h
#pragma once
#define MAXN 50
#define STU_F "C:\stu_cour_info_system\date\student.txt" //文件存放路径及文件名
#define COUR_F "C:\stu_cour_info_system\date\course.txt" //文件存放路径及文件名
#define MAN_F "C:\stu_cour_info_system\date\manager.txt" //文件存放路径及文件名
#define STU_F_BACKUP "C:\stu_cour_info_system\backup\student.txt" //备份文件存放路径及文件名
#define COUR_F_BACKUP "C:\stu_cour_info_system\backup\course.txt" //备份文件存放路径及文件名
#define MAN_F_BACKUP "C:\stu_cour_info_system\backup\manager.txt" //备份文件存放路径及文件名
struct student //学生信息结构体
{
char name[MAXN]; //姓名
char num[MAXN]; //学号
char sch_cla[20]; //学院和班级
double score_all = 0; //应选总学分
double score_sel = 0; //已选课总学分
char password[9]; //学生登陆密码,共8位
int course_sum; //选课总数
char course[50][MAXN]; //记录选课课程的编号
struct student *next; //链表指针
};
struct course //课程信息结构体
{
char num[MAXN]; //课程编号
char name[MAXN]; //课程名称
char nature[MAXN]; //课程性质
char term[MAXN]; //开课学期
double time_all; //总学时
double time_teach; //授课学时
double time_exp; //实验或上机学时
double score; //该课程学分
int stu_max; //能够容纳的学生总数
int stu_sum; //已经选课学生总数
char stu[100][MAXN]; //已经选课学生学号
struct course *next; //链表指针
};
/*通用函数*/
int judge_num(char *ch); //用于检测输入的字符串ch是否全部为数字,全部为数字则返回1,否则返回0
int input_num(); //用于输入数字,如果输入的全部为数字则返回该数字,否则一直停在输入状态
double input_double(); //用于输入小数
int input_limit(int n); //输入选项,控制输入的数字范围为0-n,在这个范围内则返回该数字,否则一直停在输入状态
int input_limit0(int n);
int keyexam(char *actual_key, char *input_key); //密码检测函数,x为密码位数,actul_key[]为真实密码,input_key为输入密码,密码匹配返回1否则返回0
student* load_stu(); //将学生文件生成链表,返回链表头指针
void store_stu(student *p_head); //将学生链表存入学生文件,需传入链表头指针
course* load_cour(); //将课程文件生成链表,返回链表头指针
void store_cour(course *p_head); //将课程链表存入课程文件,需传入链表头指针
student* locate_end(student *head); //传入头节点,返回尾节点
course* locate_end(course *head); //传入头节点,返回尾节点
void help(); //显示帮助信息
int link_count(student* head);
int link_count(course* head); //计算链表节点数量
int judge_ascii_num(char in[]); //检测输入是否全部为ASCII的数字,是返回1否则返回0
/*管理员函数*/
int man_login(); //管理员登陆函数,密码正确返回1,否则返回0
int man_menu(); //管理员主菜单,返回对应的输入值
void student_add(student *head); //增加学生的函数
void student_delete(student *head); //删除学生的函数
void man_search_stu(student *head); //搜索学生的函数
void student_modify(student *head); //管理员修改学生信息
void course_add(course *head); //增加课程的函数
void course_delete(course *head); //删除课程的函数
void course_modify(course *head); //修改课程信息的函数
void print_all(); //打印所有学生和课程的函数
void man_modifyKey(); //管理员修改密码
void man_backups_recover(); //管理员备份和恢复数据
void courseshowone_man(course *ad); //管理员显示一门课程信息
void courseshowall_man(course *ad); //管理员显示所有课程信息
/*学生函数*/
student* stu_login(student* head); //学生登陆函数,学号和密码都正确则返回链表中该学生的指针,错误则返回null
int stu_menu(); //学生菜单,返回对应的输入值
void student_showone(student *p); //显示一个学生的信息
void student_showall(student *head); //显示所有学生的信息
student *studentnamefind_char(student *head, char tar[]); //根据学生姓名查找学生,如果学生为头节点则返回空指针,不为头节点则返回前一个节点的指针,不存在则返回尾节点
student *studentnamefind_num(student *head, char tar[]); //根据学生学号查找学生,如果学生为头节点则返回空指针,不为头节点则返回前一个节点的指针,不存在则返回尾节点
void stu_modifyKey(student* stu); //学生修改密码
void coursechoose(course* head, student* stu); //选课函数,min为最少要达到的学分
void courseshow_nature(course *head); //根据课程性质查找并显示课程信息
void courseshow_term(course *head); //根据开课学期查找并显示课程信息
void cour_nat_te(course* head); //根据课程性质与开课学期组合查找课程信息
void coursenumfindtip(course *head); //查课子函数
void coursenamefindtip(course *head); //查课子函数2
void stu_dele_cour(course* head, student* stu); //删除已选课程
/*课程函数*/
void course_showone(course *ad); //显示一门的信息
void course_showall(course *head); //显示所有课程的信息
void search_course(course *head); //搜索课程的函数
course *coursenamefind_char(course* head, char tar[]); //根据课程名称查找课程节点,如果课程为头节点则返回空指针,不为头节点则返回前一个节点的指针,不存在则返回尾节点
course *coursenumfind_num(course* head, char tar[]); //根据课程编号查找课程,如果课程为头节点则返回空指针,不为头节点则返回前一个节点的指针,不存在则返回尾节点
main.cpp
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"all.h"
student* stu_head;
course* cour_head;
course *cour_tail;
student *stu_tail; //这四个指针是全局变量
int main()
{
/*对四个指针变量初始化*/
stu_head = load_stu(); //stu_head指向学生链表头
stu_tail = locate_end(stu_head); //stu_tail指向学生链表尾
cour_head = load_cour(); //cour_head指向课程链表头
cour_tail = locate_end(cour_head); //cour_tail指向课程链表尾
//{/*这段代码用于生成原始管理员密码:10个0;
// 编译链接后执行一次然后注释掉*/
// FILE *fp = fopen(MAN_F, "w+");
// for (int i = 0; i < 10; i++)
// {
// fputc('0', fp);
// }
// fclose(fp);
//}
printf("\n\t\t--------------------------------欢迎使用选课系统!---------------------------------\n");
int status=-1;
while (1)//判断登陆类型
{
status = -1;
printf("\n\n\t\t*****请选择登陆类型 [1]学生 [2]管理员 [3]显示帮助 [0]退出系统:");
status = input_limit0(3);
if ((status == 0) || (status == 1) || (status == 2)||(status==3))
break;
else
printf("\n\t\t##### 输入错误!只能选择1、2或0 #######\n");
}
while (1)
{
if (status == 2)//管理员登陆
{
if (man_login() == 1)
{
printf("\n\n\t\t-----------------------------------管理员登陆成功!--------------------------------\n\n");
int menu_return = man_menu();
while (1)
{
switch (menu_return)
{
case 1:
student_add(stu_head); break;
case 2:
student_delete(stu_head); break;
case 3:
student_modify(stu_head); break;
case 4:
man_search_stu(stu_head); break;
case 5:
course_add(cour_head); break;
case 6:
course_delete(cour_head); break;
case 7:
course_modify(cour_head); break;
case 8:
search_course(cour_head); break;
case 9:
print_all(); break;
case 10:
man_modifyKey(); break;
case 11:
man_backups_recover(); break;
case 0:
break;
default:
printf("\t\t\t#####输入错误,请重新输入######!\n");
}
if (menu_return == 0)
break;
menu_return = man_menu();
}
}
else
printf("\t\t######密码错误,请重新登陆!######\n");
}
else if (status == 1)//student login
{
student* p_stu = stu_login(stu_head);
if (p_stu != NULL)//p_stu为指向该学生的指针
{
printf("\t\t*******请输入登陆密码:");
char input[100];
scanf("%s", input);
while (getchar() != '\n');
if (strcmp(p_stu->password, input) == 0)
{
printf("\n\n\t\t-----------------------------%s 欢迎进入选课系统! ---------------------------------\n\n", p_stu->name);
int menu_return = stu_menu();
while (1)
{
switch (menu_return)
{
case 1:
course_showall(cour_head); break;
case 2:
search_course(cour_head); break;
case 3:
coursechoose(cour_head,p_stu); break;
case 4:
stu_dele_cour(cour_head, p_stu); break;
case 5:
student_showone(p_stu); break;
case 6:
stu_modifyKey(p_stu); break;
case 0:
break;
default:
printf("\t\t######输入错误,请重新输入!######\n");
}
if (menu_return == 0)
break;
menu_return = stu_menu();
}
}
else
{
printf("\t\t#####密码错误,请重新登陆!#######\n");
}
}
else
printf("\t\t#####该学号不存在,请重新登陆!######\n");
p_stu = NULL;
}
else if (status == 3)//显示帮助信息
help();
else if (status == 0)//关闭系统
return 0;
while (1)//再次判断登陆类型
{
status = -1;
printf("\n\n\t\t*****请选择登陆类型 [1]学生 [2]管理员 [3]显示帮助 [0]退出系统:");
status = input_limit0(3);
if ((status == 0) || (status == 1) || (status == 2) || (status == 3))
break;
else
printf("\n\t\t##### 输入错误!只能选择1、2或0 #######\n");
}
}
}
common.cpp
#include<stdio.h>
#include<string.h>
#include"all.h"
#include<stdlib.h>
#include<malloc.h>
#include<ctype.h>
extern student* stu_head;
extern course* cour_head;
extern course *cour_tail;
extern student *stu_tail; // 这四个指针变量在main.cpp中已经声明为全局变量
int keyexam(char *actual_key, char *input_key)//密码正确则返回1,否则返回0
{
if (strcmp(actual_key, input_key) == 0)
return 1;
else
return 0;
}
student* load_stu()//经调试已经正确
{
int count = 0;
FILE *fp;
if ((fp = fopen(STU_F, "r")) == NULL)
{
printf("\t\tcannot open the file:STU_F\n");
exit(0);
}
student* temp = (student*)malloc(sizeof(student));
while (!feof(fp))
{
if (fread(temp, sizeof(student), 1, fp))
count++;
}
free(temp);
temp = NULL;
if (count == 0)
return NULL;
else
{
rewind(fp);
student *p_head = NULL;//文件中有链表信息,则创建一个头指针
p_head = (student*)malloc(sizeof(student));
fread(p_head, sizeof(student), 1, fp);//用文件内容初始化链表节点
p_head->next = NULL;
count--;
student* p_new = p_head;
student* p_end = p_head;
for (int i = 0; i < count; i++)
{
p_new = (student*)malloc(sizeof(student));
fread(p_new, sizeof(student), 1, fp);
p_new->next = NULL;
p_end->next = p_new;
p_end = p_new;
}
fclose(fp);
return p_head;
}
}
void store_stu(student * p_head)//经调试已正确
{
FILE *fp;
if ((fp = fopen(STU_F, "w")) == NULL)//以只写方式打开文件,覆盖以前数据
{
printf("\t***STU_F missed,please quit the system and check for that!\n\n");
exit(0);
}
while (p_head != NULL)//将链表所有节点写入缓冲区
{
fwrite(p_head, sizeof(student), 1, fp);//将链表一个节点写入缓冲区
p_head = p_head->next; //p_head指向下一个节点
}
fclose(fp);//保存文件,清空缓冲区
}
course * load_cour()
{
int count = 0;
FILE *fp;
if ((fp = fopen(COUR_F, "r")) == NULL)
{
printf("\t\tcannot open the file:COUR_F\n");
exit(0);
}
course* temp = (course*)malloc(sizeof(course));
while (!feof(fp))
{
if (fread(temp, sizeof(course), 1, fp))
count++;
}
free(temp);
temp = NULL;
if (count == 0)
return NULL;
else
{
rewind(fp);
course *p_head = NULL;//文件中有链表信息,则创建一个头指针
p_head = (course*)malloc(sizeof(course));
fread(p_head, sizeof(course), 1, fp);//用文件内容初始化链表节点
p_head->next = NULL;
count--;
course* p_new = p_head;
course* p_end = p_head;
for (int i = 0; i < count; i++)
{
p_new = (course*)malloc(sizeof(course));
fread(p_new, sizeof(course), 1, fp);
p_new->next = NULL;
p_end->next = p_new;
p_end = p_new;
}
fclose(fp);
return p_head;
}
}
void store_cour(course * p_head)
{
FILE *fp;
if ((fp = fopen(COUR_F, "w")) == NULL)//以只写方式打开文件,覆盖以前数据
{
printf("\t***COUR_F missed,please quit the system and check for that!\n\n");
exit(0);
}
while (p_head != NULL)//将链表所有节点写入缓冲区
{
fwrite(p_head, sizeof(course), 1, fp);//将链表一个节点写入缓冲区
p_head = p_head->next; //p_head指向下一个节点
}
fclose(fp);//保存文件,清空缓冲区
}
student * locate_end(student * head)
{
student* end = head;
while (head != NULL)
{
end = head;
head = head->next;
}
return end;
}
course* locate_end(course * head)
{
course* end = head;
while (head != NULL)
{
end = head;
head = head->next;
}
return end;
}
void help()
{
int input = -1;
while (1)
{
printf("\n\t\t*****请选择需要的帮助类型 [1]学生帮助 [2]管理员帮助 [3]版权信息 [0]返回主页:");
scanf("%d", &input);
while (getchar() != '\n');
if (input == 0)
break;
else if (input == 1)//学生使用说明
剩余20页未读,继续阅读
weixin_38566318
- 粉丝: 7
- 资源: 972
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0