打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
还在为做不出课设担心?C语言开发的学生选课系统资料免费送


      【【走进IT】还在为做不出课设担心?C语言开发的学生选课系统资料免费送】https://toutiao.com/group/6577106224653795848/?iid=15906422033&app=explore_article&timestamp=1531374719&tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_ios&utm_campaign=client_share

很多人在学完了C语言后,都有一个疑惑:就是为什么C语言能编写电脑系统这样强大的软件,而自己连简单的程序都开发不出来呢?说到底还是缺乏开发经验,多学,多做,是学习编程语言最好的方法。从小项目做起是比较好的途径。其中学生选课系统是大多数人选择的项目之一。

在此小编提供了一份完整的学生选课系统源码,供大家参考,学习。复制到在编译器里直接运行即可,小编也提供了一份源码的 电子文档,有需要的朋友,只需要点击【关注】【私信】发送“选课”即可,小编就会把源码发给你了。

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define N 10

struct course

{

char courseCode[10];

char courseName[20];

char courseType[10];

int totalPeriod;

int classPeriod;

int experiPeriod;

int creditHour;

int term;

}CourseInfo[N];

struct student

{

char stuNo[15];

char courseCode[10];

}StuCourInfo[N];

int count;//全局变量

int main()//主函数

{

int n;

int menu();

int f1();

int luru();

int liulan();

int chaxun();

int xuanke();

int tongji();

printf('\n ********************** ***********************');

printf('\n\n ********** 欢迎进入学生选课系统!**********');

menu();

printf('\n');

printf(' ******************* the end *********************\n');

printf('\n ********************** ***********************');

printf('\n\n 请先选择1 进行课程信息录入:');

scanf('%d',&n);//防止错误,请重新输入

for(;n>5||n<0;)

{

printf('\n 输入错误!请重新输入!\n ');

scanf('%d',&n);

}

while(n>0&&n<6)

{

switch(n)

{

case 1:luru();break;//录入课程信息

case 2:liulan();break;//浏览课程信息

case 3:chaxun();break;//查询课程信息

case 4:xuanke();break;//进入选课操作

case 5:tongji();break;//统计选课情况

}

scanf('%d',&n);//选择所需操作

for(;n>5||n<0;)

{

printf('\n\n');

printf('\n 输入错误!请重新输入!\n ');

scanf('%d',&n);//防止错误,提示重新输入

}

system('cls');//清屏

}

if(n==0)

{

printf(' \n\n\n\n\n\n\n');

printf(' ********** 谢谢使用!**********\n ');

printf('\n\n\n\n\n');

}

exit(0);//退出选课系统

return 0;

}

int menu()//菜单函数

{

printf('\n\n\n\n');

printf(' 1. 录入课程信息\n\n');

printf(' 2. 浏览课程信息\n\n');

printf(' 3. 查询课程信息\n\n');

printf(' 4. 进入选课操作\n\n');

printf(' 5. 统计选课情况\n\n');

printf(' 0. 退出选课系统\n\n');

return 0;

}

int f1()

{

printf('\n 课程编号 课程名称 课程性质 总学时 授课学时 上机学时 学分 开课学期:\n');

return 0;

}

int luru()//录入函数

