用c语言编写一个完整的程序解决下面的问题 问题描述: 实验设备管理系统,实验设备信息包括:设备编号、设备种类(微机、打印机、扫描仪等等)、设备名称、设备价格、设备购入日期、是否报废、报废日期等。要求整个系统设计为实验设备信息输入模块,实验设备信息添加模块,实验设备信息修改模块,实验设备信息分类统计模块和实验设备查询输入模块。实现功能: 1、能够完成对设备的录入和修改 2、对设备进行分类 3、设备的查询 4、设备的破损耗费和遗损处理
时间: 2023-03-31 09:01:07 浏览: 105
以下是一个用 C 语言编写的实验设备管理系统的示例程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_DEVICES 100 // 最大设备数量
// 设备信息结构体
typedef struct {
char id[20]; // 设备编号
char type[20]; // 设备种类
char name[50]; // 设备名称
float price; // 设备价格
char purchase_date[20]; // 设备购入日期
int is_scrapped; // 是否报废
char scrapped_date[20]; // 报废日期
} Device;
// 设备数组
Device devices[MAX_DEVICES];
int num_devices = ;
// 显示菜单
void show_menu() {
printf("实验设备管理系统\n");
printf("1. 录入设备信息\n");
printf("2. 修改设备信息\n");
printf("3. 分类统计设备信息\n");
printf("4. 查询设备信息\n");
printf("5. 处理破损耗费和遗损\n");
printf(". 退出系统\n");
printf("请选择操作:");
}
// 录入设备信息
void add_device() {
if (num_devices >= MAX_DEVICES) {
printf("设备数量已达到上限,无法继续添加!\n");
return;
}
Device device;
printf("请输入设备编号:");
scanf("%s", device.id);
printf("请输入设备种类:");
scanf("%s", device.type);
printf("请输入设备名称:");
scanf("%s", device.name);
printf("请输入设备价格:");
scanf("%f", &device.price);
printf("请输入设备购入日期:");
scanf("%s", device.purchase_date);
device.is_scrapped = ;
num_devices++;
devices[num_devices - 1] = device;
printf("设备信息录入成功!\n");
}
// 修改设备信息
void modify_device() {
char id[20];
printf("请输入要修改的设备编号:");
scanf("%s", id);
int i;
for (i = ; i < num_devices; i++) {
if (strcmp(devices[i].id, id) == ) {
printf("请输入新的设备种类:");
scanf("%s", devices[i].type);
printf("请输入新的设备名称:");
scanf("%s", devices[i].name);
printf("请输入新的设备价格:");
scanf("%f", &devices[i].price);
printf("请输入新的设备购入日期:");
scanf("%s", devices[i].purchase_date);
printf("设备信息修改成功!\n");
return;
}
}
printf("找不到该设备编号的设备!\n");
}
// 分类统计设备信息
void classify_devices() {
int num_microcomputers = ;
int num_printers = ;
int num_scanners = ;
int i;
for (i = ; i < num_devices; i++) {
if (strcmp(devices[i].type, "微机") == ) {
num_microcomputers++;
} else if (strcmp(devices[i].type, "打印机") == ) {
num_printers++;
} else if (strcmp(devices[i].type, "扫描仪") == ) {
num_scanners++;
}
}
printf("设备种类\t数量\n");
printf("微机\t\t%d\n", num_microcomputers);
printf("打印机\t\t%d\n", num_printers);
printf("扫描仪\t\t%d\n", num_scanners);
}
// 查询设备信息
void search_device() {
char id[20];
printf("请输入要查询的设备编号:");
scanf("%s", id);
int i;
for (i = ; i < num_devices; i++) {
if (strcmp(devices[i].id, id) == ) {
printf("设备编号:%s\n", devices[i].id);
printf("设备种类:%s\n", devices[i].type);
printf("设备名称:%s\n", devices[i].name);
printf("设备价格:%f\n", devices[i].price);
printf("设备购入日期:%s\n", devices[i].purchase_date);
if (devices[i].is_scrapped) {
printf("设备状态:已报废,报废日期:%s\n", devices[i].scrapped_date);
} else {
printf("设备状态:未报废\n");
}
return;
}
}
printf("找不到该设备编号的设备!\n");
}
// 处理破损耗费和遗损
void handle_damage_and_loss() {
char id[20];
printf("请输入要处理的设备编号:");
scanf("%s", id);
int i;
for (i = ; i < num_devices; i++) {
if (strcmp(devices[i].id, id) == ) {
if (devices[i].is_scrapped) {
printf("该设备已经报废,无法进行处理!\n");
} else {
printf("请输入处理方式(1. 破损耗费,2. 遗损):");
int choice;
scanf("%d", &choice);
if (choice == 1) {
printf("请输入破损耗费金额:");
float cost;
scanf("%f", &cost);
devices[i].price -= cost;
printf("破损耗费处理成功!\n");
} else if (choice == 2) {
devices[i].is_scrapped = 1;
printf("设备已报废,请输入报废日期:");
scanf("%s", devices[i].scrapped_date);
printf("遗损处理成功!\n");
} else {
printf("无效的处理方式!\n");
}
}
return;
}
}
printf("找不到该设备编号的设备!\n");
}
int main() {
int choice;
do {
show_menu();
scanf("%d", &choice);
switch (choice) {
case 1:
add_device();
break;
case 2:
modify_device();
break;
case 3:
classify_devices();
break;
case 4:
search_device();
break;
case 5:
handle_damage_and_loss();
break;
case :
printf("感谢使用实验设备管理系统!\n");
break;
default:
printf("无效的操作!\n");
break;
}
} while (choice != );
return ;
}
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)
![](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)