资源描述
中南大学库存管理系统c
56
2020年4月19日
文档仅供参考
中南大学库存管理系统设计(C++)
v 题目六:库存管理系统设计
运用面向对象程序设计知识,利用C++语言设计和实现一个“库存管理系统设计”,主要完成对商品的销售、统计和简单管理。
超市中商品分为四类,分别是食品、化妆品、日用品和饮料。每种商品都包含商品名称、价格、库存量和品牌等信息。本系统要求具备如下主要功能:
(1)商品简单管理功能
² 添加功能:主要完成商品基本信息的添加。
² 查询功能:可按商品类别、商品名称、生产厂家、进货日期进行查询。若存在相应信息,输出所查询的信息,若不存在该记录,则提示“该记录不存在!”。
² 修改功能:可根据查询结果对相应的记录进行修改。
² 删除功能:主要完成商品信息的删除。先输入商品类别,再输入要删除的商品名称,根据查询结果删除该物品的记录,如果该商品不在物品库中,则提示“该商品不存在”。
(2)进货功能
按要求添加相应商品的信息到库存中。添加进货日期、生产厂家、进货价等信息。
(3)出货功能
出货时,先输入商品类别,然后输入商品名称,并在库存中查找该商品的相关信息。如果有库存量,输入出货的数量、出货日期,计算销售额和利润。如果库存量不够,给出提示信息,结束出货。
(4)统计功能
输出当前库存中所有商品的总数及详细信息;能统计每种商品一周时间内的销售额和利润;能统计每类商品的一周时间内的销售额和利润。输出统计信息时,要按从大到小进行排序。(根据个人能力,至少实现一种统计功能)
在实现过程中,需利用面向对象程序设计理论的基础知识,充分体现出C++语言关于类、继承和封装等核心概念,每一个类应包含数据成员和成员函数。
源代码
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>//用getch();
using namespace std;
class Goods //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌Goods类﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
public:
Goods(){}
int kind;
char name[20];//哇哈哈
char date[20];//进货日期
char brand[10];//品牌
char manufactor[10];//厂家
float buyprice; //进货价;
float saleprice; //卖出价;
int amount; //存货数量;
int amount1; //售货数量;
int profit; //净利润;
Goods * Next;
void InputAll()//输入全部函数
{
Inputmanufactor();
InputName();
InputKind();
Inputdate();
InputOther();
}
void InputKind()
{
cout<<"\t\t请选择种类:";cin>>kind;
}
void InputName()
{
cout<<"\t\t请输入商品的名称:"; cin>>name;
}
void Inputdate()
{
cout<<"\t\t请输入商品的进货日期:"; cin>>date;
}
void InputBuyprice()
{
cout<<"\t\t请输入进货价:"; cin>>buyprice;
}
void InputSaleprice()
{
cout<<"\t\t请输入售出价:"; cin>>saleprice;
}
void InputAmount()
{
cout<<"\t\t请输入剩余商品数量:"; cin>>amount;
}
void InputProfit()
{
cout<<"\t\t请输入净利润:"; cin>>profit;
}
void Inputmanufactor()
{
cout << "\t\t请输入商品厂家:"; cin >> manufactor;
}
void Inputbrand()
{
cout<<"\t\t请输入生产商品牌:"; cin>>brand;
}
void InputOther()
{
cout<<"\t\t请输入进货价:"; cin>>buyprice;
cout<<"\t\t请输入售出价:"; cin>>saleprice;
cout<<"\t\t请输入存货数量:"; cin>>amount;
cout<< "\t\t请输入商品的厂家:";cin>>manufactor;
cout<<"\t\t请输入生产商品牌:"; cin>>brand;
profit=0;
}
void ReadFile(istream &in)
{
in>>name>>kind>>date>>manufactor>>buyprice>>saleprice>>amount>>brand>>profit;
}
void Show()
{
cout<<"商品名: "<<name<<endl<<"种类:"<<kind<<endl<<"进货日期 "<<date<<endl<< "商品的厂家: " << manufactor<< endl<<"进货价 "<<buyprice<<endl<<"售出价 "<<saleprice<<endl<<"剩余商品数量: "<<
amount<<endl<<"净利润:"<<profit<<endl<<"生产商品牌: "<<brand<<endl<<endl<<endl;
}
};
class Goodsmessage : public Goods //﹌﹌﹌﹌﹌﹌﹌﹌﹌Goodsmessage类﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
public:
Goodsmessage();
~Goodsmessage();
void showMenu(int n);
void Find();
void Save();
void ModifyItem();
void RemoveItem();
void Swap(Goods *,Goods *);
void Paixu();
void Saleprice();
//void Chack();
int ListCount();
void Display()
{
system("cls");
i=0;
for(Goods * p=Head->Next;p!=End;p=p->Next)
{
p->Show();
i++;
}
cout<<"共有"<<i<<"个商品"<<"\n"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
void AddItem()//从键盘输入商品信息
{
system("cls");
showMenu(1);
End->InputKind();
End->InputName();
End->Inputdate();
End->InputOther();
End->Next = new Goods;
End=End->Next;
cout<<"添加成功!"<<endl;
Save();
cout<<"输入任意字符!返回主菜单。";
getch();
}
private:
Goods * Head,* End;
int i;
ifstream in;
ofstream out;
Goods *Findname(char * name)
{
for(Goods * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,不成功就返回空
if(!strcmp(p->Next->name,name))return p;
return NULL;
}
Goods *Findkind(int kind)
{
for(Goods * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,不成功就返回空
if(p->Next->kind==kind)return p;
return NULL;
}
Goods *Finddate(char * date)
{
for(Goods * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,不成功就返回空
if(!strcmp(p->Next->date,date))return p;
return NULL;
}
Goods *Findmanufactor(char * manufactor)
{
for(Goods * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,不成功就返回空
if(!strcmp(p->Next->manufactor,manufactor))return p;
return NULL;
}
};
Goodsmessage::Goodsmessage() //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌构造函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
Head=new Goods;
Head->Next=new Goods;
End=Head->Next;
in.open("market.txt");
if(!in)
cout<<"无商品信息。请先进货。"<<endl;
else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new Goods;
End=End->Next;
}
in.close();
cout<<"\t\t\t\t读取商品信息成功!"<<"\n"<<endl;
}
}
Goodsmessage::~Goodsmessage() //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析构函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
//Save();
for(Goods * temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete temp;
}
delete Head,End;
}
void Goodsmessage::showMenu(int n)//菜单 //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌菜单﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
switch(n)
{
case 1:
{
cout<<"********************************************************************************\n"
<<" 1. 食品 2. 化妆品 3. 日用品 4. 饮料 \n"
<<"********************************************************************************\n"<<endl;
break;}
case 2:
{
system("cls");
system("color F0");
cout<<"----------------------------------------------------------------------------"<<endl;
cout<<"********************* 库 存 管 理 系 统 **********************"<<endl;
cout<<"##################### 1.增加商品 ######################"<<endl;
cout<<"##################### 2.显示商品 ######################"<<endl;
cout<<"##################### 3.统计排序 ######################"<<endl;
cout<<"##################### 4.查找商品 ######################"<<endl;
cout<<"##################### 5.删除商品 ######################"<<endl;
cout<<"##################### 6.修改商品 ######################"<<endl;
cout<<"##################### 7.出货系统 ######################"<<endl;
cout<<"##################### 8.保存商品信息 ######################"<<endl;
cout<<"##################### 0.安全退出系统 ######################"<<endl;
cout<<"\t\t\t\t 请选择:0-8"<<endl;
break;}
case 3:
{
system("cls");
cout<<"********************************************************************************\n"
<<"\t 1. 修改商品名 2. 修改种类 3. 修改进货日期\n"
<<"\t 4. 修改进货价 5. 修改售出价 6. 修改剩余商品量\n"
<<"\t 7. 修改净利润 8. 修改商品品牌 9. 修改生产厂家\n"
<<"\t 10. 修改全部 0. 返回主菜单\n"
<<"*******************************************************************************"<<endl;
cout<<"\t\t\n\t\t\t\t 请选择:0-10"<<endl;
break;
}
case 4:
{
system("cls");
cout<<"********************************************************************************\n"
<<" 1. 按库存量排序 2. 按净利润排序 0.返回主菜单\n"
<<"********************************************************************************"<<endl;
cout<<"\t\t\n\t\t\t\t 请选择:0-3"<<endl;
break;
}
case 5:
{
system("cls");
cout<<"\n\t\t *********************************\n";
cout<<"\t\t ***** 1.按商品的名称查找 *****\n\t\t ***** 2.按生产厂家查找 *****\n\t\t ***** 3.按进货日期查找 *****\n\t\t ***** 4.按商品类别查找 *****\n\t\t ***** 0.返回主菜单 *****";
cout<<"\n\t\t *********************************\n请选择:0-4"<<endl;
break;
}
case 6:
{
system("cls");
system("color 3E");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t感谢您使用本库存管理系统,欢迎下次使用,再见!\n" << endl;
cout<<"\t\t请按任意键退出!\n\n\n\n\n\n\n\n\n\n\n"<<endl;
}
}
}
void Goodsmessage::Find() //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
system("cls");
char name[20] ,Id[10];
int x;
Goods * p=NULL;
showMenu(5);
cin>>x;
switch(x)
{
case 1:{cout<<"\t\t请输入要查找的商品的名称:";cin>>name;
if(p=Findname(name))
{
p->Next->Show();
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到该名称的商品!"<<'\n'<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}break;
case 2:
{
cout<<"\t\t请输入要查找的商品的生产厂家:";cin>>manufactor;
if(p=Findmanufactor(manufactor))
{
p->Next->Show();
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到该生产厂家的商品!"<<'\n'<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}break;
case 3:
{
cout<<"\t\t请输入要查找的商品的进货日期:";cin>>date;
if(p=Finddate(date))
{
p->Next->Show();
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到该进货日期的商品!"<<'\n'<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}break;
case 4:
{
cout<<"\t\t请输入要查找的商品的类型:";cin>>kind;
if(p=Findkind(kind))
{
p->Next->Show();
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到该种类的商品!"<<'\n'<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}break;
}
}
void Goodsmessage::ModifyItem() //修改商品信息
{
showMenu(3);
int x;
cin>>x;
switch(x)
{
case 1:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputName();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 2:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputKind();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 3:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->Inputdate();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 4:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputBuyprice();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 5:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputSaleprice();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 6:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputAmount();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 7:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputProfit();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 8:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->Inputbrand();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 9:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->Inputmanufactor();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
break;
}
case 10:
{
char name[20];
Goods * p=NULL;
cout<<"\t\t请输入要修改的商品的名称:";cin>>name;
if(p=Findname(name))
{
cout<<"\t\t已找到商品的信息,请输入新的信息!"<<endl;
p->Next->InputAll();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}
}
}
void Goodsmessage::RemoveItem() //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌删除商品信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
system("cls");
char Id[20];
Goods * p=NULL,*temp=NULL;
cout<<"\t\t请输入要删除的商品的名称:"<<endl;cin>>name;
if(p=Findname(name))
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t删除成功!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"\t\t没有找到您需要的商品!"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
}
}
void Goodsmessage::Saleprice() //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌售出商品﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
{
system("cls");
char name[20];int i;
Goods * p=NULL;
Goods * temp=NULL;
cout<<"\t\t请输入要售出的商品的名称和数量:"<<endl;cin>>name;cin>>i;
if(p=Findname(name))
{
if(p->Next->amount>i)
{
p->Next->amount -= i;
p->Next->amount1 += i;
p->Next->profit +=i*(p->Next->saleprice - p->Next->buyprice);
cout<<"商品售出成功!"<<"\n";
cout<<"售出商品名称: "<<name<<"\t"<<"数量: "<<i<<"\n";
cout<<"\n";
cout<<"售出后商品信息: "<<endl;
p->Next->Show();
Save();
cout<<"输入任意字符!返回主菜单";
getch();
}
else
{
cout<<"商品数量不够,不能购买"<<endl;
cout<<"输入任意字符!返回主菜单";
getch();
Saleprice();
}
}
else
{
cout<<"无此种商品,不能购买"<<endl;
cout<<"输入任意字符!继续……";
getch();
showMenu(2);
}
}
void Goodsmessage::Swap(Goods *p1, Goods *p2) //交换两个商品的数据
{
Goods *temp=new Goods;
strcpy(temp->name,p1->name);
strcpy(temp->manufactor,p1->manufact
展开阅读全文