c++水电煤气管理信息系统
时间: 2023-12-22 20:27:51 浏览: 114
以下是一个简单的C++水电煤气管理信息系统的示例,包括了登记费用、查询费用和住户信息管理系统等功能:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 定义住户类
class Resident {
public:
Resident(string name, string type) {
this->name = name;
this->type = type;
this->waterUsage = 0;
this->electricityUsage = 0;
this->gasUsage = 0;
}
string getName() {
return name;
}
string getType() {
return type;
}
double getWaterUsage() {
return waterUsage;
}
double getElectricityUsage() {
return electricityUsage;
}
double getGasUsage() {
return gasUsage;
}
void addWaterUsage(double usage) {
waterUsage += usage;
}
void addElectricityUsage(double usage) {
electricityUsage += usage;
}
void addGasUsage(double usage) {
gasUsage += usage;
}
private:
string name; // 姓名
string type; // 类型(学生或教工)
double waterUsage; // 用水量
double electricityUsage; // 用电量
double gasUsage; // 用气量
};
// 定义住户管理类
class ResidentManager {
public:
void addResident(Resident resident) {
residents.push_back(resident);
}
Resident* findResident(string name) {
for (int i = 0; i < residents.size(); i++) {
if (residents[i].getName() == name) {
return &residents[i];
}
}
return NULL;
}
private:
vector<Resident> residents; // 住户列表
};
// 定义费用管理类
class FeeManager {
public:
void addWaterFee(double fee) {
waterFee += fee;
}
void addElectricityFee(double fee) {
electricityFee += fee;
}
void addGasFee(double fee) {
gasFee += fee;
}
double getWaterFee() {
return waterFee;
}
double getElectricityFee() {
return electricityFee;
}
double getGasFee() {
return gasFee;
}
private:
double waterFee; // 水费
double electricityFee; // 电费
double gasFee; // 燃气费
};
int main() {
ResidentManager residentManager; // 住户管理类
FeeManager feeManager; // 费用管理类
// 添加住户
Resident student1("张三", "学生");
Resident student2("李四", "学生");
Resident teacher1("王五", "教工");
Resident teacher2("赵六", "教工");
residentManager.addResident(student1);
residentManager.addResident(student2);
residentManager.addResident(teacher1);
residentManager.addResident(teacher2);
// 登记费用
Resident* resident = residentManager.findResident("张三");
if (resident != NULL) {
resident->addWaterUsage(10);
resident->addElectricityUsage(20);
resident->addGasUsage(30);
feeManager.addWaterFee(10);
feeManager.addElectricityFee(20);
feeManager.addGasFee(30);
}
// 查询费用
cout << "水费总额:" << feeManager.getWaterFee() << endl;
cout << "电费总额:" << feeManager.getElectricityFee() << endl;
cout << "燃气费总额:" << feeManager.getGasFee() << endl;
// 住户信息管理系统
resident = residentManager.findResident("张三");
if (resident != NULL) {
cout << "姓名:" << resident->getName() << endl;
cout << "类型:" << resident->getType() << endl;
cout << "用水量:" << resident->getWaterUsage() << endl;
cout << "用电量:" << resident->getElectricityUsage() << endl;
cout << "用气量:" << resident->getGasUsage() << endl;
}
return 0;
}
```
阅读全文