C语言——上机管理系统(包含对上机时间的处理)

最近接了个c语言的课设作业,写完了在这码着吧,说不定哪天自己还能用到(滑稽)。
假设某机房共有51台计算机,其中50台(编号1~50)供学生自由上机使用,1台(编号51)为管理机。模拟网络环境,为管理机编写软件,以实现对计算机以及上机学生的管理。软件主要功能如下:

  • (1) 学生上机。即,输入学生学号,可以随机申请到一台空闲且无故障的计算机。
  • (2) 学生下机。即,输入学生学号,能够将计算机的状态由“占用”变为“空闲”,同时显示学生上机持续的时间长度(单位秒)。
  • (3) 数据统计。即,不但可以显示当前时刻机器占用情况,也可以显示当前时刻所有故障机器的编号。
  • 软件至少应具有“学生上机”、“学生下机”、“占用统计”、“故障统计”、“退出”5项菜单。
话不多说,上代码
//Time:2020/6/3 //Author:SIrcle //学生上机系统 #include #include #include #include #include using namespace std; int com_num=0; struct computer//电脑类 { int flag; char stu_num[15]; int start_h; int start_m; int start_s; }com[51]; void ready()//初始化 { for(int i=1; i<51; i++) { com[i].flag=0; } } int timecalculate(int h1,int m1,int s1,int h2,int m2,int s2)//计算上机时间函数 { int h=(h2-h1)*3600; int m=(m2-m1)*60; int s=s2-s1; return h+m+s; }void up_computer()//学生上机函数 { printf("--------请输入您的学号来申请一台电脑---------\n"); char xuehao[15]; int num,f1=0; scanf("%s",xuehao); for(int i=1; i<51; i++) { if(com[i].flag==0) { num=i; f1=1; printf("--------上机成功--------\n"); break; } } if(f1==0) printf("----------电脑已全被预约,请稍后再来---------"); SYSTEMTIME sys; GetLocalTime(&sys); com[num].flag=1; strcpy(com[num].stu_num,xuehao); com[num].start_h=sys.wHour; com[num].start_m=sys.wMinute; com[num].start_s=sys.wSecond; com_num++; } void down_computer()//学生下机函数 { int h,m,s,f=0,stu_time; printf("--------请您输入您的学号来退出机器--------\n"); SYSTEMTIME sys; GetLocalTime(&sys); char xuehao[15]; scanf("%s",xuehao); for(int i=1; i

【C语言——上机管理系统(包含对上机时间的处理)】对代码有疑问可以私信作者哦,虽然不一定回复。转载标明出处,如果对您有用希望点个赞~~
报告链接:报告

    推荐阅读