用c语言写一个辽宁省居民生活用电管理系统
时间: 2023-11-09 20:05:34 浏览: 47
好的,下面是一个简单的辽宁省居民生活用电管理系统的示例代码,包括用户信息管理、电表信息管理、电费管理和用电记录管理等功能。请注意,这只是一个简单的示例,实际的用电管理系统需要更复杂的功能和更高的安全性。
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_USERS 1000
#define MAX_METERS 1000
#define MAX_RECORDS 10000
struct user {
int id;
char name[20];
char password[20];
};
struct meter {
int id;
int type;
int status;
int user_id;
};
struct record {
int meter_id;
int year;
int month;
int amount;
};
struct user users[MAX_USERS];
struct meter meters[MAX_METERS];
struct record records[MAX_RECORDS];
int user_count = 0;
int meter_count = 0;
int record_count = 0;
int login(int user_id, char *password) {
int i;
for (i = 0; i < user_count; i++) {
if (users[i].id == user_id && strcmp(users[i].password, password) == 0) {
return 1;
}
}
return 0;
}
int add_user(char *name, char *password) {
if (user_count == MAX_USERS) {
return 0;
}
users[user_count].id = user_count + 1;
strcpy(users[user_count].name, name);
strcpy(users[user_count].password, password);
user_count++;
return 1;
}
int update_user(int user_id, char *name, char *password) {
int i;
for (i = 0; i < user_count; i++) {
if (users[i].id == user_id) {
strcpy(users[i].name, name);
strcpy(users[i].password, password);
return 1;
}
}
return 0;
}
int delete_user(int user_id) {
int i;
for (i = 0; i < user_count; i++) {
if (users[i].id == user_id) {
int j;
for (j = i; j < user_count - 1; j++) {
users[j].id = users[j+1].id;
strcpy(users[j].name, users[j+1].name);
strcpy(users[j].password, users[j+1].password);
}
user_count--;
return 1;
}
}
return 0;
}
int add_meter(int type) {
if (meter_count == MAX_METERS) {
return 0;
}
meters[meter_count].id = meter_count + 1;
meters[meter_count].type = type;
meters[meter_count].status = 1;
meter_count++;
return 1;
}
int update_meter(int meter_id, int type, int status, int user_id) {
int i;
for (i = 0; i < meter_count; i++) {
if (meters[i].id == meter_id) {
meters[i].type = type;
meters[i].status = status;
meters[i].user_id = user_id;
return 1;
}
}
return 0;
}
int delete_meter(int meter_id) {
int i;
for (i = 0; i < meter_count; i++) {
if (meters[i].id == meter_id) {
int j;
for (j = i; j < meter_count - 1; j++) {
meters[j].id = meters[j+1].id;
meters[j].type = meters[j+1].type;
meters[j].status = meters[j+1].status;
meters[j].user_id = meters[j+1].user_id;
}
meter_count--;
return 1;
}
}
return 0;
}
int calculate_fee(int meter_id, int year, int month) {
int i;
for (i = 0; i < record_count; i++) {
if (records[i].meter_id == meter_id && records[i].year == year && records[i].month == month) {
return records[i].amount * 2;
}
}
return -1;
}
int pay_fee(int meter_id, int year, int month) {
int i;
for (i = 0; i < record_count; i++) {
if (records[i].meter_id == meter_id && records[i].year == year && records[i].month == month) {
records[i].amount = 0;
return 1;
}
}
return 0;
}
int add_record(int meter_id, int year, int month, int amount) {
if (record_count == MAX_RECORDS) {
return 0;
}
records[record_count].meter_id = meter_id;
records[record_count].year = year;
records[record_count].month = month;
records[record_count].amount = amount;
record_count++;
return 1;
}
int main() {
// 示例代码中省略了用户界面和文件读写操作等部分
// 具体实现可以根据需求进行调整
return 0;
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)