用C++ 实现水电煤气管理
- 格式:doc
- 大小:118.00 KB
- 文档页数:22
C++ 课程设计报告题目:水费管理系统——水费基本信息管理、查询、统计、存盘和收费管理学生姓名:学号:专业班级:同组姓名:指导教师:设计时间: 2008年下学期第15~16周指导老师意见:评定成绩: 签名: 日期:1 系统(项目)设计1.1 系统功能模块图通过查阅相关资料和仔细分析,得出系统功能模块图如图1所示。
系统主要由用户信息管理、收费管理、查询与统计、存盘等几个功能模块组成,我负责的是收费管理、查询与统计、存盘功能。
其中收费管理包括用户本月用水量、本月所收水费、收费时间,查询与统计包括用户信息查询与收费查询与统计,存盘包括用户信息和收费信息存盘。
1.2 系统登陆模块系统登陆模块主要完成系统登陆和系统退出功能。
其详细流程图如图2所示。
1、密码输入;2、判断密码的正确与否,即当前用户是否具有进入系统运行的权限;3、主菜单中选择1、2、3、4,分别进入用户基本信息管理、收费管理、查询与统计、存盘操作;4、密码错误或主菜单中选择0,退出程序;1.3 收费管理收费管理模块主要完成对用户进行收费的功能,该模块包含用户本月所收水费、存盘等功能。
其流程图如图3所示。
1.3.1 子菜单2模块1、从子菜单2中选择1、2分别进入本月所收水费、存盘操作;2、选择0,返回主菜单。
1.3.2 本月所收水费模块该模块主要完成对用户本月收取水费的功能,其流程图如图 4所示。
1. 进入子菜单 2中选择 1,进行用户信息的添加;2. 键盘输入要收水费用户的编、名称、收费时间和本月用水量,计算对该用户所收水费;3. 一次用户信息输入完成,系统回到上一级菜单,提示存盘;4. 输入2,进行存盘。
1.3.3 存盘模块该模块主要完成用户收费信息的存盘,详情见流程图5.所示。
1、子菜单2中选择2,进行添加用户信息和所收水费存盘;2、继续输入用户信息或返回上级菜单。
1.4 查询与统计模块查询、统计模块主要完成对用户基本信息的和收费信息的查询和统计的功能,详情见流程图6所示。
项目报告——水电气费查询及充值系统谢培伟本系统是是面向学生及管理员而开发的,也就是说,本系统共有两个大端口:学生端、管理端。
学生端:学生端是针对学生生活查询及充值缴费而设计的,内分为原用户登录及新用户注册两块,学生的数据是利用文件操作储存在xstdate.dat文件。
管理端:管理端的设计则方便了管路员对学生账户数据的修改与查询。
程序流程图:本人主要负责学生端的学生登录密码的判断、水电气费的查询及充值,其中变量t是用来读取用户是进入学生端还是管理端,变量xs是判断用户是登录还是注册,用jm=strcmp(xsdbmm,xsdlmm)来判断密码的正确性,变量xstzh是登陆后用来读取用户进哪个服务的。
为了能使用户能返回到上一层,我们后来使用了goto语句,这也给我们带来不必要的麻烦,例如,用户修改了自己的数据后使用goto返回上一层时,系统它不会储存修改后的数据,后来,我们只能在每个goto执行前就用文件操作先储存起来,则加上xstdate=fopen("xstdate.dat","w");/*修改后把学生账号信息写入xstdate.dat*/for(i=0;i<50;i++){fwrite(&xsd[i],sizeof(xsd[i]),1,xstdate);}fclose(xstdate);这样就使程序更加繁琐了。
源代码中的xpw()为{printf("\n");/*系统初始界面*/printf("**************************\n");printf(" **欢迎使用水电气管理系统**\n");printf("**************************\n");printf("\n");}是为了修饰整个执行局面。
代码中的xstczs、xstczd、xstczq分别为水、电、气充值的量,将充值的量加上原先的量再赋值储存,就完成了水电气费的充值。
课程设计报告课程设计题目:水电煤气管理系统一.问题描述:设计一个水电管理信息系统,能够对高校的水电费用进行管理,包括了登记费用,查询费用,以与住户信息管理等。
在设计时要考虑到学生和教工在用水电时的不同,学生可以免费使用一定额度的水电,超过这个额度的随便以后必须自费使用,且自费部分水电费的价格标准要高于教工的收费标准(主要是节约资源)。
二.设计思路:(一)程序功能:1.实现对用户信息的录入2.实现水电煤气数据的录入3.计算并查询用户应缴费用4.查询未缴纳费用(二)程序说明:1.在主函数过分支选择可以跳转不同的功能选项进而实现2.在显示主菜单函数中,我们通过设计友好界面来与用户进行交互。
在“请选择相应功能(0-4):”中使用者输入非0-4数字或其他字符时,系统提示“请检查您输入的数字在0~4之间!请在输入一遍!”的信息,以帮助用户进行正确选择。
3.首先建立了User类,用于初始化、、用水电、煤气量,又定义了缴费函数setMonery(),用在有人缴费的函数体中,从键盘输入缴的费用,一开始我们在setMoney(),中没有对缴的费用进行累加,在查询信息时现实的应缴费用不正确,经过我们的努力,检查出错误并加以改正,让程序更加完善。
4.用User类派生出Student和|Teacher类,其中有计算应该缴的费用,Student类比Teacher类多了免费。
5.在保存文件的处理中,需考虑到“创建保存文件失败!”和“已成功保存文件!”等诸多容。
(三)文件类型:(1) Constant.h用于存放收费标准。
(2) File.cpp该文件中有两个类:.1.StuFile类,主要用于对学生信息的操作函数属性注释Public StuFile() 构造函数Public void add(Student&s)将S添加到文件中Public void display() 依次显示所有的学生的信息Public Student*gerStudent(stringid) 得到学号为id的学生的对象指针Public ~StuFile() 析构函数,释放资源,并把数组中的信息存进文件Public void wjf() 未缴费的学生的Private vector<Student>*stuList;学生信息的向量数组,用于保存所有学生的信息2 TeacherFile 类,主要用于对教工信息的操作Public TeacherFile() 构造函数Public voidadd(Teacher&s)将s添加到文件中Public void display() 依次显示所有的教师信息Public Teacher*getTeacher(string id) 得到编号为id的教师的对象指针Public ~TeacherFile() 析构函数,释放资源,并把数组中的信息存进文件Public v oid wjf() 未交费的教工人员Private Vector<Teacher>*teaLisr 教工的向量数组,用于保存所有教工的信息(3)Main.cpp函数属性注释void init() 新建一个学生或者教工的信息void select() 查询界面,根据用户的输入来显示用户想查询的信息void add() 信息的录入,录入学生或者教工的水电煤气信息void handed() 缴费,有学生或者教工缴费的时候调用此函数int mainMenu() 主菜单,显示一个菜单,返回用户的输入void work() 程序开始工作int main() 主函数,程序的入口(4)Student.cppClass Student:virtual public User函数属性注释Public Student():User(“”,””,0,0,0) 构造函数Public Student(string i,string n,Float w=0,float p=0,floatg=0):User(i,n,w,p,g) 构造函数i:学号n:Public void display() 依次显示所有的学生的信息Public float display() 返回学生应缴的费用Private float freeWater; 学生免费使用的水量Private float freePower; 学生免费使用的电量Private float freeGas; 学生免费使用的煤气量Private float money; 缴费(5)Teacher.cppClass Teacher:virtual public User函数属性注释Public Teacher(string构造函数i,string n,float w=0,floatp=0,floatg=0):User(I,n,w,p,g)Public void display() 依次显示所有的教工信息Public float getMoney() 返回教工应缴的费用(6)User.cpp函数属性注释构造函数Public User(string i,stringn,floatw=0,float p=0,float g=0)Public string getId() 获取编号Public string getName() 获取Public void setId(string i) 设置编号Public void setName(string n) 设置Public void setWater(float w) 设置水量Public void setPower(float p) 设置电量Public void setGas(float g) 设置煤气量Public float getWater() 使用水量Public virtual void display()=0; 依次显示所有信息Public void setMoney(float m) 缴费Public virtual float getMoney()=0; 应缴费用(四)UML图:StuFile+id:string+name:string+useWater:float+usePower:float+useGas:float+money:float+add():void+display():void+wjf():voidStudent-freeWater:float-freePower:float-freeGas:float+display():void+getMoney():voidUser+i:string+n:string+w:float+p:float+g:float+getId():string+getName():string+setId(string i) :string+setName(string n) :string+setWater(float w) :float+setPower(float p) :float+setGas(float g) :float+getWater():float三.程序代码:Constant.h//收费标准#ifndef Constant#define Constant//教师const static float TwaterUnit=1;const static float TpowerUnit=1;const static float TgasUnit=1;//学生const static float SwaterUnit=1;const static float SpowerUnit=1;const static float SgasUnit=1;//保存学生信息的文件const static char* stuFlieName="s.txt";//保存教师信息的文件const static char* teaFileName="t.txt";#endifMain.cpp#include<iostream>#include<iomanip>#include<string>#include<vector>#include"Student.cpp"#include"Teacher.cpp"#include"File.cpp"using namespace std;void init(){cout<<endl;cout<<"1.新建教工信息\n"<<"2.新建学生信息\n"<<endl;cout<<"请选择你要进行的操作:"<<endl;int o;cin>>o;if(o==1){string id;string name;cout<<"请输入新教工的号:";cin>>id;cout<<"请输入新教工的:";cin>>name;Teacher t(id,name);TeacherFile tf;tf.add(t);}else if(o==2){string id;string name;cout<<"请输入新学生的号:";cin>>id;cout<<"请输入新学生的:";cin>>name;Student s(id,name);StuFile sf;sf.add(s);}elsereturn ;}void select(){cout<<endl;cout<<"1.学生的信息\n"<<"2.教师的信息\n"<<"3.按号查询\n"<<"4.未缴费的人员\n"<<"5.不进行任何的操作\n"<<endl;cout<<"请输入你要进行的操作:";int o;cin>>o;StuFile sf;TeacherFile tf;if(o==1){cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;sf.display();}else if(o==2){cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;tf.display();}else if(o==3){User *user;StuFile sf;TeacherFile tf;string id;cout<<"请输入他的号:";cin>>id;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息为:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();}else if(o==4){sf.wjf();tf.wjf();}elsereturn ;}void add(){cout<<"1.对教工使用的水电煤气信息的录入"<<endl <<"2.对学生使用的水电煤气信息的录入"<<endl<<"3.不进行任何操作"<<endl;cout<<"请输入你要进行的操作:"<<endl;int o;cin>>o;string id;float water;float power;float gas;if(o==1||o==2){User*user;StuFile sf;TeacherFile tf;cout<<"请输入他的号:";cin>>id;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();cout<<"请输入他的用水量:";cin>>water;cout<<"请输入他的用电量:";cin>>power;cout<<"请输入他的用煤气量:";cin>>gas;user->setWater(water);user->setPower(power);user->setGas(gas);}elsereturn ;}void handed(){cout<<"请输入要缴费的人的号:";string id;cin>>id;User*user;StuFile sf;TeacherFile tf;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();cout<<"请输入他的缴费金额:";float money;cin>>money;user->setMoney(money);cout<<"缴费成功\n";}int mainMenu(){cout<<endl<<endl;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<<" 0.退出系统"<<endl;int a;char c[20];do{cout<<" 请选择相应的功能(0-4):"<<endl;cout<<endl;cin>>a;gets(c);if(a<0||a>4){cout<<endl<<endl;cout<<"请确认您输入的数字在0~4之间!"<<endl;cout<<"请重新输入一遍!"<<endl<<endl;}}while(a<0||a>4);return a;}void work(){switch(mainMenu()){case 1:init();break;case 2:select();break;case 3:add();break;case 4:handed();break;default:break;}}void Menu(){cout<<endl;cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆水电煤气管理系统☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆振坡☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;cout<<endl;system("pause");system("cls");}void main(){system("color 3A");Menu();char a='y';while(a=='y'){work();cout<<"是否继续使用该系统(y/n)"<<endl;cin>>a;}}File.cpp//StuFile类,对学生信息的操作//TeacherFile类,对教工信息的操作#include<iostream>#include<iomanip>#include<fstream>#include<vector>#include<string>#include"Student.cpp"#include"Teacher.cpp"#include"User.cpp"#include"Constant.h"#ifndef StuFile_class#define StuFile_classclass StuFile{vector<Student> *stuList;public :string id;string name;float useWater;float usePower;float useGas;float money;StuFile(){stuList=new vector<Student>;ifstream *is=new ifstream("StuFileName",ios_base::in);if(is==0){cout<<"打开文件失败!"<<endl;return ;}else{while(is->good()){Student s("","");is->read((char*)&s,sizeof(Student));if(s.getId() !=""){stuList->push_back(s);}}}is->close();}void add(Student &s){stuList->push_back(s);}void display(){for(int i=0;i<stuList->size();i++){Student s=stuList->at(i);s.display();}}Student *getStudent(string id){for(int i=0;i<stuList->size();i++){if(stuList->at(i).getId()==id)return &stuList->at(i);}return 0;}~StuFile(){if(stuList !=NULL && !stuList->empty()){ofstream os("stuFileName",ios_base::out);for(int i=0;i<stuList->size();i++){if(stuList->at(i).getId() !="")os.write((char*)&stuList->at(i),sizeof(Student));}os.close();delete stuList;}}void wjf(){cout<<"未缴费的学生:"<<endl;for(int i=0;i<stuList->size();i++){Student s=stuList->at(i);if(s.getMoney()>0){cout<<"该学生的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴纳的费用"<<endl;s.display();}}}};#endif#ifndef TeaFile_class#define TeaFile_classclass TeacherFile{vector<Teacher> *teaList;public:TeacherFile(){teaList=new vector<Teacher>;ifstream*is=new ifstream(teaFileName,ios_base::in);if(is==0){cout<<"打开文件失败!"<<endl;return ;}else{while(is->good()){Teacher s("","");is->read((char*)&s,sizeof(Teacher));if(s.getId() !=""){teaList->push_back(s);}}}is->close();}Teacher *getTeacher(string id){for(int i=0;i<teaList->size();i++){if(teaList->at(i).getId()==id)return &teaList->at(i);}return 0;}void wjf(){cout<<"教工未缴费的人员:"<<endl;for(int i=0;i<teaList->size();i++){Teacher t=teaList->at(i);if(t.getMoney()>0){cout<<"该教师的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;t.display();}}}void display(){for(int i=0;i<teaList->size();i++){Teacher t=teaList->at(i);t.display();}}void add(Teacher &s){teaList->push_back(s);}~TeacherFile(){if(teaList !=NULL && !teaList->empty()){ofstream os(teaFileName,ios_base::out);for(int i=0;i<teaList->size();i++){if(teaList->at(i).getId() !="")os.write((char*)&teaList->at(i),sizeof(Teacher));}os.close();delete teaList;}}};#endifStudent.cpp#ifndef STUDENT_CLASS#define STUDENT_CLASS#include<iostream>#include<iomanip>#include<string>#include"Constant.h"#include"User.cpp"using namespace std;class Student:virtual public User{private :float freeWater;float freePower;float freeGas;public :Student():User("","",0,0,0){freeWater=1;freePower=2;freeGas=3;}Student(string i,string n,float w=0,float p=0,float g=0):User(i,n,w,p,g){}void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}float getMoney(){float w=SwaterUnit*((useWater>freeWater)?(useWater-freeWater):0);float p=SpowerUnit*((usePower>freePower)?(usePower-freePower):0);float g=SgasUnit*((useGas>freeGas)?(useGas-freeGas):0);return w+p+g-money;}};#endifTeacher.cpp#include"User.cpp"#include"Constant.h"#ifndef Teacher_class#define Teacher_classclass Teacher:virtual public User{public :Teacher(string i,string n,float w=0,float p=0,float g=0):User(i,n,w,p,g){}void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}float getMoney(){float w=TwaterUnit* useWater;float p=TpowerUnit* usePower;float g=TgasUnit* useGas;return w+p+g-money;}};#endifUser.cpp#include<iostream>#include<iomanip>#include<string>using namespace std;#ifndef USER_CLASS#define USER_CLASSclass User{protected :string id;string name;float useWater;float usePower;float useGas;float money;public :User(string i,string n,float w=0,float p=0,float g=0) {id=i;name=n;useWater=w;usePower=p;useGas=g;money=0;}string getId(){return id;}string getName(){return name;}void setId(string i){id=i;}void setName(string n){name=n;}void setWater(float w){useWater=w;}void setPower(float p){usePower=p;}void setGas(float g){useGas=g;}float getWater(){return useWater;}virtual void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}virtual void setMoney(float m){money +=m;}virtual float getMoney()=0;};#endif四.测试结果:界面一:欢迎界面界面二:程序功能表界面三:新建用户信界面四:信息查询界面五:信息的录入界面六:缴费五.实验心得:课程设计的过程中遇到了很多麻烦,虽然我早有心理准备,但还是令我伤透了脑筋,只怪自己平时看书太少,其实有很多东西在书上都可以找到答案的,可是还是有一些问题我实在没有办法解决,最终通过老师和同学们的努力解决了一个又一个的问题。
简易水电费管理系统源程序代码法一:#include<stdio.h>#include<string.h>#include<stdlib.h>struct member{char no[100];char name[20];char password[20];float wfee;float efee;}memb;void newadd(int n){ int t,i;fseek(fp,0,SEEK_END);printf(">>新添人数:");scanf("%d",&t);for(i=0;i<t;i++){ printf("新添第%d个成员:");scanf("%s %s %s %f %f",memb.no,,memb.password,memb.wfee,memb.efee); fwrite(&memb,sizeof(struct member),1,fp);}}void look(int n){ char a[100];printf(">>输入卡号:");scanf("%s",a);int i=0;rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)||memb.no==a) break;i++;}if(!feof(fp)){ printf(">>卡号:");printf("%s\n",memb.no);printf(">>姓名:");printf("%s\n",");printf(">>水费:");printf("%f\n",memb.wfee);printf(">>电费:");printf("%f\n",memb.efee);}elseprintf(">>查无此人\n");};void delete(int n){ char c[100];printf(">>删除的卡号:");scanf("%s," c);if((fp1=fopen("temp.bin","wb"))==NULL){printf(">>不能建立临时文件,无法删除\n");}rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)) break;if(memb.no!=c)fwrite(&memb,sizeof(struct member),1,fp1);}fclose(fp1);fclose(fp);remove("member.bin");rename("temp.bin","member.bin");fp=fopen("member.bin","rb++");};main(){ char a[100]; char b[20];FILE *fp;printf("欢迎进入水电费管理系统\n")int i=0,sel=1;if((fp=fopen("member.bin","wb++"))==NULL){ printf(">>不能建立member.bin文件\n");return(0);}while(sel!=0){ printf("| 1 | 2 | 3 | 4 |\n"); printf("| ------------------------------------------------------------ |\n"); printf("|新添成员|查找个人信息|删除成员|退出|\n); fseek(fp,0,SEEK_END);scanf("%d",&sel);switch(sel){ case 1:newadd(sel); break;clscr(); exit(0);case 2:printf("请输入您的卡号:");printf("%s",a);printf("请输入您的密码:");puts(b);while(strcmp(a,memb.no)==0&&strcmp(b,memb.password)==0)look(sel);printf("您的输入有误\n"); break;clscr();exit(0);case 3:delete(sel); break;clscr();exit(0);}法二:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<windows.h>#include<conio.h>struct member{char no[100];char name[20];char password[20];float wfee;float efee;}memb;void newadd(int n){ int t,i;FILE *fp;fp=fopen("e:\\member.bin","a");fseek(fp,0,SEEK_END);printf(">>新添人数:");scanf("%d",&t);for(i=0;i<t;i++){ printf("新添第%d个成员:",i+1);scanf("%s %s %s %f %f",memb.no,,memb.password,&memb.wfee,&memb.efee); fwrite(&memb,sizeof(struct member),1,fp);}fclose(fp);}void look(int n){ char a[100],b[20]; FILE *fp;int i;fp=fopen("e:\\member.bin","rb");if(fp==NULL) printf("****");printf(">>输入卡号:");scanf("%s",a);i=0;rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)||strcmp(memb.no,a)==0) break;i++;}if(!feof(fp)){ printf(">>卡号:");printf("%s\n",memb.no);printf(">>姓名:");printf("%s\n",);printf(">>水费:");printf("%f\n",memb.wfee);printf(">>电费:");printf("%f\n",memb.efee);}elseprintf(">>查无此人\n");getch();fclose(fp);}void dele(int n){ char c[100];FILE *fp,*fp1;fp=fopen("e:\\member.bin","rb");printf(">>删除的卡号:");scanf("%s" ,c);if((fp1=fopen("temp.bin","wb"))==NULL){printf(">>不能建立临时文件,无法删除\n");}rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)) break;if(strcmp(memb.no,c)!=0)fwrite(&memb,sizeof(struct member),1,fp1);} fclose(fp1);fclose(fp);remove("member.bin");rename("temp.bin","member.bin");fp=fopen("member.bin","rb+");}main(){ char a[100]; char b[20];int i=0,sel=1;FILE *fp;printf("欢迎进入水电费管理系统\n");if((fp=fopen("e:\\member.bin","wb"))==NULL){ printf(">>不能建立member.bin文件\n");return(0);}while(sel!=0){ printf("| 1 | 2 | 3 | 4 |\n"); printf("| ------------------------------------------------------------ |\n"); printf("|新添成员|查找个人信息|删除成员|退出|\n"); fseek(fp,0,SEEK_END);scanf("%d",&sel);printf("sel=%d\n",sel);switch(sel){ case 1:newadd(sel);system("cls"); break;case 2:look(sel);system("cls"); break;case 3:dele(sel);system("cls");break;}}}。
xx大学【实验目的和要求】:1、利用所学过的C语言编程的基本知识如综合顺序、分支、循环结构和函数,以及数组、指针、结构体和共用体、文件等进行编程,较全面的掌握C语言的知识。
2、初步掌握输入、输出、查找、排序的编程方法。
3、逐步掌握C语言编程基本方法和技能。
【实验内容】:编写程序,从键盘输入某宿舍楼6家用户某月的水电消耗量及水费和电费标准,计算各户应缴纳的水费和电费。
(1)水费标准为:1.5元/吨,电费标准为:0.5元/度.。
将信息组织在文件input.dat中:1.5 0.5101 5 150102 4 90103 4 120104 3 78105 5 60106 6 105(2)分别计算各户应缴纳的水费和电费及应缴纳的水费和电费的总和。
(3)汇总全部住户水费电费的总和。
(4)将结果写入文件charge.dat中。
【源程序】//王灵艳0900820305#include<stdio.h>#define NULL 0FILE *fp1,*fp2;struct yong_hu{float price[2];int addr[5];int water[6];int elect[6];}yonghu[6];struct fei_yong{int addr[5];int water[6];float water_1[6];int elect[6];float elect_1[6];float sum[6];float total[5];}fei_yong [6];void main(){void input();void output();int i,j;float a,b,c[5]={0.0};input();fp1=fopen("input.dat","rb");for(i=0;i<6;i++){fread(&yonghu[i],sizeof(struct yong_hu),1,fp1);*fei_yong[i].water_1=(*yonghu[0].price)*(*yonghu[i].water);a=*fei_yong[i].water_1;*fei_yong[i].elect_1=(*yonghu[1].price)*(*yonghu[i].elect);b=*fei_yong[i].elect_1;*fei_yong[i].sum=a+b;c[0]+=*yonghu[i].water;c[1]+=a;c[2]+=*yonghu[i].elect;c[3]+=b;c[4]+=*fei_yong[i].sum;for(j=0;j<5;j++)*fei_yong[j].total=c[j];*fei_yong[i].addr=*yonghu[i].addr;*fei_yong[i].water=*yonghu[i].water;*fei_yong[i].elect=*yonghu[i].elect;}output();printf("住户地址水耗(吨) 水费(元) 电耗(度) 电费(元) 合计(元)\n");for(i=0;i<6;i++)printf("%3d %8d %8.1f %5d %7.1f %7.1f\n",*yonghu[i].addr,*fei_yong [i].water,*fei_yong [i].water_1,*fei_yong [i].elect,*fei_yong [i].elect_1,*fei_yong [i].sum);printf("Total");for(i=0;i<5;i++)printf("%9.1f",*fei_yong[i].total);printf("\n");}void input(){int i;printf("Please enter the number:\n");scanf("%f%f",&yonghu[0].price,&yonghu[1].price);for(i=0;i<6;i++){scanf("%d%d%d",yonghu[i].addr,yonghu[i].water,yonghu[i].elect);}if((fp1=fopen("input.dat","wb"))==NULL){printf("cannot open file\n");return;}for(i=0;i<6;i++)if(fwrite(&yonghu[i],sizeof(struct yong_hu),1,fp1));elseprintf("file write error\n");fclose(fp1);}void output(){int i;if((fp2=fopen("charge.dat","wb"))==NULL){printf("cannot open file\n");return;}for(i=0;i<6;i++)if(fwrite(&fei_yong [i],sizeof(struct fei_yong ),1,fp2));elseprintf("file write error\n");fclose(fp2);}【运行结果贴图】。
c语言编亏一个月度收费系统,功能包括计算电费、水费、燃气费。
1. 首先确定需要输入的数据。
根据收费系统的功能,输入数据应该包括电费、水费、燃气费的使用量。
这些信息可以通过键盘输入,或者从文件中读取。
2. 定义变量。
根据上一步确定的需要输入的数据,定义相关的变量,如电费、水费、燃气费的使用量变量。
还需要定义一些常量,如电费、水费、燃气费的单价。
3. 计算费用。
根据上一步定义的变量和常量,计算出电费、水费、燃气费的总量和总费用。
需要注意的是,在计算时需要判断输入的数据是否合法(如使用量是否为正数,是否超出了合理范围等),避免出现计算错误。
4. 输出结果。
将计算出来的费用输出到屏幕上,或者写入文件中。
5. 完善用户交互界面。
可以加入菜单、选择功能等,使用户操作更加方便。
下面是一份简单的代码示例,仅供参考:#include <stdio.h>// 定义电费、水费、燃气费的单价常量#define ELECTRIC_PRICE 0.5#define WATER_PRICE 1.2#define GAS_PRICE 2.0int main() {// 定义电费、水费、燃气费的使用量变量float electric, water, gas;// 输入电费、水费、燃气费的使用量printf("请输入电费使用量(度):");scanf("%f", &electric);printf("请输入水费使用量(吨):");scanf("%f", &water);printf("请输入燃气费使用量(立方米):");scanf("%f", &gas);// 计算费用float electricFee = electric * ELECTRIC_PRICE;float waterFee = water * WATER_PRICE;float gasFee = gas * GAS_PRICE;float totalFee = electricFee + waterFee + gasFee;// 输出费用printf("电费:%f 元\n", electricFee);printf("水费:%f 元\n", waterFee);printf("燃气费:%f 元\n", gasFee);printf("总费用:%f 元\n", totalFee);return 0;}当然,这只是一个简单示例,如果实际使用时还需要加入其他功能或优化代码,可以根据实际需要进行修改。
青岛理工大学C ++面向对象课程设计报告院(系):计算机工程学院专业:软件工程学生姓名:* * *班级* * * * 学号:20 13 0 7 * * * 题目:高校水电费管理系统设计起迄日期:_ 2 0 1 5 . 6 . 2 9 ~ 2 0 1 5 . 7 . 10设计地点:计算机学院机房指导教师:完成日期 : 2 01 5 年 7 月 1 0 日《C++面向对象课程设计》任务书题目9“高校水电费管理系统设计”1、问题描述住宿学生信息包括:学号、姓名、性别、年龄、班级、用电量、用水量等信息。
教工信息包括职工号、姓名、性别、年龄、工作部门、用电量、用水量等信息。
能计算出学生和教工每月所要交的电费和水费。
定义一个人员类,实现学生和教工共同的信息和行为。
2、功能要求( 1 )添加功能:程序能够添加不同学生和教工的记录,提供选择界面供用户选择所要添加的类别,要求编号号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加。
( 2 )查询功能:可根据姓名、用水量、用电量信息对已添加的学生或教工记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息。
( 3 )显示功能:可显示当前系统中所有学生和教工的记录,每条记录占据一行。
( 4 )编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。
( 5 )删除功能:主要实现对已添加的学生或教工记录进行删除。
如果当前系统中没有相应的记录,则提示“记录为空!”并返回操作。
( 6 )统计功能:能根据多种参数进行统计。
能统计学生和教工的用水用电量、所要交纳的电费和水费、未交纳水电费的人员信息等。
( 7 )保存功能:可将当前系统中各类记录存入文件中,存入方式任意。
( 8 )读取功能:可将保存在文件中的信息读入到当前系统中,供用户进行使用。
( 9 )计算电费和水费。
学生每月都有一定额度的水电是免费使用的,超过的部分需要交费。
3、问题的解决方案根据系统功能要求,可以将问题解决分为以下步骤:( 1 )应用系统分析,建立该系统的功能模块框图以及界面的组织和设计;( 2 )分析系统中的各个实体及它们之间的关系;( 3 )根据问题描述,设计系统的类层次;( 4 )完成类层次中各个类的描述;( 5 )完成类中各个成员函数的定义;( 6 )完成系统的应用模块;( 7 )功能调试;( 8 )完成系统总结报告。
课程设计报告课程设计题目:水电煤气管理系统学生:专业:网络工程班级:10211303指导教师:林2011年 11 月 25 日东华理工大学课程设计评分表学生:班级:学号:课程设计题目:水电煤气管理系统一.问题描述:设计一个水电管理信息系统,能够对高校的水电费用进行管理,包括了登记费用,查询费用,以及住户信息管理等。
在设计时要考虑到学生和教工在用水电时的不同,学生可以免费使用一定额度的水电,超过这个额度的随便以后必须自费使用,且自费部分水电费的价格标准要高于教工的收费标准(主要是节约资源)。
二.设计思路:(一)程序功能:1.实现对用户信息的录入2.实现水电煤气数据的录入3.计算并查询用户应缴费用4.查询未缴纳费用(二)程序说明:1.在主函数过分支选择可以跳转不同的功能选项进而实现2.在显示主菜单函数中,我们通过设计友好界面来与用户进行交互。
在“请选择相应功能(0-4):”中使用者输入非0-4数字或其他字符时,系统提示“请检查您输入的数字在0~4之间!请在输入一遍!”的信息,以帮助用户进行正确选择。
3.首先建立了User类,用于初始化、、用水电、煤气量,又定义了缴费函数setMonery(),用在有人缴费的函数体中,从键盘输入缴的费用,一开始我们在setMoney(),中没有对缴的费用进行累加,在查询信息时现实的应缴费用不正确,经过我们的努力,检查出错误并加以改正,让程序更加完善。
4.用User类派生出Student和|Teacher类,其中有计算应该缴的费用,Student类比Teacher类多了免费。
5.在保存文件的处理中,需考虑到“创建保存文件失败!”和“已成功保存文件!”等诸多容。
(三)文件类型:(1) Constant.h用于存放收费标准。
(2) File.cpp该文件中有两个类:1.StuFile类,主要用于对学生信息的操作函数属性注释Public StuFile() 构造函数Public void add(Student&s)将S添加到文件中Public void display() 依次显示所有的学生的信息Public Student*gerStudent(stringid) 得到学号为id的学生的对象指针Public ~StuFile() 析构函数,释放资源,并把数组中的信息存进文件Public void wjf() 未缴费的学生的Private vector<Student>*stuList;学生信息的向量数组,用于保存所有学生的信息2 TeacherFile 类,主要用于对教工信息的操作Public TeacherFile() 构造函数Public voidadd(Teacher&s)将s添加到文件中Public void display() 依次显示所有的教师信息Public Teacher*getTeacher(string id) 得到编号为id的教师的对象指针Public ~TeacherFile() 析构函数,释放资源,并把数组中的信息存进文件Public v oid wjf() 未交费的教工人员Private Vector<Teacher>*teaLisr 教工的向量数组,用于保存所有教工的信息(3)Main.cpp函数属性注释void init() 新建一个学生或者教工的信息void select() 查询界面,根据用户的输入来显示用户想查询的信息void add() 信息的录入,录入学生或者教工的水电煤气信息void handed() 缴费,有学生或者教工缴费的时候调用此函数int mainMenu() 主菜单,显示一个菜单,返回用户的输入void work() 程序开始工作int main() 主函数,程序的入口(4)Student.cppClass Student:virtual public User函数属性注释Public Student():User(“”,””,0,0,0) 构造函数Public Student(string i,string n,Float w=0,float p=0,floatg=0):User(i,n,w,p,g) 构造函数i:学号n:Public void display() 依次显示所有的学生的信息Public float display() 返回学生应缴的费用Private float freeWater; 学生免费使用的水量Private float freePower; 学生免费使用的电量Private float freeGas; 学生免费使用的煤气量Private float money; 缴费(5)Teacher.cppClass Teacher:virtual public User函数属性注释Public Teacher(stringi,string n,float w=0,floatp=0,floatg=0):User(I,n,w,p,g)构造函数Public void display() 依次显示所有的教工信息Public float getMoney() 返回教工应缴的费用(6)User.cpp函数属性注释Public User(string i,string构造函数n,floatw=0,float p=0,float g=0)Public string getId() 获取编号Public string getName() 获取Public void setId(string i) 设置编号Public void setName(string n) 设置Public void setWater(float w) 设置水量Public void setPower(float p) 设置电量Public void setGas(float g) 设置煤气量Public float getWater() 使用水量Public virtual void display()=0; 依次显示所有信息Public void setMoney(float m) 缴费Public virtual float getMoney()=0; 应缴费用(四)UML图:StuFile+id:string+name:string+useWater:float+usePower:float+useGas:float+money:float+add():void+display():void+wjf():voidStudent-freeWater:float-freePower:float-freeGas:float+display():void+getMoney():voidUser+i:string+n:string+w:float+p:float+g:float+getId():string+getName():string+setId(string i) :string+setName(string n) :string+setWater(float w) :float+setPower(float p) :float+setGas(float g) :float+getWater():float三.程序代码:Constant.h//收费标准#ifndef Constant#define Constant//教师const static float TwaterUnit=1;const static float TpowerUnit=1;const static float TgasUnit=1;//学生const static float SwaterUnit=1;const static float SpowerUnit=1;const static float SgasUnit=1;//保存学生信息的文件const static char* stuFlieName="s.txt"; //保存教师信息的文件const static char* teaFileName="t.txt"; #endifMain.cpp#include<iostream>#include<iomanip>#include<string>#include<vector>#include"Student.cpp"#include"Teacher.cpp"#include"File.cpp"using namespace std;void init(){cout<<endl;cout<<"1.新建教工信息\n"<<"2.新建学生信息\n"<<endl;cout<<"请选择你要进行的操作:"<<endl;int o;cin>>o;if(o==1){string id;string name;cout<<"请输入新教工的号:";cin>>id;cout<<"请输入新教工的:";cin>>name;Teacher t(id,name);TeacherFile tf;tf.add(t);}else if(o==2){string id;string name;cout<<"请输入新学生的号:";cin>>id;cout<<"请输入新学生的:";cin>>name;Student s(id,name);StuFile sf;sf.add(s);}elsereturn ;}void select(){cout<<endl;cout<<"1.学生的信息\n"<<"2.教师的信息\n"<<"3.按号查询\n"<<"4.未缴费的人员\n"<<"5.不进行任何的操作\n"<<endl;cout<<"请输入你要进行的操作:";int o;cin>>o;StuFile sf;TeacherFile tf;if(o==1){cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;sf.display();}else if(o==2){cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;tf.display();}else if(o==3){User *user;StuFile sf;TeacherFile tf;string id;cout<<"请输入他的号:";cin>>id;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息为:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();}else if(o==4){sf.wjf();tf.wjf();}elsereturn ;}void add(){cout<<"1.对教工使用的水电煤气信息的录入"<<endl <<"2.对学生使用的水电煤气信息的录入"<<endl<<"3.不进行任何操作"<<endl;cout<<"请输入你要进行的操作:"<<endl;int o;string id;float water;float power;float gas;if(o==1||o==2){User*user;StuFile sf;TeacherFile tf;cout<<"请输入他的号:";cin>>id;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();cout<<"请输入他的用水量:";cin>>water;cout<<"请输入他的用电量:";cin>>power;cout<<"请输入他的用煤气量:";cin>>gas;user->setWater(water);user->setPower(power);user->setGas(gas);}elsereturn ;}void handed(){cout<<"请输入要缴费的人的号:";cin>>id;User*user;StuFile sf;TeacherFile tf;user=sf.getStudent(id);if(user==0)user=tf.getTeacher(id);if(user==0){cout<<"资料库中没有该号的用户!"<<endl;return ;}cout<<"该用户的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;user->display();cout<<"请输入他的缴费金额:";float money;cin>>money;user->setMoney(money);cout<<"缴费成功\n";}int mainMenu(){cout<<endl<<endl;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<<" 0.退出系统"<<endl;int a;char c[20];do{cout<<" 请选择相应的功能(0-4):"<<endl;cout<<endl;cin>>a;gets(c);if(a<0||a>4){cout<<endl<<endl;cout<<"请确认您输入的数字在0~4之间!"<<endl;cout<<"请重新输入一遍!"<<endl<<endl;}}while(a<0||a>4);return a;}void work(){switch(mainMenu()){case 1:init();break;case 2:select();break;case 3:add();break;case 4:handed();break;default:break;}}void Menu(){cout<<endl;cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆水电煤气管理系统☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆振坡☆"<<endl;cout<<" ☆☆"<<endl;cout<<" ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;cout<<endl;system("pause");system("cls");}void main(){system("color 3A");Menu();char a='y';while(a=='y'){work();cout<<"是否继续使用该系统(y/n)"<<endl;cin>>a;}}File.cpp//StuFile类,对学生信息的操作//TeacherFile类,对教工信息的操作#include<iostream>#include<iomanip>#include<fstream>#include<vector>#include<string>#include"Student.cpp"#include"Teacher.cpp"#include"User.cpp"#include"Constant.h"#ifndef StuFile_class#define StuFile_classclass StuFile{vector<Student> *stuList;public :string id;string name;float useWater;float usePower;float useGas;float money;StuFile(){stuList=new vector<Student>;ifstream *is=new ifstream("StuFileName",ios_base::in);if(is==0){cout<<"打开文件失败!"<<endl;return ;}else{while(is->good()){Student s("","");is->read((char*)&s,sizeof(Student));if(s.getId() !=""){stuList->push_back(s);}}}is->close();}void add(Student &s){stuList->push_back(s);}void display(){for(int i=0;i<stuList->size();i++){Student s=stuList->at(i);s.display();}}Student *getStudent(string id){for(int i=0;i<stuList->size();i++){if(stuList->at(i).getId()==id)return &stuList->at(i);}return 0;~StuFile(){if(stuList !=NULL && !stuList->empty()){ofstream os("stuFileName",ios_base::out);for(int i=0;i<stuList->size();i++){if(stuList->at(i).getId() !="")os.write((char*)&stuList->at(i),sizeof(Student));}os.close();delete stuList;}}void wjf(){cout<<"未缴费的学生:"<<endl;for(int i=0;i<stuList->size();i++){Student s=stuList->at(i);if(s.getMoney()>0){cout<<"该学生的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴纳的费用"<<endl;s.display();}}}};#endif#ifndef TeaFile_class#define TeaFile_classclass TeacherFile{vector<Teacher> *teaList;public:TeacherFile()teaList=new vector<Teacher>;ifstream*is=new ifstream(teaFileName,ios_base::in);if(is==0){cout<<"打开文件失败!"<<endl;return ;}else{while(is->good()){Teacher s("","");is->read((char*)&s,sizeof(Teacher));if(s.getId() !=""){teaList->push_back(s);}}}is->close();}Teacher *getTeacher(string id){for(int i=0;i<teaList->size();i++){if(teaList->at(i).getId()==id)return &teaList->at(i);}return 0;}void wjf(){cout<<"教工未缴费的人员:"<<endl;for(int i=0;i<teaList->size();i++){Teacher t=teaList->at(i);if(t.getMoney()>0){cout<<"该教师的信息是:"<<endl;cout<<"|"<<setw(18)<<"号"<<"|"<<setw(8)<<""<<"|"<<setw(8)<<"用水量"<<"|"<<setw(8)<<"用电量"<<"|"<<setw(8)<<"用煤气量"<<"|"<<setw(8)<<"要缴的费用"<<endl;t.display();}}}void display(){for(int i=0;i<teaList->size();i++){Teacher t=teaList->at(i);t.display();}}void add(Teacher &s){teaList->push_back(s);}~TeacherFile(){if(teaList !=NULL && !teaList->empty()){ofstream os(teaFileName,ios_base::out);for(int i=0;i<teaList->size();i++){if(teaList->at(i).getId() !="")os.write((char*)&teaList->at(i),sizeof(Teacher));}os.close();delete teaList;}}};#endifStudent.cpp#ifndef STUDENT_CLASS#define STUDENT_CLASS#include<iostream>#include<iomanip>#include<string>#include"Constant.h"#include"User.cpp"using namespace std;class Student:virtual public User{private :float freeWater;float freePower;float freeGas;public :Student():User("","",0,0,0){freeWater=1;freePower=2;freeGas=3;}Student(string i,string n,float w=0,float p=0,float g=0):User(i,n,w,p,g){}void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}float getMoney(){float w=SwaterUnit*((useWater>freeWater)?(useWater-freeWater):0);float p=SpowerUnit*((usePower>freePower)?(usePower-freePower):0);float g=SgasUnit*((useGas>freeGas)?(useGas-freeGas):0);return w+p+g-money;}};#endifTeacher.cpp#include"User.cpp"#include"Constant.h"#ifndef Teacher_class#define Teacher_classclass Teacher:virtual public User{public :Teacher(string i,string n,float w=0,float p=0,float g=0):User(i,n,w,p,g) {}void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}float getMoney(){float w=TwaterUnit* useWater;float p=TpowerUnit* usePower;float g=TgasUnit* useGas;return w+p+g-money;}};#endifUser.cpp#include<iostream>#include<iomanip>#include<string>using namespace std;#ifndef USER_CLASS#define USER_CLASSclass User{protected :string id;string name;float useWater;float usePower;float useGas;float money;public :User(string i,string n,float w=0,float p=0,float g=0) {id=i;name=n;useWater=w;usePower=p;useGas=g;money=0;}string getId(){return id;}string getName(){return name;}void setId(string i){id=i;}void setName(string n){name=n;}void setWater(float w){useWater=w;}void setPower(float p){usePower=p;}void setGas(float g){useGas=g;}float getWater(){return useWater;}virtual void display(){cout<<"|"<<setw(18)<<id<<"|"<<setw(8)<<name<<"|"<<setw(8)<<useWater<<"|"<<setw(8)<<usePower<<"|"<<setw(8)<<useGas<<"|"<<setw(8)<<getMoney()<<endl;}virtual void setMoney(float m){money +=m;}virtual float getMoney()=0;};#endif四.测试结果:界面一:欢迎界面界面二:程序功能表界面三:新建用户信界面四:信息查询界面五:信息的录入界面六:缴费五.实验心得:课程设计的过程中遇到了很多麻烦,虽然我早有心理准备,但还是令我伤透了脑筋,只怪自己平时看书太少,其实有很多东西在书上都可以找到答案的,可是还是有一些问题我实在没有办法解决,最终通过老师和同学们的努力解决了一个又一个的问题。
简易水电费管理系统源程序代码法一:#include<stdio.h>#include<string。
h>#include<stdlib。
h〉struct member{char no[100];char name[20];char password[20];float wfee;float efee;}memb;void newadd(int n){ int t,i;fseek(fp,0,SEEK_END);printf("〉〉新添人数:”);scanf("%d",&t);for(i=0;i〈t;i++){ printf("新添第%d个成员:”);scanf(”%s %s %s %f %f",memb.no,memb。
name,memb.password,memb.wfee,memb。
efee); fwrite(&memb,sizeof(struct member),1,fp);}}void look(int n){ char a[100];printf(">>输入卡号:”);scanf(”%s",a);int i=0;rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)||memb。
no==a) break;i++;}if(!feof(fp)){ printf("〉>卡号:”);printf("%s\n”,memb.no);printf(”〉>姓名:”);printf("%s\n”,memb。
name”);printf(">>水费:”);printf(”%f\n",memb。
wfee);printf(">〉电费:”);printf("%f\n",memb.efee);}elseprintf(">〉查无此人\n”);};void delete(int n){char c[100];printf(">>删除的卡号:”);scanf("%s,” c);if((fp1=fopen("temp。
面向对象技术与C++课程设计报告题目:设计高校水电管理系统班级:120604学号:120604129姓名:尤雅欢2013年9月课程设计任务书一、设计目的与要求1、目的:(1)要求学生达到熟练掌握C++语言的基本知识和技能;(2)基本掌握面向对象程序设计的基本思路和方法;(3)能够利用所学的基本知识和技能,解决简单的面向对象程序设计问题.2、基本要求:(1)要求利用面向对象的方法以及C++的编程思想来完成系统的设计;(2)要求在设计的过程中,建立清晰的类层次;要分析和定义各个类,每个类中要有各自的属性和方法;要求运用面向对象的机制(继承、派生及多态性)来实现系统功能.(3)在系统的设计中,要有清晰的界面设计,同时采用文件进行读写操作.3、创新要求:在基本要求达到后,可进行创新设计。
二、问题描述及功能要求设计一个水电管理信息系统,能够对高校的水电费用进行管理,包括登记费用、查询费用和住户信息管理等。
在设计时要考虑到学生和教工在用水电时的不同,学生可以免费使用一定额度的水电,超过这个额度的水电以后必须自费使用,且自费部分水电费的价格标准要高于教工的收费标准(主要是节约资源).完成如下功能:⑴实现对用户信息的录入。
⑵实现水电煤气数据的录入。
⑶计算并查询用户应缴费用。
⑷查询未缴纳费用的名单.三、问题的解决方案根据系统功能要求,可以将问题解决分为以下步骤:(1)应用系统分析,建立该系统的功能模块框图以及界面的组织和设计;(2)分析系统中的各个实体及它们之间的关系包括属性和行为;(3)根据问题描述,设计系统的类层次;(4)完成类层次中各个类的描述(包括属性和方法);(5)完成类中各个成员函数的定义;(6)完成系统的应用模块;(7)功能调试;1、在主函数中通过分支选择实现不同的功能。
2、在菜单函数中,通过设计界面与用户进行交互。
3、定义一个使用者类,在类的内部定义各种函数,实现显示、修改、删除、查询、统计用户信息等功能.五、各功能模块和流程图#include <iostream>#include 〈string〉#include〈iomanip>#include〈fstream〉using namespace std;class User{private:int num;//编号string name;//姓名string sex;//性别string status;//身份double water;//用水量double power;//用电量double watermoney;//水费double powermoney;//电费static int top; //top表示当前系统中存储的记录个数;public:User();void Display();//显示用户信息void Modify();//修改用户信息void Delete();//删除用户信息void Search();//查询用户信息void Save();//将该记录保存到文件void Input();//输入函数int Add();//统计人数};User::User(){}void User::Input()//输入函数{cout〈<”请输入编号:"〈<endl;cin〉〉num;cout〈〈"请输入姓名:"〈<endl;cin>>name;cout<<”请输入性别:"〈〈endl;cin〉>sex;cout<<" 请输入身份:”<〈endl;cin>>status;cout〈〈”请输入用水量:”<<endl;cin>>water;cout〈<"请输入用电量:"<<endl;cin〉>power;cout<〈”请选择收费方式:";cout〈<”1。
#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<<;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=;number=S.number;water=S.water;power=S.power;gas=S.gas;}double Stu::SGetW( ) //计算水费{if(water<10)water_rate=0;elsewater_rate=4.2*(water-10);return water_rate;}double Stu::SGetC() //计算电费{if(power<10)circuit=0;elsecircuit=0.6*(power-10);return circuit;}double Stu::SGetG() //计算煤气费{gas_rate=0;elsegas_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();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;}elsecout<<"没有这个学生"<<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;}elsecout<<"没有这个学生"<<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<<;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=;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;f>>teacher[i].power;f>>teacher[i].gas;i++;}f.close();count2=i;cout<<"\t\t 注册成功,祝你使用愉快……"<<endl; }void arrayofTeacher::jiaofei() //用户交费{char ch;string na;cout<<"\t\t\t欢迎使用交费功能"<<endl;cout<<"请输入姓名:"<<endl;cin>>na;int fl=0;double money,money2;for(int i=0;i<count2;i++)if(na==teacher[i].name){fl=1;if(teacher[i].flag){cout<<"该教工已缴纳过费用"<<endl; break;}else{cout<<"你应该交"<<teacher[i].Ttotal()<<"钱"<<endl;cout<<"确定是否真的现在交费(Y/N)"<<endl;cin>>ch;if(ch=='Y'||ch=='y'){teacher[i].flag=1;cout<<"你实际交的钱是:"<<endl;cin>>money;if(money>teacher[i].Ttotal()) cout<<"找零"<<money-teacher[i].Ttotal()<<"钱"<<endl;if(teacher[i].Ttotal()>money) { cout<<"交的钱不够,还应交"<<teacher[i].Ttotal()-money<<"钱"<<endl;cout<<"补交:"; cin>>money2;} cout<<"交费成功"<<endl;count22++;jiaogong();}else jiaogong();}}if(!fl)cout<<"没有这个教工"<<endl;}void arrayofTeacher::add() //增加教工{cout<<"\t\t\t欢迎使用增加教工功能"<<endl;cout<<"请输入教工的姓名"<<endl;cin>>teacher[count2].name;cout<<"请输入教工的用水量"<<endl;cin>>teacher[count2].water;cout<<"请输入教工的用电量"<<endl;cin>>teacher[count2].power;cout<<"请输入教工的用煤气量"<<endl;cin>>teacher[count2].gas;count2++;cout<<"\t\t\t教工已被成功增加!"<<endl;}void arrayofTeacher::delet( ) //删除教工{cout<<"\t\t\t欢迎使用删除教工功能"<<endl;int fl=0; int i,j;string name;cout<<"请输入要删除教工的姓名"<<endl;cin>>name;for(i=0;i<count2;i++)if(name==teacher[i].name){fl=1;break;}if(fl){for(j=i;j<count2-1;j++) //不能写成for(j=i;j<size;j++) teacher[j]=teacher[j+1];count2--;cout<<"你已成功删除教工信息"<<endl;}else cout<<"没有这个教工"<<endl;}void arrayofTeacher::check( ) //查找交费情况{ cout<<"\t\t\t欢迎使用查费功能"<<endl;string na;int i=0,fl=0;cout<<"请你输入姓名"<<endl;cin>>na;for(i=0;i<count2;i++)if(na==teacher[i].name){fl=1;break;}if(fl){cout<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<" 总额"<<" 是否交费"<<endl;cout<<teacher[i]<<endl;}elsecout<<"没有这个教工"<<endl;}void arrayofTeacher::display() //查看交费情况{int i;if(count22==0)cout<<"暂时还无教工交钱"<<endl;else {cout<<"已交费人员信息"<<endl;cout<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<" 总额"<<" 是否交费"<<endl;for( i=0;i<count2;i++)if(teacher[i].flag)cout<<teacher[i];}//cout<<count22;if(count22==count2) cout<<"所有的教工均以交钱"<<endl;else{ cout<<"未交费人员信息"<<endl;cout<<"姓名"<<"用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<" 总额"<<" 是否交费"<<endl;for(i=0;i<count2;i++)if(!teacher[i].flag)cout<<teacher[i];}}void arrayofTeacher::save(){ofstream f("Teacher2.txt");f<<"学号"<<"姓名"<<" 用水量"<<"用电量"<<"用煤气量"<<"水费"<<"电费"<<"煤气费"<<" 总额"<<" 是否交费"<<endl;for(int i=0;i<count2;i++)f<<teacher[i]<<endl;f.close();cout<<"\t\t教工信息以成功保存到磁盘文件中"<<endl;}void arrayofTeacher::amend() //修改菜单{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: add(); break;case 2: delet();break;case 0: jiaogong(); break;}if(choice==0)break;}}void arrayofTeacher::jiaogong() //教工主菜单{int choice;cout<<"\t\t 欢迎使用教工用户电煤气管理系统"<<endl<<endl;cout<<" 1,注册教工"<<endl;cout<<" 2,修改用户"<<endl;cout<<" 3,缴纳费用"<<endl;cout<<" 4,查询费用"<<endl;cout<<" 5,显示交费情况"<<endl;cout<<" 6,保存信息到文件"<<endl;cout<<" 0,返回上一层"<<endl;cout<<"温馨提示:第一次登陆时,要进行注册!!"<<endl<<endl;cout<<"================================================"<<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 main(){arrayofStu student(200);arrayofTeacher teacher(200);cout<<"友情提示:本程序的菜单中,每个功能前都有相应的数字,输入数字实现相应的功能!"<<endl<<endl;int choice;for(;;){cout<<"\t\t 欢迎使用高校电煤气管理系统\a"<<endl<<endl ;cout<<" 1,教工用户管理系统"<<endl<<endl;cout<<" 2,学生用户管理系统"<<endl<<endl;cout<<" 0,退出系统"<<endl<<endl;cout<<"************************************************************************ ********\n";cout<<"请输入你的选择"<<endl;cin>>choice;switch(choice){case 1:teacher.jiaogong( ); break;case 2:student.xuesheng( ); break;case 0:break;}if(choice==0)break;}}。