社区门诊信息管理系统C语言,c语言之仓库信息管理系统

这篇博客介绍了一个仓库管理系统的实现,包括进库、出库、查询和数据持久化功能。系统使用文件存储数据,采用C语言编程,利用结构体和文件操作函数实现数据的读写。主要功能如库存初始化、物品增加、减少和查找,以及数据更新后的文件同步。程序还提供了用户交互界面,允许用户进行各种操作。
摘要由CSDN通过智能技术生成

仓库管理系统报告

一、项目背景

仓库信息管理系统:实现进库出库、展示仓库信息、支持查询功能、数据的长久保存

二、实现环境

1. WSL

2. clang version 10.0.0

Target: x86_64-pc-linux-gnu

(c环境都能跑哦~)

三、报告正文

实现方法

数据使用文件保存

采用函数模块化编程思想

使用了必要的结构体

重要的数据结构

typedef struct{

char name[100];

int count;

}Goods; // 物品结构体,其成员为物品名称和数量。

typedef struct{

Goods goods[50];

int count;

}Store; // 仓库结构体,成员是物品类数组和目前已存进的数目

实现过程

main函数

调用void Init_Store()函数,读取文件数据,初始化全局变量store及其成员

使用switch分支结构,进行每次操作选择

初始化

主控函数void Init_Store()

定义文件指针FILE *fp,只读权限

通过feof(fp)保证文件完成读取,同时更新仓库store内容

完成后关闭文件

入库

主控函数int add_to_list(char name[], int count)

调用函数int InStore(char name[]),查找该物品是否已经存在

若已存在(即返回值不是FALSE),调用函数int increase_count(char name[], int count, int pos);更新store变量和data.txt数据存储文件

若不存在(即返回值为具体下标),调用函数int add_to_list(char name[], int count);更新store变量和data.txt数据存储文件

int increase_count(char name[], int count, int pos)

说明该物品在仓库中已存在,通过下标修改物品数量

int add_to_list(char name[], int count)

判断仓库是否已满(store.count > 50 ?)

判断存储物品的名称是否合法(strlen(name) > 100 ?)

若合法,则将物品添加到store.goods数组末尾;若不合法,则添加失败

出库

主控函数int delete_goods(char namep[], int count)

调用函数int InStore(char name[]),查找仓库中是否有该物品;若不存在则报错

获取到物品目前数量,与需取出相比较

物品数量不足,取出失败

数量恰好,调用函数int delete_from_list(char name[], int pos)

数量大于需求,调用函数int decrease_count(char name[], int count, int pos)

取出完成,更新store变量和data.txt数据存储文件

int delete_from_list(char name[], int pos)

判断要删除的位置是否在数组末尾

若不是,则删除目前位置内容;并将该位置之后的内容依次向前挪一个单元

将数组末尾初始化置为0;store.count --

int decrease_count(char name[], int count, int pos)

通过下标修改物品数量

查找

遍历仓库void show_goods()

查找物品Goods find_goods(char name[])

调用函数int InStore(char name[])

若未找到,则返回一个空goods;若找到,则返回变量内容

辅助函数

int InStore(char name[])遍历函数

查找store中是否有name

若有,则返回对应下标;若无,则返回FALSE

void Write_tofile()更新文件函数

只写方式打开data.txt

将store.goods[]写入,并控制写入格式

测试

数据正常读入,正常写入。

程序功能完整。

d23f8d77c01d2f959be8b79bf179d419.png

34f31508501e8a3353e47a6833d085cd.png

总结

就简单的写写 ... 题目中也没要求太多 ...

UI使用qt或者MFC都是不错的选择 ...

或者使用一些宏渲染一下颜色什么的都是可以的 ...

然后也没有进行异常处理 ... 只进行了警告和函数控制 ...

对于程序消耗,struct Store是起控制作用的结构体,完全可以用指针来代替定长数组 ... and so on

就这样吧 ...

源码

#include

#include

#include

#define TRUE 1

#define FALSE -1

typedef struct{

char name[100];

int count;

}Goods;

typedef struct{

Goods goods[50];

int count;

}Store;

Store store;

void Init_Store()

