资源描述
JINGCHU UNIVERSITY OF TECHNOLOGY
课程设计成果
学院:_计算机工程学院_____
班 级: _计算机科学与技术(一)
学生姓名: 姜桥学 号:2009404010121
设计地点(单位)___ A5 -101___________ ____________
设计题目:___ 电煤气管理系统___________________________
完成日期: 2012 年1月 5 日
指导教师评语: _______________________________________
___________________________________________________________________________________________________________________________________________________________________________________________________________________ _
成绩(五级记分制):______ __________
教师签名:_________________________
目 录
一.课程设计目的和要求…………………………………… 2
二.课题分析 …………………………………… 2
三.设计…………………………………… 2-3
1。设计思想
2。设计分析
四.主程序……………………………………3—19
五.结果显示及分析…………………………………19—21
六.感想、收获及体会……………………………………21
七.参考文献……………………………………22
附录……………………………………22
一. 课程设计目的和要求
问题描述:设计一个水电管理信息系统,能够对高校的水电费用进行管理,包括了登记费用,查询费用,以及住户信息管理等。在设计时要考虑到学生和教工在用水电时的不同,学生可以免费使用一定额度的水电,超过这个额度的随便以后必须自费使用,且自费部分水电费的价格标准要高于教工的收费标准(主要是节约资源).
基本要求:
实现对用户信息的录入
实现水电煤气数据的录入
计算并查询用户应缴费用
查询未缴纳费用名单
测试数据:可选用小区物业管理部门的数据,也可采用手工输入不少于10个用户信息的数据。
实现提示:用户基本信息类,教工用户信息类,学生用户信息类,收费标准类,该类存储水电煤气标准单位的收费标准,如:煤气,1。0元/立方米;
不同类型人员水、电、煤气信息类,这些类可以包括水表,电表,煤气表ID,抄表时间,上次抄表时间,本次抄表时间,上次抄表度数,本次抄表度数,本次使用度数,费用,是否缴费标记等信息.在实现的时候考虑继承和多态技术的合理使用.
二.课题分析:
本程序是一个水电气管理信息系统,能够对高校的水电气费用进行管理,包括了成员基本信息,如学号、编号、姓名、成员水电气的用量;程序的用途包括缴纳水电气费、查询一个同学水电气费用量”、查看所有同学的缴费情况、增加学生信息、删除学生信息、退出系统等。在设计时也考虑到学生和教师在用水电气时的不同,学生可以免费使用一定额度的水电气,超过这个额度的以后必须付费,且付费部分水电气费的价格要高于教工的收费标准,该措施的实行是为了鼓励同学们节约用水,以免造成不必要的资源浪费。该软件主要是为了学校的管理人员提供便捷,以更快的完成水电气费用的收缴.
三. 设计
1.设计思想:
设计面向对象的程序设计语言,首先考虑的肯定是要设计类.程序设计了四个类,两个是学生类,两个是教师类.在主函数中用动态数组,机动的分配类存,以至于不造成类存的浪费.在本程序中涉及用户的选择,用户要根据自己的实际需要选择不同的功能,由于选择的多样性,程序中必须要有switch结构控制各个功能的选择,如果需要多次进行操作,则要在switch结构的外部,通过循环来实现.首先该程序的第一目的是要读附录里的内容,然后再根据用户的选项来实现各种不同的功能,当正确按照要求就可进行更进一步进行操作,直到你达到自己的目的为止。本程序通过调用不同的函数来实现不同的功能,通过用户自己的选择可以自己进行操作,在主函数中申明的函数分别起到不同的作用,在本程序中所有的子函数都是在主函数外实现的.在子函数的函数体中为了使程序的功能和细节更加的完善,在子函数中设置菜单,这样不仅使得程序更加完善还有利于用户的操作。使得程序更加简洁明了。
2.设计分析:
在这个电煤气管理系统中,共用到了四个类,一个是stut类,它起的作用是把水电煤气的用量和每个人的缴费信息结合在一起,还有赋值运算符重载、插入运算符重载,最重要的就是那些对象都有共同的属性,通过这个类把学号、姓名、水用量、电用量、气用量集中到一起,所以才能设计一个类;另一个类就是arrayofStu 学生类计算类,这个类的作用主要就是一些功能的实现,有主菜单、交费菜单、交费功能和、查询菜单、查询功能、增加功能、删除菜单、删除功能、查看功能。同样定义一个teacher它起的作用是把水电煤气的用量和每个人的缴费信息结合在一起,还有赋值运算符重载、插入运算符重载,最重要的就是那些对象都有共同的属性,通过这个类把姓名、水用量、电用量、气用量集中到一起,所以才能设计一个类;其另一个类就是arrayofTeacher老师类数组计算,这个类的作用主要就是一些功能的实现,有主菜单、交费菜单、交费功能和、查询菜单、查询功能、增加功能、删除菜单、删除功能、查看功能
四.主程序
#include ”iostream"
#include”string”
#include”fstream”
#include”iomanip"
using namespace std;
int count1=0,count11=0; //学生总数和交钱的人数
int count2=0,count22=0;
class Stu
{
public:
Stu(double xwater=0,double xpower=0,double xgas=0,string xnum="a”,string xna=”a”); //学生类构造函数
void operator =(Stu S); //赋值运算符重载
friend ostream &operator 〈〈(ostream & a,Stu &S) //插入运算符重载
{ a〈<setw(8)〈<left〈〈S.number;
a〈<setw(8)〈<left<〈S.name;
a〈<setw(8)<〈left〈〈S.water;
a〈<setw(8)<〈left<<S。power;
a<<setw(8)〈<left<〈S。gas;
a〈〈setw(8)〈<left<<S。SGetW();
a<〈setw(8)<〈left〈〈S。SGetC();
a〈〈setw(8)<〈left〈<S。SGetG();
a〈<setw(8)<〈left〈〈S.Stotal();
if(S.flag)
a<〈"已交";
else a〈<”未交";
cout〈<endl;
return a;
}
double SGetW(); //计算水费
double SGetC(); //计算电费
double SGetG(); //计算煤气费
double Stotal(); //计算总费用
double water,power,gas,water_rate,circuit,gas_rate,total;
int flag;
string number,name;
};
Stu::Stu(double xwater,double xpower,double xgas,string xnum,string xna) //学生类构造函数
{
water=xwater;
power=xpower;
gas=xgas;
number=xnum;
name=xna;
flag=0;
}
void Stu::operator =(Stu S) //赋值运算符重载
{
name=S.name;
number=S.number;
water=S.water;
power=S.power;
gas=S。gas;
}
double Stu::SGetW( ) //计算水费
{
if(water〈10)
water_rate=0;
else
water_rate=4。2*(water—10);
return water_rate;
}
double Stu::SGetC() //计算电费
{
if(power<10)
circuit=0;
else
circuit=0。6*(power-10);
return circuit;
}
double Stu::SGetG() //计算煤气费
{
if(gas<10)
gas_rate=0;
else
gas_rate=2。3*(gas-10);
return gas_rate;
}
double Stu::Stotal() //计算总的钱
{
total=SGetG()+SGetW()+SGetC();
return total;
}
class arrayofStu //学生类计算
{
public:
arrayofStu(int sz=1) {size=sz; student=new Stu[size];} //构造函数
~arrayofStu() { delete [] student; }
void xuesheng(); //学生用户主菜单
void jiaofei(); //学生交费菜单
void regist(); //登记学生
void amend( ); //修改用户菜单
void add( ); //增加用户
void delet(); // 删除用户菜单
void nad(); //姓名删除
void numd(); //学号删除
void check( ); //查询菜单
void nacheck(); //姓名查询
void numcheck(); //学号查询
void naj(); //输入姓名交费
void numj(); //输入学号交费
void display(); //查看交费情况
void save();
private:
int size;
Stu *student;
};
void arrayofStu::regist() //学生用户注册
{
int i=0;
ifstream f(”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 注册成功!!!”〈〈endl;
}
void arrayofStu::naj( ) //输入姓名交费
{ char ch;
double money,money2;
cout〈<”\t\t\t欢迎使用姓名交费功能"〈〈endl;
string na;
cout〈<”请输入学生姓名:”〈<endl;
cin〉>na;
int fl=0;
for(int i=0;i<count1;i++)
if(na==student[i]。name)
{fl=1;
if(student[i]。flag)
cout〈<”该学生已缴纳过费用”〈〈endl;
else
{cout<〈"你应该交”<<student[i].Stotal()<〈”钱"〈<endl;
cout<<”确定是否真的现在交费 (Y/N)”〈〈endl;
cin>〉ch;
if(ch==’Y’||ch==’y')
{student[i].flag=1;
cout〈〈”你实际交的钱是:”〈〈endl;
cin〉〉money;
if(money〉student[i]。Stotal())
cout〈〈”找零”〈〈money—student[i].Stotal()〈<"钱”<〈endl;
if(student[i].Stotal()〉money)
{ cout〈〈”交的钱不够,还应交”〈〈student[i]。Stotal()-money〈〈”钱”〈〈endl;
cout<〈”补交:”;
cin〉〉money2;}
cout<<”交费成功”<〈endl;
count11++;
xuesheng();
}
else xuesheng();
}
}
if(!fl)
cout〈<"没有这个学生"〈<endl;
}
void arrayofStu::numj( ) //输入学号交费
{ cout<〈”\t\t\t欢迎使用学号交费功能"<〈endl;
string num;double money,money2;char ch;
cout<<”请输入学生学号:”〈<endl;
cin>〉num;
int fl=0;
for(int i=0;i〈count1;i++)
if(num==student[i].number)
{
if(student[i]。flag)
{fl=1; cout〈〈”该学生已缴纳过费用”〈<endl;}
else
{ cout〈〈"你应该交”<〈student[i]。Stotal()〈<"钱”<<endl;
cout<<”确定是否真的现在交费 (Y/N)”〈〈endl;
cin〉〉ch;
if(ch=='Y’||ch==’y’)
{student[i].flag=1;
cout〈〈”你实际交的钱是:"〈〈endl;
cin>>money;
if(money〉student[i].Stotal())
cout〈<"找零”<〈money-student[i]。Stotal()〈〈”钱”<<endl;
if(student[i].Stotal()〉money)
{ cout〈〈”交的钱不够,还应交”〈〈student[i].Stotal()-money〈〈"钱”<〈endl;
cout〈<”补交:”; cin〉〉money2;}
cout〈<"交费成功"〈<endl;
count11++;
xuesheng();
}
else xuesheng();
}
}
if(!fl)
cout<〈”没有这个学生”<〈endl;
}
void arrayofStu::add() //增加学生
{cout〈<”\t\t\t欢迎使用增加学生功能”〈〈endl;
cout<〈"请输入学生的姓名:”〈<endl;
cin〉〉student[count1]。name;
cout〈〈”请输入学生的学号:”<<endl;
cin〉〉student[count1]。number;
cout〈<”请输入学生的用水量:”〈〈endl;
cin〉〉student[count1]。water;
cout〈〈"请输入学生的用电量:”<〈endl;
cin>〉student[count1]。power;
cout〈〈"请输入学生的用煤气量:”〈〈endl;
cin〉〉student[count1]。gas;
count1++;
cout〈<”\t\t\t学生信息已被成功的增加!”<〈endl;
}
void arrayofStu::nad( ) //按姓名删除
{cout〈〈”\t\t\t欢迎使用姓名删除学生功能”〈〈endl;
/*cout〈〈student[0];
cout〈<endl〈〈student[0].name;*/
int fl=0;
int i,j;
string na;
cout〈<”请输入要删除学生的姓名”〈<endl;
cin〉〉na;
for(i=0;i〈count1;i++)
if(na==student[i].name)
{fl=1;break;}
if(fl)
{for(j=i;j〈count1—1;j++)
student[j]=student[j+1];
count1-—;
cout〈<”你已成功删除学生信息”〈〈endl;
}
else
cout〈<”没有这个学生”<〈endl;
}
void arrayofStu::display()
{ int i;
if(count11==0)
cout<〈”暂时还无学生交费"〈〈endl;
else
{cout<〈”已交费人员信息”<〈endl;
cout〈〈”学号 "〈〈”姓名 ”〈〈” 用水量 "〈〈"用电量 "〈<”用煤气量 ”〈〈”水费 ”〈<”电费 ”<〈”煤气费 ”〈〈" 总额 ”<<" 是否交费”<〈endl;
for( i=0;i<count1;i++)
if(student[i]。flag)
cout〈〈student[i];
}
if(count11==count1) cout〈〈"所有学生均以交费”〈〈endl;
else
{cout<<"未交费人员信息”〈<endl;
cout<<"学号 "〈〈"姓名 "<〈" 用水量 ”〈<”用电量 ”〈〈"用煤气量 ”〈〈"水费 ”<<”电费 "〈〈”煤气费 ”〈<" 总额 ”〈<” 是否交费"〈<endl;
for(i=0;i〈count1;i++)
if(!student[i]。flag)
cout〈〈student[i];
}
}
void arrayofStu::numd( ) //按学号删除
{cout<<”\t\t\t欢迎使用学号删除学生功能”<〈endl;
int fl=0;
int i,j;
string num;
cout〈<”请输入要删除学生的学号”〈〈endl;
cin>>num;
for(i=0;i〈count1;i++)
if(num==student[i]。number)
{fl=1;break;}
if(fl)
{for(j=i;j<count1—1;j++)
student[j]=student[j+1];
count1—-;
cout〈〈"你已成功删除学生信息”<〈endl;
}
else
cout<<"没有这个学生”<<endl;
}
void arrayofStu::nacheck( ) //姓名查询
{ cout<<"\t\t\t欢迎使用姓名查询学生功能”<<endl;
int i,fl=0;
string na;
cout〈<”请输入要查找的姓名”〈〈endl;
cin>〉na;
for(i=0;i〈count1;i++)
if(na==student[i].name)
{ fl=1;break;}
if(fl)
{
cout<〈”学号 ”<<"姓名 ”<〈" 用水量 ”〈〈”用电量 "〈<”用煤气量 ”<〈”水费 ”〈<”电费 ”<<"煤气费 ”<<" 总额 ”<<" 是否交费"<〈endl;
cout〈<student[i]〈<endl;}
else
cout〈〈”没有这个学生”<〈endl;
}
void arrayofStu::numcheck() //学号查询
{ cout〈<”\t\t\t欢迎使用学号查询学生功能"〈<endl;
int i,fl=0;
string num;
cout〈<"请输入要查找的学号"<〈endl;
cin>〉num;
for(i=0;i〈count1;i++)
if(num==student[i].number)
{ fl=1;break;}
if(fl)
{
cout<〈”学号 "<<”姓名 ”〈〈” 用水量 ”〈〈”用电量 "〈〈”用煤气量 ”〈<"水费 "〈〈”电费 "〈〈”煤气费 ”<〈” 总额 "<〈" 是否交费”〈〈endl;
cout<〈student[i]〈〈endl;
}
else
cout〈<"没有这个学生”<<endl;
}
void arrayofStu::save()
{ofstream f(”Stu2.txt”);
f<〈"学号 "<〈”姓名 ”<〈” 用水量 "<〈”用电量 ”〈〈"用煤气量 ”<<”水费 ”<<"电费 ”〈<”煤气费 "<〈" 总额 ”<〈” 是否交费”〈〈endl;
for(int i=0;i<count1;i++)
f〈<student[i]<<endl;
f。close();
cout〈<”恭喜你,文件已成功保存”〈〈endl;
}
void arrayofStu::delet() //删除学生菜单
{
int choice;
cout〈〈”\t\t\t\t**************”<〈endl;
cout<〈"\t\t\t\t 删除信息"〈<endl;
cout〈〈"\t\t\t\t 1,按学号删除”<〈endl;
cout〈〈”\t\t\t\t 2,按姓名删除"〈〈endl;
cout〈〈”\t\t\t\t 3,返回主菜单”〈<endl;
cout〈〈”\t\t\t\t 0,返回上一层”<<endl;
cout〈〈”\t\t\t\t**************”<<endl;
while(1)
{
cout〈〈"请输入你的选择”<〈endl;
cin〉〉choice;
switch(choice)
{
case 1: numd(); break; //学号删除
case 2: nad(); break; //姓名删除
case 3: xuesheng(); break; //返回学生管理主菜单
case 0: amend(); break; //返回上一层
}
if(choice==0)
break;
}
}
void arrayofStu::jiaofei() //学生缴费菜单
{
int choice;
cout<〈”\t\t\t\t****************"<〈endl;
cout〈〈"\t\t\t\t*———学生缴费——-*”〈<endl;
cout〈<”\t\t\t\t*1,输入学号交费*"<<endl;
cout<〈”\t\t\t\t*2,输入姓名交费*”〈<endl;
cout〈<”\t\t\t\t*0, 返回上一层 *"<〈endl;
cout<〈”\t\t\t\t****************”〈<endl;
while(1)
{
cout<<"请输入你的选择”〈〈endl;
cin>>choice;
switch(choice)
{ case 1: numj(); break; //输入学号计费
case 2: naj(); break; //输入姓名计费
case 0: xuesheng(); break; //返回上一层
}
if(choice==0)
break;
}
}
void arrayofStu::xuesheng() //学生用户主菜单
{
int choice;
cout<〈”\t\t\t\t欢迎使用学生用户管理系统”〈<endl〈〈endl;
cout<〈”********************************"〈〈endl;
cout〈〈"\t\t\t\t*——-—--1,注册学生—---—-*"〈〈endl;
cout〈<”\t\t\t\t*—-——-—2,修改用户——-——-*”<〈endl;
cout<〈"\t\t\t\t*——————3,缴纳费用——---—*”〈〈endl;
cout〈〈”\t\t\t\t*-—--——4,查询费用—————-*”〈〈endl;
cout〈〈”\t\t\t\t*———--—5,查看交费情况-—*"〈<endl;
cout<〈”\t\t\t\t*——————6,保存信息到文件——*"〈<endl;
cout〈〈”\t\t\t\t*——————0,返回上一层--—-*”〈<endl;
cout〈〈"********************************”〈<endl;
cout〈〈”友情提示:第一次使用时,要进行注册!"〈〈endl〈<endl;
for(;;)
{
cout〈〈”请输入您的选择”〈〈endl;
cin>〉choice;
switch(choice)
{
case 1: regist(); break; //注册
case 2: amend(); break; //修改
case 3: jiaofei(); break; //缴纳费用
case 4: check(); break;
case 5: display(); break;
case 6: save(); break;
case 0: break;
}
if(choice==0) break;
}
}
void arrayofStu::amend() //修改用户菜单
{
int choice;
cout〈〈"\t\t\t\t修改学生信息”〈〈endl<〈endl;
cout<〈"\t\t\t\t1,增加学生 ”<〈endl;
cout<〈"\t\t\t\t2,删除学生 "<〈endl;
cout<<"\t\t\t\t0,回上一层 ”<〈endl;
while(1)
{
cout〈〈”请输入你的选择”<〈endl;
cin>>choice;
switch(choice)
{case 1: add(); break;
case 2: delet(); break;
case 0: xuesheng(); break;
}
if(choice==0)
break;
}
}
void arrayofStu::check() //查询菜单
{
int choice;
cout<<"\t\t 查询学生信息"〈〈endl<<endl;
cout<〈” 1,按姓名查找 ”〈<endl;
cout〈<” 2,按学号查找 "<<endl;
cout<<” 0,返回上一层 ”〈<endl;
cout<<"=============================================”<<endl;
while(1)
{
cout<〈"请输入您的选择"<〈endl;
cin〉〉choice;
switch(choice)
{
case 1: nacheck(); break; //输入姓名查找
case 2: numcheck(); break; //输入学号查找
case 0:xuesheng(); break;//如果是break时分析
}
if(choice==0)break;
}
}
class Teacher //教师
{
public:
Teacher( double xwater=0,double xpower=0,double xgas=0,string xname="a")
{water=xwater;power=xpower;gas=xgas;name=xname;flag=0;}
void operator =(Teacher S); //赋值运算符重载
friend ostream &operator 〈〈(ostream & a,Teacher &S) //插入运算符重载
{
a〈〈setw(6)<<left〈〈S。name;
a<〈setw(6)〈〈left〈〈S。water;
a<〈setw(10)<〈S。power;
a〈<setw(10)〈<S.gas;
a〈<setw(10)<〈S。TGetW();
a〈〈setw(10)<〈S.TGetC();
a<〈setw(10)<<S.TGetG();
a<〈setw(10)<<S。Ttotal();
if(S.flag)
a<〈”已交";
else a<<”未交”;
cout〈<endl;
return a;
}
double TGetW(); //水费计算
double TGetC(); //电费计算
double TGetG(); //煤气费计算
double Ttotal(); //计算总的钱
string name;
double water,power,gas,water_rate,circuit,gas_rate,total;
int flag;
};
void Teacher::operator =(Teacher S) //赋值运算符重载
{
name=S.name;
water=S。water;
power=S。power;
gas=S。gas;
}
double Teacher::TGetW() //计算水费
{
water_rate=3。7*water;
return water_rate;
}
double Teacher::TGetC() //计算电费
{
circuit=0。45*power;
return circuit;
}
double Teacher::TGetG() //计算煤气费
{
gas_rate=1.9*gas;
return gas_rate;
}
double Teacher::Ttotal() //计算应该付的的钱
{
total=TGetW()+TGetC()+TGetG();
return total;
}
class arrayofTeacher //老师类数组计算
{
public:
arrayofTeacher( int sz=1)
{size=sz;teacher=new Teacher[size];}
~arrayofTeacher() {delete [] teacher ; }
void regist(); //注册教工
void jiaogong(); //教工主菜单
void amend( ); //修改用户菜单
void add(); //增加用户
void delet(); // 删除用户
void check(); //查询是否交费
void jiaofei(); //交水电煤气费
// void display(); //展示所有的用户
void display(); //查看交费情况
void save();
private:
int size;
Teacher *teacher;
};
void arrayofTeacher::regist() //教工用户注册
{int i=0;
ifstream f(”Teacher.txt”);
while(f。good())
{
f〉>teacher[i].name;
f〉>teacher[i].water;
展开阅读全文