栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

商品库存管理系统(c语言)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

商品库存管理系统(c语言)

c语言商品库存管理系统
    • 一、项目背景
    • 二、设计目的
    • 三、项目功能需求
      • 1、商品入库
      • 2、商品出库
      • 3、删除商品信息
      • 4、修改商品信息
      • 5、查询商品信息
    • 四、系统的功能结构图
    • 五、功能模块介绍
      • 1、商品入库模块
      • 2、商品出库模块
      • 3、删除商品模块
      • 4、修改商品模块
      • 5、查询商品模块
      • 6、显示商品模块
    • 六、详细设计
      • 1、主函数
      • 2、商品入库模块
      • 3、商品出库模块
      • 4、删除商品模块
      • 5、修改商品模块
      • 6、查询商品模块
      • 7、显示商品模块
    • 七、代码

一、项目背景

​ 为了解决商品库存信息在日常生活中易于丢失、遗忘,不易保存和管理的问题,我们设计商品库存管理系统,来帮助商家方便地对商品信息进行增加、删除、修改等日常维护,并且能进行商品信息的查询,从而能更全面直观地了解到商品库存信息。

二、设计目的
  1. 如何实现菜单的显示、选择和响应等功能
  2. 如何将信息保存到指定的磁盘文件中,并通过操作文件指针和调用文件相关函数来实现对文件的读写操作
  3. 如何使用结构体封装商品属性信息
  4. 如何利用结构体数组记录多个商品信息
  5. 如何通过C语言实现基本的增、删、改、查等信息管理功能
三、项目功能需求 1、商品入库

能够录入商品编号、名称、数量、价格、生产日期、供货商等信息,并支持连续输入多个商品信息

2、商品出库

根据用户输入要进行出库操作的商品编号,如果存在该商品,则可以输入要出库的商品数量,实现出库操作

3、删除商品信息

根据用户输入要进行删除的商品编号,如果找到该商品,则将该编号所对应的商品名称等各项信息均删除

4、修改商品信息

根据用户输入的商品编号找到该商品,若该商品存在,则可以修改商品的各项信息

5、查询商品信息

可以显示所有商品的信息,也可以输入商品编号,查询某一个商品的信息

四、系统的功能结构图

五、功能模块介绍 1、商品入库模块
  • 自动显示系统中已有的商品信息,如果还没有商品,显示没有记录。提示用户是否需要入库
  • 用户输入需要入库的商品编号,系统自动判断该商品是否已经存在,若存在则无法入库;若不存在,则提示用户输入商品的相关信息
  • 一条商品的所有信息均输入完成之后,系统还会询问是否继续进行其他商品的入库操作
2、商品出库模块
  • 自动显示系统中已有的商品信息,并提示用户输入需要出库的商品编号
  • 系统自动判断该商品是否已经存在,若存在则提示用户输入出库的数量;若不存在,则提示用户找不到该商品,无法进行出库操作
3、删除商品模块
  • 自动显示系统中已有的商品信息,并提示用户输入需要删除的商品编号
  • 系统自动判断该商品是否已经存在,若存在则提示用户是否删除该商品;若不存在则提示无法找到该商品
4、修改商品模块
  • 自动显示系统中已有的商品信息,并提示用户输入需要修改的商品编号
  • 系统自动判断该商品是否已经存在,若存在则提示用户输入新的商品信息;若不存在则提示无法找到该商品
5、查询商品模块
  • 通过用户输入的商品编号来查找商品,若存在则提示用户是否显示商品所有信息,若不存在则提示无法找到该商品
6、显示商品模块
  • 负责将所有商品的信息列表显示出来
六、详细设计 1、主函数

主函数运行后,首先调用菜单响应函数ShowMenu实现菜单的显示。

程序流程图如下所示。

2、商品入库模块

函数功能设计

  • 在主菜单的界面中输入“1”,即可进入商品入库模块。
  • 首先展示系统中的商品信息,并提示用户是否录入,用户输入字符y或者字符Y,则可以进行数据录入。
  • 首先录入商品编号,如果输入的商品编号已经存在,系统会提示用户该商品已经存在;若商品是第一次入库,用户则需陆续输入商品的名称、生产商、生产日期、价格和数量信息。
3、商品出库模块

函数功能设计

  • 在主菜单的界面中输入“2”,即可进入商品出库模块。
  • 首先也展示系统中所有商品信息,并提示用户输入要出库的商品编号。
  • 一旦商品编号确实是系统中已有的商品编号,则可以对该商品的数量进行修改。
  • 用户可以输入要出库的商品数量,如果用户输入的数量比商品的实际库存还要大,则自动将商品库存变成0。
  • 最后显示出库操作后所有商品的信息列表。
4、删除商品模块

