用C语言再写一个
时间: 2023-11-27 20:05:27 浏览: 25
好的,以下是一个使用 C 语言编写的物料管理系统程序示例,您可以根据需要进行修改和完善:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 定义物料结构体
typedef struct Material {
char code[20]; // 物料编码
char name[50]; // 物料名称
char model[50]; // 物料型号
char process[50]; // 工序
int count; // 数量
char unit[20]; // 单位
char location[50]; // 存放位置
char category[50]; // 物料分类
char in_time[20]; // 入库时间
char warranty_time[20]; // 质保时间
char picture[100]; // 备件图片
int remaining_time; // 剩余时间
} Material;
// 定义物料管理系统结构体
typedef struct MaterialManagementSystem {
Material *materials[1000]; // 存储物料信息的数组
int count; // 物料数量
} MaterialManagementSystem;
// 初始化物料管理系统
void initialize(MaterialManagementSystem *system) {
system->count = 0;
}
// 物料入库
void inbound(MaterialManagementSystem *system) {
Material *material = (Material*)malloc(sizeof(Material));
printf("请输入物料编码:");
scanf("%s", material->code);
printf("请输入物料名称:");
scanf("%s", material->name);
printf("请输入物料型号:");
scanf("%s", material->model);
printf("请输入工序:");
scanf("%s", material->process);
printf("请输入数量:");
scanf("%d", &material->count);
printf("请输入单位:");
scanf("%s", material->unit);
printf("请输入存放位置:");
scanf("%s", material->location);
printf("请输入物料分类:");
scanf("%s", material->category);
printf("请输入入库时间(格式为YYYY-MM-DD):");
scanf("%s", material->in_time);
printf("请输入质保时间(格式为YYYY-MM-DD):");
scanf("%s", material->warranty_time);
printf("请输入备件图片:");
scanf("%s", material->picture);
time_t now = time(NULL);
struct tm *tm_now = localtime(&now);
struct tm tm_warranty_end;
memset(&tm_warranty_end, 0, sizeof(struct tm));
sscanf(material->warranty_time, "%d-%d-%d", &tm_warranty_end.tm_year, &tm_warranty_end.tm_mon, &tm_warranty_end.tm_mday);
tm_warranty_end.tm_year -= 1900;
tm_warranty_end.tm_mon -= 1;
time_t warranty_end_time = mktime(&tm_warranty_end);
double remaining_time = difftime(warranty_end_time, now) / (24 * 60 * 60);
material->remaining_time = (int)remaining_time;
system->materials[system->count++] = material;
printf("物料入库成功!\n");
}
// 物料领用
void outbound(MaterialManagementSystem *system) {
char code[20];
int count;
printf("请输入物料编码:");
scanf("%s", code);
printf("请输入领用数量:");
scanf("%d", &count);
for (int i = 0; i < system->count; i++) {
Material *material = system->materials[i];
if (strcmp(material->code, code) == 0) {
if (material->count >= count) {
material->count -= count;
printf("物料领用成功!\n");
return;
}
else {
printf("库存不足,无法领用!\n");
return;
}
}
}
printf("未找到该物料编码!\n");
}
// 物料查询
void query(MaterialManagementSystem *system) {
char code[20];
printf("请输入物料编码:");
scanf("%s", code);
for (int i = 0; i < system->count; i++) {
Material *material = system->materials[i];
if (strcmp(material->code, code) == 0) {
printf("物料编码:%s\n", material->code);
printf("物料名称:%s\n", material->name);
printf("物料型号:%s\n", material->model);
printf("工序:%s\n", material->process);
printf("数量:%d\n", material->count);
printf("单位:%s\n", material->unit);
printf("存放位置:%s\n", material->location);
printf("物料分类:%s\n", material->category);
printf("入库时间:%s\n", material->in_time);
printf("质保时间:%s\n", material->warranty_time);
printf("剩余时间:%d天\n", material->remaining_time);
printf("备件图片:%s\n", material->picture);
return;
}
}
printf("未找到该物料编码!\n");
}
// 主函数
int main() {
MaterialManagementSystem system;
initialize(&system);
int choice;
while (1) {
printf("请选择操作:\n");
printf("1. 物料入库\n");
printf("2. 物料领用\n");
printf("3. 物料查询\n");
printf("4. 退出程序\n");
scanf("%d", &choice);
switch (choice) {
case 1:
inbound(&system);
break;
case 2:
outbound(&system);
break;
case 3:
query(&system);
break;
case 4:
exit(0);
default:
printf("请输入正确的选项!\n");
break;
}
}
return 0;
}
```
以上是一个使用 C 语言编写的物料管理系统程序示例,您可以根据需要进行修改和完善。