c宿舍管理系统实现.doc
《c宿舍管理系统实现.doc》由会员分享,可在线阅读,更多相关《c宿舍管理系统实现.doc(29页珍藏版)》请在冰豆网上搜索。
河南工业大学计科0906马飞扬
根据本报告,可完全实现建立运行宿舍管理系统,这是我c++的课程设计。
1:
工程结构
初始信息:
2:
源代码
main.cpp:
#include//预编译语句
#include//
#include//
#include//
usingnamespacestd;//
#include"show.h"//文件包含语句
#include"show2.h"//
#include"denglu.h"//
#include"jianlixinxi.h"//
#include"chaxun.h"//
#include"xiugai.h"//
#include"shanchu.h"//
#include"huizong.h"//
#include"xiumima.h"//
#include"zhuce.h"//
#include"weisheng.h"//
voidmain()
{
intchoice=0;//记录选择
denglu();//输入登录信息
show();//显示菜单
cin>>choice;
while(choice!
=0)//循环输入选择
{
switch(choice)
{
case1:
jianli();break;//建立宿舍信息
case2:
chaxun();break;//查询学生信息
case3:
huizong();break;//宿舍信息汇总
case4:
xiugai();break;//修改学生信息
case5:
zhuce();break;//添加学生信息
case6:
shanchu();break;//删除学生信息
case7:
weisheng();break;//宿舍卫生评比
case8:
xiumima();break;//修改登录信息
case0:
break;
default:
cout<<"您按错了!
"< }
cin>>choice;
}
}
chaxun.h:
voidchaxue(intrenshu);//按学号查询
voidchaban(intrenshu);//按班级查询
voidchasu(intrenshu);//按宿舍查询
structstudent2//定义存储信息的结点结构
{
charname[20];
charnumber[20];
charbanji[20];
intsushehao;
};
student2array1[100];//定义存储信息的线性结构数组
voidchaxun()
{
student2p;//辅助结点变量
intchoice=0;
intrenshu=0;
ifstreamfin2("学生信息.txt");
if(!
fin2)
{
cout<<"error!
"< exit(0);
}
while(!
fin2.eof())//从文件输入当前所有学生信息
{
fin2>>p.name>>p.number>>p.banji>>p.sushehao;
renshu++;
}
renshu--;
fin2.close();
cout<<"1:
按学号查询";
cout<<"\t\t\t2:
按班级查询\n";
cout<<"3:
按宿舍查询\n";
cout<<"请选择(0返回):
";
cin>>choice;
while(choice!
=0)//循环操作
{
switch(choice)
{
case1:
chaxue(renshu);break;
case2:
chaban(renshu);break;
case3:
chasu(renshu);break;
case0:
break;
default:
cout<<"您输错了!
"< }
cout<<"请选择:
";
cin>>choice;
}
cout<<"已退出!
"< show2();//显示主菜单
}
voidchaxue(intrenshu)
{
student2p;
inti=0;
charxuehao[20];
cout<<"查询的学号:
";//
cin>>xuehao;//输入查询的学号
ifstreamfin1("学生信息.txt");
if(!
fin1)
{
cout<<"error!
"< exit(0);
}
for(intj=0;j {
fin1>>p.name>>p.number>>p.banji>>p.sushehao;
if(!
strcmp(p.number,xuehao))//找到相关信息后进行输出
{
cout<<"姓名:
"<
"<
cout<<"班级:
"<
"<
i++;
break;
}
}
fin1.close();
if(i==0)
{
cout<<"没有该生信息!
"< }
}
voidchaban(intrenshu)//实现细节类似上个函数
{
student2p;
inti=0;
charbanji[20];
cout<<"查询的班级:
";
cin>>banji;
ifstreamfin1("学生信息.txt");
if(!
fin1)
{
cout<<"error!
"< exit(0);
}
for(intj=0;j {
fin1>>p.name>>p.number>>p.banji>>p.sushehao;
if(!
strcmp(p.banji,banji))
{
cout<<"姓名:
"<
"<
cout<<"班级:
"<
"<
i++;
}
}
fin1.close();
if(i==0)
{
cout<<"没有该班学生信息!
"< }
}
voidchasu(intrenshu)//实现细节类似上个函数
{
student2p;
inti=0;
intsushehao;
cout<<"查询的宿舍号:
";
cin>>sushehao;
ifstreamfin1("学生信息.txt");
if(!
fin1)
{
cout<<"error!
"< exit(0);
}
for(intj=0;j {
fin1>>p.name>>p.number>>p.banji>>p.sushehao;
if(p.sushehao==sushehao)
{
cout<<"姓名:
"<
"<
cout<<"班级:
"<
"<
i++;
}
}
fin1.close();
if(i==0)
{
cout<<"该宿舍无人入住!
"< }
}
denglu.h:
voiddenglu()
{
charyonghu1[20];//存储用户输入的登录信息
charmima1[10];//
charyonghu2[20];//存储当前系统设定的登录信息
charmima2[10];//
cout<<"用户名(初始值:
111111):
";
cin>>yonghu1;
cout<<"密码(初始值:
000000):
";
cin>>mima1;
ifstreamfin1("登录信息.txt");
if(!
fin1)
{
cout<<"error!
"< exit(0);
}
fin1>>yonghu2
>>mima2;
fin1.close();
if(strcmp(yonghu1,yonghu2)||strcmp(mima1,mima2))//判断是否为合法用户
{
cout<<"用户名或密码错误!
"< exit(0);
}
}
huizong.h:
voidhuizong()
{
charlouhao[20];intloucheng=0;intfangjian=0;introngliang=0;inti=0;//记录宿舍楼的基本信息
student2array4[100];//存储宿舍楼的所有学生信息
intsusheshu=0;intrenshu=0;//记录宿舍楼已入住的宿舍数及总入住人数
ifstreamfin("学生信息.txt");
if(!
fin)
{
cout<<"error!
"< exit(0);
}
while(!
fin.eof())//输入所有学生信息
{
fin>>array4[renshu].name>>array4[renshu].number>>array4[renshu].banji>>array4[renshu].sushehao;
renshu++;
}
renshu--;//记录入住人数
fin.close();
if(renshu!
=0)
{
susheshu++;//
for(i=1;i {
if(array4[i].sushehao!
=array4[i-1].sushehao)
{
susheshu++;
}
}
}
ifstreamfin1("宿舍信息.txt");
if(!
fin1)
{
cout<<"error!
"< exit(0);
}
fin1>>louhao;//宿舍楼编号
fin1>>loucheng;//楼层个数
fin1>>fangjian;//每层房间数
fin1>>rongliang;//房间容量
fin1.close();
cout<"< cout<<"已入住:
"< cout<<"\t\t剩余容纳量:
"<