使用顺序表实现编号、企业编号、企业名称、联系电话、谷电量、峰电量、谷价、峰价、年月、合计电量、合计电费等。系统能够完成用电情况信息的,排序,查询、更新、插入、删除、浏览,统计等功能。
时间: 2023-10-24 16:09:44 浏览: 35
好的,这是一个比较完整的电力信息管理系统。下面我来为你简单介绍一下使用顺序表实现的流程。
首先,我们可以定义一个结构体来表示每个电力信息的各个属性,如下所示:
```c
typedef struct {
int id; // 编号
int ent_id; // 企业编号
char ent_name[50]; // 企业名称
char phone[20]; // 联系电话
int valley_elec; // 谷电量
int peak_elec; // 峰电量
double valley_price;// 谷价
double peak_price; // 峰价
int year_month; // 年月
int total_elec; // 合计电量
double total_price; // 合计电费
} ElectricityInfo;
```
然后,我们可以定义一个顺序表来存储所有的电力信息,以及各种对电力信息进行操作的函数,如下所示:
```c
#define MAX_SIZE 1000 // 电力信息的最大数量
typedef struct {
ElectricityInfo data[MAX_SIZE]; // 数据元素
int length; // 顺序表长度
} SeqList;
// 初始化顺序表
void InitList(SeqList *L);
// 向顺序表中插入一条电力信息
bool Insert(SeqList *L, ElectricityInfo e);
// 删除顺序表中指定编号的电力信息
bool Delete(SeqList *L, int id);
// 更新顺序表中指定编号的电力信息
bool Update(SeqList *L, ElectricityInfo e);
// 根据编号查询顺序表中的电力信息
ElectricityInfo* FindById(SeqList *L, int id);
// 根据企业名称查询顺序表中的电力信息
ElectricityInfo* FindByEntName(SeqList *L, char *ent_name);
// 根据年月查询顺序表中的电力信息
ElectricityInfo* FindByYearMonth(SeqList *L, int year_month);
// 对顺序表中的电力信息按指定属性进行排序
void Sort(SeqList *L, int sort_field);
// 统计顺序表中的电力信息总数、总电量、总电费等
void Statistics(SeqList *L, int *count, int *total_elec, double *total_price);
// 浏览顺序表中的所有电力信息
void Traverse(SeqList *L);
```
最后,我们可以根据需要在主函数中调用这些函数来实现具体的功能,如下所示:
```c
int main() {
SeqList L;
InitList(&L);
// 向顺序表中插入电力信息
ElectricityInfo e = {1, 1001, "ABC公司", "13333333333", 1000, 500, 0.5, 1.0, 202112, 1500, 1800.0};
Insert(&L, e);
// 删除顺序表中指定编号的电力信息
Delete(&L, 1);
// 更新顺序表中指定编号的电力信息
e.total_elec = 2000;
e.total_price = 2400.0;
Update(&L, e);
// 根据编号查询顺序表中的电力信息
ElectricityInfo *p = FindById(&L, 1);
if (p != NULL) {
printf("%d %d %s %s %d %d %.2f %.2f %d %d %.2f\n", p->id, p->ent_id, p->ent_name, p->phone,
p->valley_elec, p->peak_elec, p->valley_price, p->peak_price, p->year_month,
p->total_elec, p->total_price);
}
// 根据企业名称查询顺序表中的电力信息
p = FindByEntName(&L, "ABC公司");
if (p != NULL) {
printf("%d %d %s %s %d %d %.2f %.2f %d %d %.2f\n", p->id, p->ent_id, p->ent_name, p->phone,
p->valley_elec, p->peak_elec, p->valley_price, p->peak_price, p->year_month,
p->total_elec, p->total_price);
}
// 根据年月查询顺序表中的电力信息
p = FindByYearMonth(&L, 202112);
if (p != NULL) {
printf("%d %d %s %s %d %d %.2f %.2f %d %d %.2f\n", p->id, p->ent_id, p->ent_name, p->phone,
p->valley_elec, p->peak_elec, p->valley_price, p->peak_price, p->year_month,
p->total_elec, p->total_price);
}
// 对顺序表中的电力信息按指定属性进行排序
Sort(&L, 1);
// 统计顺序表中的电力信息总数、总电量、总电费等
int count = 0, total_elec = 0;
double total_price = 0.0;
Statistics(&L, &count, &total_elec, &total_price);
printf("%d %d %.2f\n", count, total_elec, total_price);
// 浏览顺序表中的所有电力信息
Traverse(&L);
return 0;
}
```
以上就是使用顺序表实现电力信息管理系统的一个简单流程,具体实现细节可能还需要根据实际情况进行调整。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)