商店仓库管理系统
一、问题描述
系统应具有下列主要功能:输入记录功能:从键盘输入货物信息:商品代号,商品名称, 数
量,价格,所属类别(如家用电器、日用品等)等;修改商品数量、删除记录功能、按商品代号查询、按商品代号排序并显示等功能。
二、基本要求
(1)使用面向对象编程思想编写开发过程中需要用到的类,使用继承的方法构造至少 3
个类(即商品类(虚基类),家用电器类和日用品类(派生类)),另外再设计一个管理类,
实现对商品的管理;
(2)输入和输出可以使用文本文件重定向输入(保存数据为磁盘文件);也可以使用标
准输入输出进行(提交时需要提交TXT格式输入数据)。包含各类商品信息,程序运行时进行初始化数据,使用vector 数组存放对象指针。并能保存数据为磁盘文件。
(3)程序运行时使用菜单显示添加(输入)记录,修改商品数量,浏览商品信息,按商品代号查找 ,删除记录。
(4)编写同名 display() 成员函数既虚函数,用来输出所有商品的信息。要求对<< 和>>
运算符进行重载,实现信息的输入输出。
(5) 基本功能要求具有增、删、改、查。
基本流程图
#include <iostream>//基本的输入输出
#include <fstream> //文件操作
#include <cstring>//strcmp函数,比较两个字符串
#include <conio.h>//用getch();
#include <vector>//vector数组
#define SIZE 100 //采用宏定义,定义char数组的大小
using namespace std;
class Goods//Goods类定义
{
public:
Goods(){
}//无参数无初值的构造函数 ,缺省构造函数
char Number[SIZE];//编号
char Name[SIZE];//商品名
int Amount;//数量
float Price;//价格
char Type[SIZE];//类别
Goods * Next;//指针
vector<Goods> Manage; //vector数组的定义
friend ostream& operator<<(ostream& out,Goods& obj)//重载<<输出运算符
{
out<<obj.Number<<obj.Name<<obj.Amount<<obj.Type;
}
friend istream& operator>>(istream& in,Goods& obj)//重载>>输入运算符
{
in>>obj.Number>>obj.Name>>obj.Amount>>obj.Type;
}
void SetType()//设置商品类别
{
cout<<" 请选择种类:"; cin>>Type;}
void SetName()//设置商品名
{
cout<<" 请输入商品的名称:"; cin>>Name;}
void SetNumber()//设置商品编号
{
cout<<" 请输入商品的编号:"; cin>>Number;}
void SetPrice()//设置类商品价格
{
cout<<" 请输入商品单价:"; cin>>Price;}
void SetAmount()//设置商品数量
{
cout<<" 请输入商品库存:"; cin>>Amount;}
void SetOther() //设置其他数据
{
cout<<" 请输入商品价格:"; cin>>Price;
cout<<" 请输入存货数量:"; cin>>Amount;}
void ReadFile(istream & in)//读取文件
{
in>>Name>>Type>>Number>>Price>>Amount;}
void SetAll()//成员函数 功能:输入信息
{
SetName();
SetType();
SetNumber();
SetOther();
}
void Show()//输出商品信息
{
cout<<"商品名: "<<Name<<endl<<"种类:"<<Type<<endl<<"编号: "<<Number<<endl<<"价格 "<<Price<<endl<<"商品库存: "<<Amount<<endl<<endl;}
};
class LifeGoods:public Goods//生活用品类
{
public:
LifeGoods(){
}//构造函数
~ LifeGoods(){
} //析构函数
char Number[SIZE];//编号
char Name[SIZE];//商品名
int Amount;//数量
float Price;//价格
};
class electricLifeGoods:public Goods//家用电器类
{
electricLifeGoods() {
}//构造函数
~electricLifeGoods(){
}//析构函数
char Number[SIZE];//编号
char Name[SIZE];/