{

FILE *fp;//定义指向文件的指针

struct course c;

int i;

if((fp=fopen('D://course.txt','w'))==NULL)//在D盘建立文件'course.txt'

{

printf('cannot open file\n');

exit(0);

}

printf('\n 请输入选择的课程门数:');

scanf('%d',&count);

printf('\n\n');

f1();

for(i=0;i<count;i )

{

scanf('%s%s%s%d%d%d%d%d',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,&CourseInfo[N].totalPeriod,&CourseInfo[N].classPeriod,&CourseInfo[N].experiPeriod,&CourseInfo[N].creditHour,&CourseInfo[N].term);

fprintf(fp,'%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,CourseInfo[N].totalPeriod,CourseInfo[N].classPeriod,CourseInfo[N].experiPeriod,CourseInfo[N].creditHour,CourseInfo[N].term);

}

fclose(fp);//关闭文件

printf('\n ********* 录入成功!*********\n');

menu();

return 0;

}

int liulan()//浏览函数

{

int i=0;

FILE *fp;//定义指向文件的指针

struct course c;//定义课程结构体变量

if((fp=fopen('D://course.txt','r'))==NULL)//打开文件'course.txt'

{

printf('\ncannot open course!\n');

exit(0);

}

f1();

while(!feof(fp)&&i<count)

{

fscanf(fp,'%s%s%s%d%d%d%d%d',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,&CourseInfo[N].totalPeriod,&CourseInfo[N].classPeriod,&CourseInfo[N].experiPeriod,&CourseInfo[N].creditHour,&CourseInfo[N].term);

printf('%7s%11s%10s%9d%9d%8d%9d%8d\n',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,CourseInfo[N].totalPeriod,CourseInfo[N].classPeriod,CourseInfo[N].experiPeriod,CourseInfo[N].creditHour,CourseInfo[N].term);

i ;

}

fclose(fp);//关闭文件

menu();

return 0;

}

int chaxun()//查询函数

{

FILE *fp;//定义指向文件的指针

struct course c;//定义课程结构体变量

int score;

int b,i=0;

char courseType[10];

printf('\n 1.按学分查询\n');

printf('\n 2.按课程性质查询');

printf(' 请选择查询方式\n\n 输入选项数字:');

scanf('%d',&b);//防止错误,提示重新输入

for(;b<1||b>2;)

{

printf('\n 输入错误!请重新输入!\n ');

scanf('%d',&b);

}//按学分查询

if(b==1)

{

printf('\n 输入你要查询的学分: ');

scanf('%d',&score);

if((fp=fopen('D://course.txt','r'))==NULL)

{

printf('\ncannot open course!\n');

exit(0);

}

f1();

while(!feof(fp)&&i<count)//当没有指向文件尾部,读取文件'course.txt'中的数据

{

fscanf(fp,'%s%s%s%d%d%d%d%d',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,&CourseInfo[N].totalPeriod,&CourseInfo[N].classPeriod,&CourseInfo[N].experiPeriod,&CourseInfo[N].creditHour,&CourseInfo[N].term);

if(c.creditHour==score)//比较输入的分数和结构体中的分数,如果相同,输出那组数据

printf('%7s%11s%10s%9d%9d%8d%9d%8d\n',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,CourseInfo[N].totalPeriod,CourseInfo[N].classPeriod,CourseInfo[N].experiPeriod,CourseInfo[N].creditHour,CourseInfo[N].term);

i ;

}

}

else if(b==2)//按课程性质查询

{

printf('\n\n 输入你要查询的课程性质:');

scanf('%s',courseType);

if((fp=fopen('D://course.txt','r'))==NULL)//打开文件'course.txt'

{

printf('\ncannot open course!\n');

}

f1();

while(!feof(fp)&&i<count)//当没有到达文件尾部,读取'course.txt'中的数据

{

fscanf(fp,'%s%s%s%d%d%d%d%d',CourseInfo[N].courseCode,CourseInfo[N].courseType,CourseInfo[N].totalPeriod,&CourseInfo[N].classPeriod,&CourseInfo[N].experiPeriod,&CourseInfo[N].creditHour,&CourseInfo[N].term);

if(strcmp(c.courseType,courseType)==0)//比较输入的字符串与原文件中的课程性质,如果相同,输出那组数据

printf('%7s%11s%10s%9d%9d%8d%9d%8d\n',c.courseCode,c.courseName,c.courseType,c.totalPeriod,c.classPeriod,c.experiPeriod,c.creditHour,c.term);

i ;

}

}

else

{

printf('输入错误!');//选择错误,就退出

exit(1);

}

fclose(fp);

menu();

return 0;

}

int xuanke()//选课函数

{

int t=0,flag;

int i;

FILE *fp;//定义指向文件的指针

do

{

printf('\n 请输入学号课程编号:');

scanf('%s%s',&StuCourInfo[N].stuNo,&StuCourInfo[N].courseCode);

if((fp=fopen('D://course.txt','r'))==NULL)//打开文件'course.txt'

{

printf('\ncannot open course!\n');

exit(0);

}

while(!feof(fp))//如果课程编号与学生所选一致,就跳出,执行下一步

{

fscanf(fp,'%s%s%s%d%d%d%d%d',CourseInfo[N].courseCode,CourseInfo[N].courseName,CourseInfo[N].courseType,&CourseInfo[N].totalPeriod,&CourseInfo[N].classPeriod,&CourseInfo[N].experiPeriod,&CourseInfo[N].creditHour,&CourseInfo[N].term);

if((StuCourInfo[N].courseCode==CourseInfo[N].courseCode))

t ;

break;

} fclose(fp);

printf('\n 是否继续,是1,否0 \n ');

scanf('%d',&flag);

if((fp=fopen('D://student.txt','a '))==NULL)//在D盘建立文件'student.txt'

{

printf('\ncannot open student!\n');

exit(0);

} //建立,并将学生选课信息输入'student.txt'

for(i=0;i<t;i );

fprintf(fp,'%s\t%s\t',StuCourInfo[N].courseCode,StuCourInfo[N].stuNo);

fclose(fp);//关闭选课文件'course.txt'

}while(flag);

printf('\n ********* 恭喜选课成功!*********\n');

menu();

return 0;

}

int tongji()//统计函数

{

int total=0;

int t,i=0;

FILE *fp;

if((fp=fopen('D://student.txt','r'))==NULL)//打开文件'student.txt'

{

printf('\ncannot open student!\n');

exit(0);

}

printf('\n 学号课程编号\n');

while(!feof(fp))//计数

{

fscanf(fp,'%s%s%d%s\n',StuCourInfo[i].courseCode,StuCourInfo[i].stuNo);//读取文件'student.txt'

total ;

i ;

}

t=i;

for(i=0;i<t;i )

printf('%6s%6s',StuCourInfo[i].courseCode,StuCourInfo[i].stuNo);

printf('\n 选课学生总人数为:%d人',total);

fclose(fp);//关闭文件

menu();

return 0;

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
c语言例题
多记记吧、、、
C语言解二元一次方程
142.抛物样条曲线
经典C语言编程100例/编程开发
经典c程序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服