宿舍管理系统代码实现.docx
《宿舍管理系统代码实现.docx》由会员分享,可在线阅读,更多相关《宿舍管理系统代码实现.docx(33页珍藏版)》请在冰豆网上搜索。
宿舍管理系统代码实现
VC++6.0实现的代码
由于数据库暂时没学会,利用了文本文件进行保存修改用户数据
#include"iostream"
#include"string"
#include"fstream"
#include"iomanip"
usingnamespacestd;
intcount1=0,count11=0;//学生总数和交钱的人数
intcount2=0,count22=0;
classStu
{
public:
Stu(doublexwater=0,doublexpower=0,doublexgas=0,stringxnum="a",stringxna="a");//学生类构造函数
voidoperator=(StuS);//赋值运算符重载
friendostream&operator<<(ostream&a,Stu&S)//插入运算符重载
{a<a<a<a<a<a<a<a<a<if(S.flag!
=0)
a<<"已交";
elsea<<"未交";
cout<returna;
}
doubleSGetW();//计算水费
doubleSGetC();//计算电费
doubleSGetG();//计算煤气费
doubleStotal();//计算总费用
doublewater,power,gas,water_rate,circuit,gas_rate,total;
intflag;
stringnumber,name;
};
Stu:
:
Stu(doublexwater,doublexpower,doublexgas,stringxnum,stringxna)//学生类构造函数
{
water=xwater;power=xpower;gas=xgas;
number=xnum;name=xna;
flag=0;
}
voidStu:
:
operator=(StuS)//赋值运算符重载
{
name=S.name;
number=S.number;
water=S.water;
power=S.power;
gas=S.gas;
}
doubleStu:
:
SGetW()//计算水费
{
if(water<10)
water_rate=0;
else
water_rate=4.2*(water-10);
returnwater_rate;
}
doubleStu:
:
SGetC()//计算电费
{
if(power<10)
circuit=0;
else
circuit=0.6*(power-10);
returncircuit;
}
doubleStu:
:
SGetG()//计算煤气费
{
if(gas<10)
gas_rate=0;
else
gas_rate=2.3*(gas-10);
returngas_rate;
}
doubleStu:
:
Stotal()//计算总的钱
{
total=SGetG()+SGetW()+SGetC();
returntotal;
}
//*************************************************************************************
classarrayofStu//学生类计算
{
public:
arrayofStu(intsz=1){size=sz;student=newStu[size];}//构造函数
~arrayofStu(){delete[]student;}
voidxuesheng();//学生用户主菜单
voidjiaofei();//学生交费菜单
voidregist();//登记学生
voidamend();//修改用户菜单
voidadd();//增加用户
voiddelet();//删除用户菜单
voidnad();//姓名删除
voidnumd();//学号删除
voidcheck();//查询菜单
voidnacheck();//姓名查询
voidnumcheck();//学号查询
voidnaj();//输入姓名交费
voidnumj();//输入学号交费
voiddisplay();//查看交费情况
voidsave();
private:
intsize;
Stu*student;
};
voidarrayofStu:
:
regist()//学生用户注册
{inti=0;
ifstreamf("Stu.txt");
while(f.good())//!
f.eof()
{
f>>student[i].number;
f>>student[i].name;
f>>student[i].water;
f>>student[i].power;
f>>student[i].gas;
i++;
}
f.close();
count1=i;
cout<<"\t\t注册成功!
!
!
"<}
voidarrayofStu:
:
naj()//输入姓名交费
{charch;doublemoney,money2;
cout<<"\t\t\t欢迎使用姓名交费功能"<stringna;
cout<<"请输入学生姓名:
"<cin>>na;
intfl=0;
for(inti=0;iif(na==student[i].name)
{fl=1;
if(student[i].flag)
cout<<"该学生已缴纳过费用"<else
{cout<<"你应该交"<cout<<"确定是否真的现在交费(Y/N)"<cin>>ch;
if(ch=='Y'||ch=='y')
{student[i].flag=1;
cout<<"你实际交的钱是:
"<cin>>money;
if(money>student[i].Stotal())cout<<"找零"<if(student[i].Stotal()>money){cout<<"交的钱不够,还应交"<cout<<"补交:
";cin>>money2;}
cout<<"交费成功"<xuesheng();
}
elsexuesheng();
}
}
if(!
fl)
cout<<"没有这个学生"<}
voidarrayofStu:
:
numj()//输入学号交费
{cout<<"\t\t\t欢迎使用学号交费功能"<stringnum;doublemoney,money2;charch;
cout<<"请输入学生学号:
"<cin>>num;
intfl=0;
for(inti=0;iif(num==student[i].number)
{
if(student[i].flag)
{fl=1;cout<<"该学生已缴纳过费用"<else
{cout<<"你应该交"<cout<<"确定是否真的现在交费(Y/N)"<cin>>ch;
if(ch=='Y'||ch=='y')
{student[i].flag=1;
cout<<"你实际交的钱是:
"<cin>>money;
if(money>student[i].Stotal())cout<<"找零"<if(student[i].Stotal()>money){cout<<"交的钱不够,还应交"<cout<<"补交:
";cin>>money2;}
cout<<"交费成功"<xuesheng();
}
elsexuesheng();
}
}
if(!
fl)
cout<<"没有这个学生"<}
voidarrayofStu:
:
add()//增加学生
{cout<<"\t\t\t欢迎使用增加学生功能"<cout<<"请输入学生的姓名:
"<cin>>student[count1].name;
cout<<"请输入学生的学号:
"<cin>>student[count1].number;
cout<<"请输入学生的用水量:
"<cin>>student[count1].water;
cout<<"请输入学生的用电量:
"<cin>>student[count1].power;
cout<<"请输入学生的用煤气量:
"<cin>>student[count1].gas;
count1++;
cout<<"\t\t\t学生信息已被成功的增加!
"<}
voidarrayofStu:
:
nad()//按姓名删除
{cout<<"\t\t\t欢迎使用姓名删除学生功能"</*cout<cout<intfl=0;inti,j;
stringna;
cout<<"请输入要删除学生的姓名"<cin>>na;
for(i=0;iif(na==student[i].name)
{fl=1;break;}
if(fl)
{for(j=i;jstudent[j]=student[j+1];
count1--;
cout<<"你已成功删除学生信息"<}
elsecout<<"没有这个学生"<}
voidarrayofStu:
:
display()
{
inti;
if(count11==0)cout<<"暂时还无学生交费"<else{cout<<"已交费人员信息"<cout<<"学号"<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<"总额"<<"是否交费"<for(i=0;iif(student[i].flag)
cout<}
if(count11==count1)cout<<"所有学生均以交费"<else{cout<<"未交费人员信息"<cout<<"学号"<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<"总额"<<"是否交费"<for(i=0;iif(!
student[i].flag)
cout<}
}
voidarrayofStu:
:
numd()//按学号删除
{cout<<"\t\t\t欢迎使用学号删除学生功能"<intfl=0;inti,j;
stringnum;
cout<<"请输入要删除学生的学号"<cin>>num;
for(i=0;iif(num==student[i].number)
{fl=1;break;}
if(fl)
{for(j=i;jstudent[j]=student[j+1];
count1--;
cout<<"你已成功删除学生信息"<}
else
cout<<"没有这个学生"<}
voidarrayofStu:
:
nacheck()//姓名查询
{cout<<"\t\t\t欢迎使用姓名查询学生功能"<inti,fl=0;
stringna;
cout<<"请输入要查找的姓名"<cin>>na;
for(i=0;iif(na==student[i].name)
{fl=1;break;}
if(fl){
cout<<"学号"<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<"总额"<<"是否交费"<cout<elsecout<<"没有这个学生"<}
voidarrayofStu:
:
numcheck()//学号查询
{cout<<"\t\t\t欢迎使用学号查询学生功能"<inti,fl=0;
stringnum;
cout<<"请输入要查找的学号"<cin>>num;
for(i=0;iif(num==student[i].number)
{fl=1;break;}
if(fl)
{
cout<<"学号"<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<"总额"<<"是否交费"<cout<}
else
cout<<"没有这个学生"<}
voidarrayofStu:
:
save()
{
ofstreamf("Stu2.txt");
f<<"学号"<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<"总额"<<"是否交费"<for(inti=0;if<f.close();
//cout<<"恭喜你,文件已成功保存"<}
voidarrayofStu:
:
delet()//删除学生菜单
{
intchoice;
cout<<"\t\t\t\t**************"<cout<<"\t\t\t\t删除信息"<cout<<"\t\t\t\t1,按学号删除"<cout<<"\t\t\t\t2,按姓名删除"<cout<<"\t\t\t\t3,返回主菜单"<cout<<"\t\t\t\t0,返回上一层"<cout<<"\t\t\t\t**************"<while
(1)
{
cout<<"请输入你的选择"<cin>>choice;
switch(choice)
{case1:
numd();break;//学号删除
case2:
nad();break;//姓名删除
case3:
xuesheng();break;//返回学生管理主菜单
case0:
amend();break;//返回上一层
}
if(choice==0)
break;
}
}
voidarrayofStu:
:
jiaofei()//学生缴费菜单
{
intchoice;
cout<<"\t\t\t\t****************"<cout<<"\t\t\t\t*---学生缴费---*"<cout<<"\t\t\t\t*1,输入学号交费*"<cout<<"\t\t\t\t*2,输入姓名交费*"<cout<<"\t\t\t\t*0,返回上一层*"<cout<<"\t\t\t\t****************"<while
(1)
{
cout<<"请输入你的选择"<cin>>choice;
switch(choice)
{case1:
numj();break;//输入学号计费
case2:
naj();break;//输入姓名计费
case0:
xuesheng();break;//返回上一层
}
if(choice==0)
break;
}
}
voidarrayofStu:
:
xuesheng()//学生用户主菜单
{
intchoice;
cout<<"\t\t\t\t欢迎使用学生用户管理系统"<cout<<"********************************"<cout<<"\t\t\t\t*------1,注册学生------*"<cout<<"\t\t\t\t*------2,修改用户------*"<cout<<"\t\t\t\t*------3,缴纳费用------*"<cout<<"\t\t\t\t*------4,查询费用------*"<cout<<"\t\t\t\t*------5,查看交费情况--*"<cout<<"\t\t\t\t*------6,保存信息到文件--*"<cout<<"\t\t\t\t*------0,返回上一层----*"<cout<<"********************************"<cout<<"友情提示:
第一次使用时,要进行注册,否则,后果自负!
"<for(;;)
{
cout<<"请输入您的选择"<cin>>choice;
switch(choice)
{
case1:
regist();break;//注册
case2:
amend();break;//修改
case3:
jiaofei();break;//缴纳费用
case4:
check();break;
case5:
display();break;
case6:
save();break;
case0:
break;
}
if(choice==0)break;
}
}
voidarrayofStu:
:
amend()//修改用户菜单
{
intchoice;
cout<<"\t\t\t\t修改学生信息"<cout<<"\t\t\t\t1,增加学生"<cout<<"\t\t\t\t2,删除学生"<cout<<"\t\t\t\t0,回上一层"<while
(1)
{
cout<<"请输入你的选择"<cin>>choice;
switch(choice)
{case1:
add();break;
case2:
delet();break;
case0:
xuesheng();break;
}
if(choice==0)
break;
}
}
voidarrayofStu:
:
check()//查询菜单
{
intchoice;
cout<<"\t\t查询学生信息"<cout<<"1,按姓名查找"<cout<<"2,按学号查找"<cout<<"0,返回上一层"<cout<<"============================================="<while
(1)
{
cout<<"请输入您的选择"<cin>>choice;
switch(choice)
{
case1:
nacheck();break;//输入姓名查找
case2:
numcheck();break;//输入学号查找
case0:
xuesheng();break;//如果是break时分析
}
if(choice==0)break;
}
}
//*********************************************************************************