函数功能设计

  • 在主菜单的界面中输入“3”,即可进入删除商品模块。
  • 同样先显示所有商品信息,若文件不存在或者没有记录,则不能进行删除操作。
  • 程序提示用户输入要删除的商品编号,系统会自动将该编号对应的商品条目彻底从文件中删除,最后会显示删除后的商品信息列表。
5、修改商品模块

函数功能设计

  • 在主菜单的界面中输入“4”,即可进入修改商品模块。
  • 和商品出库模块的不同之处在于,商品出库仅修改商品库存量,而修改商品模块可以修改商品信息的各个字段的数据。
  • 程序提示用户输入要修改的商品编号,如果此编号的商品存在,系统会自动提示用户输入要修改的各项商品信息。
  • 最后显示修改后的所有商品信息。
6、查询商品模块

函数功能设计

  • 在主菜单的界面中输入“5”,即可进入查询商品模块。
  • 查询时根据用户输入的商品编号进行查询,若查询的商品存在,则会提示用户找到该商品,是否查看详细信息显示。
  • 用户选择是,则显示商品的各种信息。如果查不到该商品,则提示用户找不到商品信息。
7、显示商品模块

函数功能设计

  • 在主菜单的界面中输入“6”,即可显示所有商品信息。
  • 通过列表的方式,显示商品的各个属性,以及每一条商品记录。
七、代码
#include
#include  
#include 

#define PRODUCT_LEN sizeof(struct Product) 
#define FORMAT "%-8d%-15s%-15s%-15s%-12.1lf%-8dn"
#define DATA astPro[i].iId,astPro[i].acName,astPro[i].acProducer,astPro[i].acDate,astPro[i].dPrice,astPro[i].iAmount
struct Product                        
{
	int  iId;                         
	char acName[15];                  
	char acProducer[15];              
	char acDate[15];                  
	double dPrice;                    
	int  iAmount;                     
};
struct Product astPro[100];           

void ShowMenu();                      
void InputProduct();                  
void OutputProduct();                 
void DeleteProduct();                 
void ModifyProduct();                 
void SearchProduct();                 
int ShowProduct();                   




void main()                           
{
	int iItem;
	ShowMenu();
	scanf("%d", &iItem);              
	while (iItem)
	{
		switch (iItem)
		{
		case 1:InputProduct(); break;  
		case 2:OutputProduct(); break; 
		case 3:DeleteProduct(); break; 
		case 4:ModifyProduct(); break; 
		case 5:SearchProduct(); break; 
		case 6:ShowProduct(); break;   
		default:printf("input wrong number"); 
		}
		getch();                       
		ShowMenu();                    
		scanf("%d", &iItem);           
	}
}

void ShowMenu()                        
{
	system("cls");
	printf("nnnnn");
	printf("tt|---------------------PRODUCT-------------------|n");
	printf("tt|t 1. input record                        |n");
	printf("tt|t 2. output record                       |n");
	printf("tt|t 3. delete record                       |n");
	printf("tt|t 4. modify record                       |n");
	printf("tt|t 5. search record                       |n");
	printf("tt|t 6. show record                         |n");
	printf("tt|t 0. exit                                |n");
	printf("tt|-----------------------------------------------|nn");
	printf("tttchoose(0-6):");
}


void InputProduct()                                    
{
	int i, iMax = 0;                                   
	char cDecide;                                      
	FILE *fp;                                          

	iMax = ShowProduct();

	if ((fp = fopen("product.txt", "ab")) == NULL)     
	{
		printf("can not open filen");                 
		return;
	}
	printf("press y/Y to input:");
	getchar();                                        
	cDecide = getchar();                              
	while (cDecide == 'y' || cDecide == 'Y')          
	{
		printf("Id:");                                
		scanf("%d", &astPro[iMax].iId);
		for (i = 0; i
			printf("the id is existing,press any key to continue!");
			getch();
			fclose(fp);                      
			return;
		}
		printf("Name:");                             
		scanf("%s", &astPro[iMax].acName);
		printf("Producer:");                         
		scanf("%s", &astPro[iMax].acProducer);
		printf("Date(Example 15-5-1):");             
		scanf("%s", &astPro[iMax].acDate);
		printf("Price:");                            
		scanf("%lf", &astPro[iMax].dPrice);
		printf("Amount:");                           
		scanf("%d", &astPro[iMax].iAmount);

		if (fwrite(&astPro[iMax], PRODUCT_LEN, 1, fp) != 1)  
		{
			printf("can not save!n");
			getch();                                 
		}
		else
		{
			printf("product Id %d is saved!n", astPro[iMax].iId);
			iMax++;
		}
		printf("press y/Y to continue input:");      
		getchar();                                   
		cDecide = getchar();                         
	}
	fclose(fp);                                      
	printf("Input is over!n");
}

