资源描述
面向对象程序设计课外实践汇报
项 目 名 称: 水电气管理系统
所 在 班 级: 计算机科技和技术
小 组 成 员: 王耀权、董金明
指 导 教 师: 葛文英
起 止 时 间: .11.25——.12.20
项目基础信息
项目名称
设计一个水电气管理系统
项目介绍
1.问题描述
设计一个水电管理信息系统,能够对高校水电费用进行管理,包含登记费用、查询费用和住户信息管理等。在设计时要考虑到学生和教工在用水电时不一样,学生能够无偿使用一定额度水电,超出这个额度水电以后必需自费使用,且自费部分水电费价格标准要高于教工收费标准(关键是节省资源)。
2.基础要求
⑴实现对用户信息录入。
⑵实现水电煤气数据录入。
⑶计算并查询用户应缴费用。
⑷查询未缴纳费用名单。
3.测试数据
可选择小区物业管理部门数据,也可采取手工输入不少于10个用户信息数据。
小组组员
王耀权、董金明
任务分工
这个程序是一起做,王耀权关键做是学生水电气管理系统,
董金明做是老师水电气管理系统,然后再见合改错误,最终一起把这个是试验汇报完成。
一、问题描述及分析:
设计一个水电管理信息系统,能够对高校水电费用进行管理,包含登记费用、查询费用和住户信息管理等。在设计时要考虑到学生和教工在用水电时不一样,学生能够无偿使用一定额度水电,超出这个额度水电以后必需自费使用,且自费部分水电费价格标准要高于教工收费标准(关键是节省资源)。
二、功效模块及结构描述:
功效模块: 1.在主函数中经过分支选择能够跳转不一样功效选项进而实现
2.在显示主菜单函数中,我们经过设计友好界面来和用户进行交互。在“请选择对应功效(1-3):”中使用者输入非1-3数字或其它字符时,系统提醒结束然后从新开始。
3.进入学生管理系统菜单或老师管理系统菜单会出现对应功效(1-6):分别对应有交费功效、查询一个功效、、查询全部功效、增加功效、删除功效。
学生查询功效分别为学号和姓名,老师查询功效为编号和姓名,也能够查询到是否缴费,如未交费就会分别显示水费、电费、煤气费、费用并显示总费用。
4.交费时它会显示费用多少,实际交了多少钱,假如钱交多了显示应找零多少。
结构描述:
1.首先建立了Feebz类,用于初始化身份证号码、姓名、用水电、煤气量,又定义了缴费函数Get(),用在有些人缴费函数体中,从键盘输入缴费用,一开始我们在Get(),中没有对缴费用进行累加,在查询信息时现实应缴费用不正确,经过我们努力,检验犯错误并加以更正,让程序愈加完善。
2.用Feebz类派生出StuMan和|TeaMan类,其中有计算应该缴费用,StuMan类比TeaMan类多了无偿。
3.在保留文件处理中,需考虑到“查询失败”和“重新输入”等很多内容
三、关键步骤描述:
水 电 气 管 理 系 统
选操作对象
退 出 系 统
教 师
学 生
选择操作对象
缴 纳 水 电 气
费
查询一个学生水电气用
量
查询全部学生交费情况
增
加 学 生 信 息
删 除 学 生 信 息
退
出
系
统
缴
纳
水
电
气
费
查询一个老师水电用量
查询全部老师缴费情况
增
加
教
师
信
息
删
除
教
师
信
息
退
出
系
统
退 出
退 出 系 统
步骤图:
选择操作对象
四、使用说明:
程序运行后,进入界面:
在如上所表示界面下,依据提醒进行基础操作。
五、 问题及处理方法
问题1. 认为该系统不足就是不能够实现查看某个人用水量、用电量或用气量中一个和应该支付钱。
问题2还有一个不足就是程序感觉不够简练,有点罗嗦。
处理方法:对于处理这些问题,认为应该定义子函数来提取每个人信息这么就能够实现查看某人用水量、用电量、或用气量一个和应该支付钱。对于问题2这需要有扎实基础功,能全部用最简短源程序代码去处理一个相同问题。
六、 实践总结:
课程设汁过程中碰到了很多麻烦,即使我早有心理准备,但还是令我伤透了脑筋,只怪自己平时看书太少,其实有很多东匹在书上全部能够找到答案,可是还是有部分问題我实在没有措施处理,最终经过老师和同学们努力处理了一个又一个问题。
经过这次课程设计,我学习到了很多知识,而且给了我一个星月时间去重新认真有目标性C++语言进行复习,查找补漏,为后续课程做充足准备。设计过程是困难,因为以前没有类似经验刚开始几天没有太多进展,不过我们没有气馁,经过认真思索和老师帮助,最我们有了很好设设计方法。
程序完成使我们很快乐,全部疲惫己经不算什么了,现在认为要想编写一个好程序真很累,它需要牢靠基础知识作为 铺垫,全部源代码编写输入和每一步调试全部容不得一点马虎,整个牢靠基础是编程最基础需要,要想好每一步算法,要想到每一个对应函数。
我认为一月课程设计远远比我自己看一学期书 收获多,实践是检验知识最隹手段。
七、 源代码:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std;
int ns,nt;
class Feebz // 学生信息类
{
public:
Feebz(string Num="",string Name="董金明",
double water=1,double power=0,double gas=10);
// 结构函数
friend ostream &operator <<(ostream &out,Feebz &r)
//运算符重载
{out<<setw(12)<<left<<r.number;
out<<setw(8)<<left<<r.name;
out<<setw(8)<<left<<r.water;
out<<setw(8)<<left<<r.power;
out<<setw(8)<<left<<r.gas;
out<<setw(8)<<left<<r.GetW();
out<<setw(8)<<left<<r.GetP();
out<<setw(8)<<left<<r.GetG();
out<<setw(8)<<left<<r.GetTotal();
if(r.flag)
out<<"已交";
else
out<<"未交"; return out; }
void operator =(Feebz r); // 运算符重载
double GetW(); // 计算学生水费
double GetP(); // 计算学生电费
double GetG(); // 计算学生气费
double GetTotal() {return GetW()+GetP()+GetG();} // 计算学生总费用
string number,name; int flag;
double water,power,gas,Waterprice,Powerprice,Gasprice; };
Feebz::Feebz(string Num,string Name,
double Water,
double Power,
double Gas) // 结构函数
{number=Num; name=Name; water=Water;
power=Power; gas=Gas; flag=0; }
void Feebz::operator =(Feebz r) // 赋值运算符重载
{name=r.name;
number=r.number;
water=r.water;
power=r.power;
gas=r.gas; }
double Feebz::GetW() // 计算学生水费
{
if(water<=6) Waterprice=0;
else
Waterprice=0.6*(water-6);
return Waterprice; }
double Feebz::GetP() // 计算学生电费
{if(power<=6) Powerprice=0;
else
Powerprice=0.6*(power-6);
return Powerprice; }
double Feebz::GetG() // 计算学生气费
{if(gas<=6) Powerprice=0;
else
Powerprice=0.6*(gas-6);
return Powerprice; }
class StuMan // 学生管理类
{public:
StuMan(int sz=50)
{
size=sz;
St=new Feebz[size];} //结构函数
~StuMan()
{delete [] St;} // 析构函数
void MainMenu(); // 主菜单
void FeeMenu(); // 学生交费菜单
void NumFee(); // 输入学号交费
void NameFee(); // 输入姓名交费
void CheckMenu(); // 学生查询菜单
void NumCheck(); // 输入学号查询
void NameCheck(); // 输入姓名查询
void Add(); // 增加学生功效
void DeleteMenu(); // 学生删除菜单
void NumDelete(); // 输入学号删除
void NameDelete(); // 输入姓名删除
void Regist();
void Chakan(); // 学生查看作用
private:
int size; Feebz *St; };
void StuMan::MainMenu() // 主菜单
{system("cls"); int choice;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆ 水电煤气管理系统 ☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" 欢 迎 使 用 教 师 水 电 气 费 管 理 系 统"<<endl;
cout<<" 1.缴纳水电气费"<<endl;
cout<<" 2.查询一个同学水电气费用量"<<endl;
cout<<" 3.查看全部同学缴费情况"<<endl;
cout<<" 4.增加学生信息"<<endl;
cout<<" 5.删除学生信息"<<endl;
cout<<" 6.退出系统"<<endl;
while(1) {
cout<<"请选择:";
cin>>choice;
switch(choice)
{
case 1:FeeMenu();
break;
case 2:CheckMenu();
break;
case 3:Chakan();
break;
case 4:Add();
break;
case 5:DeleteMenu();
break;
default:
break;
}if(choice==6)
break;
}
}
void StuMan::Regist()
{
int i=0;
ifstream tfile("student.txt");
while(tfile.good())
{
tfile>>St[i].number;
tfile>>St[i].name;
tfile>>St[i].water;
tfile>>St[i].power;
tfile>>St[i].gas; i++;
}
tfile.close(); ns=i;
}
void StuMan::FeeMenu() //学生交费菜单
{
system("cls");
int choice;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆ 水电煤气管理系统 ☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" 学 生 交 费 菜 单"<<endl;
cout<<" 1.根据学号交费"<<endl;
cout<<" 2.根据姓名交费"<<endl;
cout<<" 3.返回主菜单"<<endl;
cout<<" 4.退出系统"<<endl;
while(1)
{
cout<<"请选择:";
cin>>choice;
switch(choice)
{
case 1:NumFee();
break;
case 2:NameFee();
break;
case 3:system("cls");
MainMenu();
break;
default:exit(1);
}
if(choice==3)
break;
}
}
void StuMan::NumFee() // 输入学号交费
{
string number;
float money;
int flag=0,flag1=0;
cout<<"欢迎使用交费功效"<<endl;
cout<<"请输入学生学号:";
cin>>number;
for(int i=0;i<ns;i++)
if(number==St[i].number)
{
flag1=1;
cout<<"该同学应该交费共"<<St[i].GetTotal()<<"元"<<endl;
cout<<"该同学实际交钱:";
cin>>money;
if(money<St[i].GetTotal())
{
cout<<"该同学需再补交"<<St[i].GetTotal()-money<<"元"<<endl;
St[i].flag=0; MainMenu(); }
else
{
cout<<"该同学交费成功,且找零钱为"<<money-St[i].GetTotal()<<"元"<<endl;
St[i].flag=1; MainMenu();
}
break;
}
if(!flag1)
{
system("cls");
cout<<"该学生学号输入错误,请重新使用该功效!"<<endl;
NumFee();
}
}
void StuMan::NameFee() // 输入姓名交费
{
string name;
float money;
int flag=0,flag1=0;
cout<<" 欢迎使用交费功效"<<endl;
cout<<"请输入学生姓名:";
cin>>name;
for(int i=0;i<ns;i++)
if(name==St[i].name)
{
flag1=1;
cout<<"该同学应该交费共"<<St[i].GetTotal()<<"元"<<endl;
cout<<"该同学实际交钱:";
cin>>money;
if(money<St[i].GetTotal())
{
cout<<"该同学需再补交"<<St[i].GetTotal()-money<<"元"<<endl;
St[i].flag=0; MainMenu();
}
else
{
cout<<"该同学交费成功,且找零钱为"<<money-St[i].GetTotal()<<"元"<<endl;
St[i].flag=1;
MainMenu();
}
break;
}
if(!flag1)
{
system("cls");
cout<<"该学生姓名输入错误,请重新使用该功效!"<<endl;
NameFee();
}
}
void StuMan::CheckMenu() // 学生查询菜单
{
system("cls"); int choice;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆ 水电煤气管理系统 ☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" 学 生 查 询 菜 单"<<endl;
cout<<" 1.根据学号查询"<<endl;
cout<<" 2.根据姓名查询"<<endl;
cout<<" 3.返回主菜单"<<endl;
cout<<" 4.退出系统"<<endl;
while(1) {
cout<<"请选择:"<<endl;
cin>>choice;
switch(choice)
{
case 1:NumCheck();
break;
case 2:NameCheck();
break;
case 3:system("cls");
MainMenu();
break;
default:exit(1);
}
if(choice==3)
break;
}
}
void StuMan::NumCheck() // 输入学号查询
{
string number;
int flag1=0,i,item;
cout<<"欢迎使用查询功效"<<endl;
cout<<"请输入需要查找学生学号:";
cin>>number;
for(i=0;i<ns;i++)
if(number==St[i].number)
{
flag1=1;
item=i;
break;
}
if(flag1)
{
cout<<"学号 "<<"姓名"<<"用水量 "<<"用电量 "<<"用煤气量 "<<"水费 "<<"电费 "<<"煤气费 "<<" 总额 "<<" 交费否"<<endl;
cout<<St[item]<<endl;
}
else
{
system("cls");
cout<<"该学生学号输入错误,请重新使用该功效!"<<endl;
NumCheck(); } }
void StuMan::NameCheck() // 输入姓名查询
{
string name;
int flag1=0,i,item;
cout<<"欢迎使用查询功效"<<endl;
cout<<"请输入需要查找学生姓名:";
cin>>name;
for(i=0;i<ns;i++)
if(name==St[i].name)
{
flag1=1; item=i;
break;
}
if(flag1)
{
cout<<"学号"<<"姓名"<<" 用水量"<<"用电量 "<<"用煤气量 "<<"水费"<<"电费 "<<"煤气费 "<<" 总额 "<<" 交费否"<<endl;
cout<<St[item]<<endl;
}
else
{
system("cls");
cout<<"该学生学号输入错误,请重新使用该功效!"<<endl;
NameCheck();
}
}
void StuMan::DeleteMenu() // 学生删除菜单
{
system("cls");
int choice;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆ 水电煤气管理系统 ☆"<<endl;
cout<<" ☆ ☆"<<endl;
cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<" 学 生 删 除 菜 单"<<endl;
cout<<" 1.根据学号删除"<<endl;
cout<<" 2.根据姓名删除"<<endl;
cout<<" 3.返回主菜单"<<endl;
cout<<" 4.退出系统"<<endl;
while(1)
{
cout<<"请选择:";
cin>>choice;
switch(choice)
{
case 1:NumDelete();
break;
case 2:NameDelete();
break;
case 3:system("cls");
MainMenu();
break;
default:exit(1);
}
if(choice==3)
break;
}
}
void StuMan::NumDelete() // 输入学号删除
{
string number;
int item=1,i,j;
cout<<"欢迎使用删除功效"<<endl;
cout<<"请输入要删除学生学号:";
cin>>number;
for(i=0;i<ns;i++)
if(number==St[i].number)
{
item=0; j=i;
break;
}
if(!item)
{
for(j=i;j<ns-1;j++)
St[j]=St[j+1];
cout<<"该学生信息已被删除!"<<endl;
}
if(item) {system("cls");
cout<<"该学生学号输入错误,请重新使用该功效!"<<endl;
NumDelete(); } }
void StuMan::NameDelete() // 输入姓名删除
{
string name;
int item=1,i,j;
cout<<"欢迎使用删除功效"<<endl;
cout<<"请输入要删除学生姓名:";
cin>>name;
for(i=0;i<ns;i++)
if((name==St[i].name))
{
item=0; j=i;
break;
}
if(!item)
for(j=i;j<ns-1;j++)
St[j]=St[j+1];
cout<<"该学生信息已被删除!"<<endl;
if(item) {system("cls");
cout<<"该学生姓名输入错误,请重新使用该功效!"<<endl;
NameDelete();
}
}
void StuMan::Add() // 增加学生功效
{
int n,i,j=1;
cout<<"请输入你要增加学生数:";
cin>>n;
i=ns;
for(;ns<i+n;ns++)
{cout<<"请输入第"<<j<<"个学生学号、姓名、水用量、电用量、用气量:"<<endl;
cin>>St[ns].number;
cin>>St[ns].name;
cin>>St[ns].water;
cin>>St[ns].power;
cin>>St[ns].gas;
j++;
}
}
void StuMan::Chakan() // 学生查看功效
{
int i;
cout<<"已交费学生信息"<<endl;
cout<<"学号 "<<"姓名 "<<" 用水量"<<"用电量"<<"用煤气量 "<<"水费 "<<"电费"<<"煤气费"<<" 总额 "<<" 交费否"<<endl;
for( i=0;i<ns;i++)
if(St[i].flag)
cout<<St[i];
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"未交费学生信息"<<endl;
cout<<"学号"<<"姓名"<<" 用水量"<<"用电量 "<<"用煤气量"<<"水费 "<<"电费 "<<"煤气费"<<" 总额 "<<" 交费否"<<endl;
for(i=0;i<ns;i++)
if(!St[i].flag)
cout<<St[i];
}
class TFeebz // 老师信息类
{
public:
TFeebz(string Num="01",string Name="王耀权",double water=1,double power=0,double gas=10) ;
friend ostream &operator <<(ostream &out,TFeebz &r) // 运算符重载
{
out<<setw(12)<<left<<r.number;
out<<setw(8)<<left<<r.name;
out<<setw(8)<<left<<r.water;
out<
展开阅读全文