{

printf("Init Start ...\n");

FILE *fp;

fp = fopen("data.txt","r");

if(fp == NULL) {

printf("No such file !\n");

exit(0);

}

while(1) {

if(feof(fp)) break;

fscanf(fp, "%s%d", store.goods[store.count].name, &store.goods[store.count].count);

store.count++;

}

fclose(fp);

printf("Init Finished !\n");

printf("There are %d kinds of items.\n", store.count);

}

int InStore(char name[])

{

int i = 0;

for(;i < store.count; ++ i){

if(strcmp(name, store.goods[i].name) == 0)

return i;

}

return FALSE;

}

void Write_tofile()

{

FILE *fp = NULL;

fp = fopen("data.txt","w");

int i = 0;

while(i < store.count) {

fprintf(fp, "%s %d", store.goods[i].name, store.goods[i].count);

if(i != store.count-1) {

fprintf(fp, "\n");

}

i++;

}

fclose(fp);

}

int increase_count(char name[], int count, int pos)

{

store.goods[pos].count += count;

printf("The items already exist and have increased %d.\nNow the count is : %d.\n", count, store.goods[pos].count);

return TRUE;

}

int add_to_list(char name[], int count)

{

if(store.count > 50) {

printf("No more space for this goods ! Can't be stocked !\n");

return FALSE;

}

if(strlen(name) > 100) {

printf("Name's length over 100! Can't be stocked !\n");

return FALSE;

}

strcpy(store.goods[store.count].name, name);

store.goods[store.count].count = count;

printf("Stock successfully !\nNow the count is : %d.\n", store.goods[store.count].count);

store.count ++;

return TRUE;

}

int add_goods(char name[], int count)

{

int instore = InStore(name);

if(instore != FALSE) {

increase_count(name, count, instore);

Write_tofile();

return TRUE;

}

add_to_list(name, count);

Write_tofile();

return 0;

}

int decrease_count(char name[], int count, int pos)

{

store.goods[pos].count -= count;

printf("%d out of stock.\nNow the count is : %d.\n", count, store.goods[pos].count);

return TRUE;

}

int delete_from_list(char name[], int pos)

{

if(pos != store.count-1) {

for(;pos < store.count-1;) {

strcpy(store.goods[pos].name, store.goods[pos+1].name);

store.goods[pos].count = store.goods[pos+1].count;

pos ++;

}

}

store.goods[pos].name[0] = '\0';

store.goods[pos].count = 0;

store.count --;

printf("Out of stock and delete from list.\n");

return TRUE;

}

int delete_goods(char name[], int count)

{

int instore = InStore(name);

if(instore == FALSE) {

printf("There is no such goods ! Can't out of the stock !\n");

return FALSE;

}

int goods_count = store.goods[instore].count;

if(goods_count < count) {

printf("The %s goods isn't enough !\nNow the count is : %d.\n", name, goods_count);

return FALSE;

} else if(goods_count == count) {

delete_from_list(name, instore);

} else if(goods_count > count) {

decrease_count(name, count, instore);

}

Write_tofile();

return TRUE;

}

void show_goods()

{

int i = 0;

printf("show goods : \n");

for(;i < store.count;i ++) {

printf("%s : %d\n",store.goods[i].name, store.goods[i].count);

}

}

Goods find_goods(char name[])

{

int instore = InStore(name);

if(instore == FALSE) {

printf("Can't find such goods!\n");

Goods goods;

goods.count = 0;

goods.name[0] = '\0';

return goods;

}

return store.goods[instore];

}

int main()

{

Init_Store();

printf("---- list ----\n");

printf("1: add goods2: delete goods\n");

printf("3: list goods4: find goods\n");

printf("-- 0: exit --\n");

int choice = 1;

while(choice!=0) {

printf("Enter your choice : ");

scanf("%d",&choice);

switch(choice) {

case 1:{

char str[100];

int count;

printf("Input goods and count to add : ");

scanf("%s%d", str, &count);

add_goods(str, count);

break;

}

case 2:{

char str[100];

int count;

printf("Input goods and count to delete : ");

scanf("%s%d", str, &count);

delete_goods(str, count);

break;

}

case 3:{

show_goods();

break;

}

case 4:{

char str[100];

printf("Input goods name to find : ");

scanf("%s",str);

Goods temp = find_goods(str);

printf("The goods : %s %d\n", temp.name, temp.count);

break;

}

default:{

printf("Please enter correct choice!\n");

break;

}

}

}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值