void OutputProduct()                               
{
	FILE *fp;
	int iId, i, iMax = 0, iOut = 0;             
	char cDecide;                                  

	iMax = ShowProduct();

	if (iMax <= -1)                                 
	{
		printf("please input first!");
		return;
	}

	printf("please input the id:");
	scanf("%d", &iId);                             
	for (i = 0; i < iMax; i++)
	{
		if (iId == astPro[i].iId)                   
		{
			printf("find the product,press y/Y to output:");
			getchar();
			cDecide = getchar();
			if (cDecide == 'y' || cDecide == 'Y')   
			{
				printf("input the amount to output:");
				scanf("%d", &iOut);
				astPro[i].iAmount = astPro[i].iAmount - iOut;
				if (astPro[i].iAmount < 0)          
				{
					printf("the amount is less than your input and the amount is 0 now!n");
					astPro[i].iAmount = 0;          
				}
				if ((fp = fopen("product.txt", "rb+")) == NULL)     
				{
					printf("can not open filen");  
					return;
				}
				fseek(fp, i*PRODUCT_LEN, 0);        
				if (fwrite(&astPro[i], PRODUCT_LEN, 1, fp) != 1) 
				{
					printf("can not save file!n");
					getch();
				}
				fclose(fp);
				printf("output successfully!n");
				ShowProduct();                      
			}
			return;
		}
	}
	printf("can not find the product!n");         
}

void DeleteProduct()                                
{
	FILE *fp;
	int i, j, iMax = 0, iId;

	iMax = ShowProduct();

	if (iMax <= -1)                                 
	{
		printf("please input first!");
		return;
	}

	printf("please input the id to delete:");
	scanf("%d", &iId);
	for (i = 0; i
		if (iId == astPro[i].iId)                     
		{
			for (j = i; j < iMax; j++)
				astPro[j] = astPro[j + 1];
			iMax--;

			if ((fp = fopen("product.txt", "wb")) == NULL)  
			{
				printf("can not open filen");
				return;
			}
			for (j = 0; j
				printf("can not save!");
				getch();
			}
			fclose(fp);
			printf("delete successfully!n");
			ShowProduct();                      
			return;
		}
	}
	printf("can not find the product!n");
}


void ModifyProduct()                                
{
	FILE *fp;
	int i, iMax = 0, iId;

	iMax = ShowProduct();
	if (iMax <= -1)                                 
	{
		printf("please input first!");
		return;
	}

	printf("please input the id to modify:");
	scanf("%d", &iId);
	for (i = 0; i
		if (iId == astPro[i].iId)                  
		{
			printf("find the product, you can modify!n");
			printf("id:");
			scanf("%d", &astPro[i].iId);
			printf("Name:");
			scanf("%s", &astPro[i].acName);
			printf("Producer:");
			scanf("%s", &astPro[i].acProducer);
			printf("Date:");
			scanf("%s", &astPro[i].acDate);
			printf("Price:");
			scanf("%lf", &astPro[i].dPrice);
			printf("Amount:");
			scanf("%d", &astPro[i].iAmount);
			if ((fp = fopen("product.txt", "rb+")) == NULL)
			{
				printf("can not openn");
				return;
			}
			fseek(fp, i*PRODUCT_LEN, 0);             
			if (fwrite(&astPro[i], PRODUCT_LEN, 1, fp) != 1)
			{
				printf("can not save!");
				getch();
			}
			fclose(fp);
			printf("modify successful!n");
			ShowProduct();                        
			return;
		}
	}
	printf("can not find information!n");
}

void SearchProduct()                                 
{
	//FILE *fp;
	int iId, i, iMax = 0;
	char cDecide;

	iMax = ShowProduct();
	if (iMax <= -1)                                  
	{
		printf("please input first!");
		return;
	}

	printf("please input the id:");
	scanf("%d", &iId);
	for (i = 0; i
		printf("find the product,press y/Y to show:");
		getchar();
		cDecide = getchar();
		if (cDecide == 'y' || cDecide == 'Y')
		{
			printf("id      name           producer       date           price       amountn");
			printf(FORMAT, DATA);            
			return;
		}
	}
	printf("can not find the product");          
}


int ShowProduct()                              
{
	int i, iMax = 0;
	FILE *fp;
	if ((fp = fopen("product.txt", "rb")) == NULL)    
	{
		printf("can not open filen");                 
		return -1;
	}
	while (!feof(fp))                                  
	if (fread(&astPro[iMax], PRODUCT_LEN, 1, fp) == 1)
		iMax++;                                        
	fclose(fp);                                        

	if (iMax == 0)                                     
		printf("No record in file!n");
	else                                               
	{
		printf("id      name           producer       date           price       amountn");
		for (i = 0; i < iMax; i++)
		{
			printf(FORMAT, DATA);                      
		}
	}
	return iMax;
	fclose(fp);                                        
	if (iMax == 0)                                     
		printf("No record in file!n");
	else                                               
	{
		printf("id      name           producer       date           price       amountn");
		for (i = 0; i < iMax; i++)
		{
			printf(FORMAT, DATA);                      
		}
	}
	return iMax;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/994465.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号