资源描述
实训报告
题 目: 超市库存管理
院 系:
专 业:
姓 名:
学 号:
指导教师:
日 期:
目 录
一、 课题设计
1. 设计目的
2. 设计要求
二、需求分析
三、系统设计
1.系统采用的关键技术
2.主要类的说明
3. 系统模块图
4. 函数清单
5. 详细设计
五、测试
六、设计心得
七、附录(源程序)
一. 课题设计
1. 设计目的:
(1) 熟悉C++中类的概念、类的封装、继承的实现方式。
(2) 了解系统开发的需求分析、类层次设计、模块分析、编码测试、模块组装与整体调试的全过程。
(3) 深对C++的理解与Visual C++环境的使用。
(4) 逐步熟悉程序设计的方法,并养成良好的编程习惯。
2. 设计要求:
(1) 源程序要有适当的注释,使程序容易阅读。
(2) 必须用C++中的类,要求命令行界面用文件保存,不得把用数组保存和文件保存相混淆。
(3) 设计系统要求用C++语言。
(4) 设计的系统不仅要具备四个基本功能—增、删、改、查,还要具备“货物的有关信息数据存盘”的功能。因此,货物的有关信息数据既可以保存到磁盘文件,今后也可以从磁盘文件随时读出货物的有关信息。这样做,不仅方便用户使用,也可以避免数据录入。同时为了考虑到系统实现简洁,货物数据文件采用文本文件,货物数据文件名:date.dat。
二、 需求分析
随着现代生活水平的提高,超市这种便利的服务逐渐与我们的生活息息相关,如何更便利地对超市进行系统和有序的操作,成为了我们需要考虑的问题。
本程序运用C++程序设计了一个超市库存管理系统。
作为一个完整的系统,除了具有增加货物,删除货物的信息模块,还应该具有修改货物相关信息的功能。所以本系统具备了“商品入库”、“商品出库”、“查询统计”、“商品破损”、“退出系统”这5个基本功能,还可以在相应的硬盘上进行存盘以防止部分数据的丢失。这样一来,就可以用最简洁的方式实现对货物的管理,也就实现了系统的要求。
三、 系统设计
1. 系统采用的关键技术
a.仓库管理员类
class admin
{
public:
admin();
private:
string name;
};
b.仓库货架类
class shelf
{
public:
shelf();
private:
admin men;//管理员
string storeNo;//仓库编号
string kinds;//商品大类
string shelfNo;//货架号
};
2.主要类的说明
(1)使用面向对象的程序设计进行分析,整个系统涉及两大类可操作,仓库、商品。所以系统主要涉及两大类:仓库类、商品类。
(2)系统框架就是仓库类和商品类的定义。
(3)主函数中定义一个仓库对象,循环显示主菜单并根据用户选择调用仓库类的相应方法(成员函数)。
(4)考虑系统操作的货物信息具有不确定性,所以考虑使用链表保存、处理货物信息。
(5)仓库类包含:所有货物信息的一个不带头结点的链表及可以对货物信息进行增,改,删除,查询,数量设置,数据存盘等操作的相关模块为成员函数。所有货物都具有的公共信息及操作可以使用仓库类进行描述。
(6)仓库类包含:所有货物信息的一个不带头结点的链表及可以对货物信息进行增,改,删除,查询,数量设置,数据存盘等操作的相关模块为成员函数。所有货物都具有的公共信息及操作可以使用仓库类进行描述。
(7)退出系统:选择该项,自动退出该系统。
3. 系统模块图
商场库存货物管理系统
商品入库
查询统计
退出系统
商品信息
商品分类信息
按名称查询
按类别查询
商品出库
商品报损
直接退出
报损商品信息
4. 函数清单:
(1) 首页函数:first_face();
(2) 入库函数:in_storage();
(3) 出库函数:out_storage();
(4) 查询函数:void select_ele(); //查询
A.按商品名称查函数:void select_name();
B.按商品价格查询函数:select_price();
C.按大类查询函数:call_break();
(5) 商品报损函数:call_break();
5. 详细设计
1、 首页函数: [char first_face()……]
2. 新购商品入库函数:[void in_storage()……]
3. 商品信息删除函数:[void out_storage()……]
4. 商品信息查询函数:[void select_ele()……]
5. 商品报损函数: [ void call_break()……]
五、 测试
1. 系统选择界面
2. 商品入库:
3. 商品信息存盘:
4. 商品查询统计:
5. 商品破损:
6. 商品出库:
7. 系统退出:
六、 设计心得
在短短几天的时间里,完成了该系统的设计,对自己来说确实是一个不小的挑战。本系统的主要功能是管理员对超市库存商品的管理,可以进行查询、删除、添加、修改等操作。在设计这个超市库存管理系统的过程中,认识到自己所学的知识确实少得有点可怜,编写代码的时候有时会连最基本的语句都想不起来,只有通过查找课本还有网上的一些资料才慢慢进入设计状态。
通过本次超市库存管理系统的设计,认识到了自身C++的基础知识并不扎实,不过也让我再次熟悉数据库的设计过程。同时,我也能够基本掌握C++程序设计的方法,并且在此基础上掌握类的构造方法,明确类中构造函数、成员函数的建立以及调用,此外,另外,当我结合C++中字符串函数的编译系统给定的库函数,采用一定的逻辑编译,就可以实现系统设计的各项要求,达到设计目的,进而提高自己的C++语言使用水平。
学习是无止境的,要想有所建树就必须要付出比别人更多的努力,希望在以后的学习中可以有更深的认识,以取得更好的成绩!
七、附录(源程序)
//main.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <conio.h>
using namespace std;
//仓库管理员类
class admin
{
public:
admin();
private:
string name;
};
//仓库货架类
class shelf
{
public:
shelf();
private:
admin men;//管理员
string storeNo;//仓库编号
string kinds;//商品大类
string shelfNo;//货架号
};
//electrical class
class ele
{
public:
ele();
private:
string name;//商品名
double price;//介格
shelf sh;//所属货架
long count;//商品数量
};
//管理(组合类)
class mana
{
public:
mana();
char first_face();//首页
void in_storage();//入库
void out_storage();// 出库
void select_ele();//查询
void select_name();//按商品名称查询
void select_price();//按商品价格查询
void select_kind();//按大类查询
void call_break();//商品报损
private:
ele aele;
shelf ashelf;
admin abs;
};
//电器类默认构造函数
ele::ele():sh()
{
name = "xxx";//商品名
price = 0.0;//介格
count = 0;//商品数量
}
//仓库货架类默认构造函数
shelf::shelf():men()
{
storeNo = "xxx";//仓库编号
kinds = "xxx";//商品大类
shelfNo = "xxx";;//货架号
}
//仓库管理员类
admin::admin()
{
name = "xxx";
}
//管理类默认构造函数
mana::mana():aele(), ashelf(), abs()
{
}
char mana::first_face()
{
system("cls");
cout << endl;
cout <<endl <<"\t\t>>>>>>>>>>>>>>>>超市库存货物管理系统<<<<<<<<<<<<<<<<<<<<\t\t"
<<endl<<"\t--------------------------系统菜单显示如下---------------------\t"
<<endl <<"\t\t¥¥"
<<endl <<"\t\t¥¥ 1. 商品入库 ¥¥"
<<endl <<"\t\t¥¥ 2. 商品出库 ¥¥"
<<endl <<"\t\t¥¥ 3. 查询统计 ¥¥"
<<endl <<"\t\t¥¥ 4. 商品报损 ¥¥"
<<endl <<"\t\t¥¥ 5. 退出系统 ¥¥"
<<endl <<"\t\t---------------------------------------------------" <<endl <<endl <<"\t\t";
return getch();
}
//入库
void mana::in_storage()
{
system("cls");
string name;//商品名
double price;//介格
string storeNo;//仓库编号
string kinds;//商品大类
string shelfNo;//货架号
long count = 0; //商品数量
cout << endl << "商品入库,请输入相关信息 : " << endl << endl ;
cout << "\t商品名称 : ";
cin >> name;
cout << endl << "\t商品介格 : ";
cin >> price;
cout << endl << "\t商品数量 : ";
cin >> count;
cout << endl << "\t仓库编号 : ";
cin >> storeNo;
cout << endl << "\t商品大类 : ";
cin >> kinds;
cout << endl << "\t货架编号 : " ;
cin >> shelfNo;
ofstream storeFile("store.txt", ios::app);
storeFile << setiosflags(ios::left) << setw(20) << name << " "
<< setw(15) << price << " " << setw(10) << count << " "
<< setw(10) << storeNo << " " << setw(20) << kinds << " "
<< shelfNo << endl;
storeFile.close();
cout << endl << endl << "\t该商品已经入库......." << endl << endl << "\t";
system("pause");
}
// 出库
void mana::out_storage()
{
system("cls");
string name;//商品名
cout << endl << "\t商品出库,输入出库商品信息 : " << endl << endl;
cout << "\t商品名称 : ";
cin >> name;
ifstream storeFile("store.txt");
if (!storeFile)
{
ofstream storeFile1("store.txt");
storeFile1.close();
cout << endl << endl << "\t仓存为空!!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ofstream tempFile("temp.txt");
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1==name)
flag = true;
else
{
tempFile << setiosflags(ios::left) << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
}
tempFile.close();
storeFile.close();
if (!flag)
{
cout << endl << endl << "\t仓库中没有这种商品!!!" << endl << endl << "\t";
system("pause");
return;
}
ofstream storeFile1("store.txt");
ifstream tempFile1("temp.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();
cout << endl << "\t这些商品已经出库, 请仔细检查!!!" << endl << endl << "\t";
system("pause");
}
//查询
void mana::select_ele()
{
while (1)
{
system("cls");
cout << endl << endl;
cout << "\t=============================================================" << endl
<< "\t|| ||" << endl
<< "\t|| 商 品 查 询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 1. 按商品名称查询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 2. 按商品价格查询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 3. 按大类查询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 4. 返回 ||" << endl
<< "\t|| ||" << endl
<< "\t=============================================================" << endl << endl << "\t\t";
char select = getch();
switch (select)
{
case '1':
select_name();
break;
case '2':
select_price();
break;
case '3':
select_kind();
break;
case '4':
return;
default:
break;
}
}
}
//按商品名称查询
void mana::select_name()
{
system("cls");
cout << endl << "\t按商品名查询 : " << endl << endl ;
cout << "\t输入商品名 : ";
string name;
cin >> name;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFile("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你的库存为空!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1 == name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
if (!flag)
cout << endl << endl << "对不起,库存中没有这种商品!!!";
cout << endl << endl;
system("pause");
}
//按商品价格查询
void mana::select_price()
{
system("cls");
cout << endl << "\t按商品价格查询 : " << endl << endl ;
cout << "\t输入价格 : ";
double price;
cin >> price;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFile("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你的库存为空!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (price1 == price)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
if (!flag)
cout << endl << endl << "对不起,库存中没有这个价格的商品!!!";
cout << endl << endl;
system("pause");
}
//按大类查询
void mana::select_kind()
{
system("cls");
cout << endl << "\t按商品大类查询 : " << endl << endl ;
cout << "\t输入大类名 : ";
string kinds;
cin >> kinds;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFile("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你的库存为空!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (kinds1 == kinds)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
if (!flag)
cout << endl << endl << "对不起,库存中没有这类商品!!!";
cout << endl << endl;
system("pause");
}
//商品报损
void mana::call_break()
{
system("cls");
string name;//商品名
cout << endl << "\t商品报损,请输入要报损商品信息 : " << endl << endl;
cout << "\t商品名称 : ";
cin >> name;
ifstream storeFile("store.txt");
if (!storeFile)
{
ofstream storeFile1("store.txt");
storeFile1.close();
cout << endl << endl << "\t仓存为空!!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
string name1;//商品名
double price1;//介格
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ofstream tempFile("temp.txt");
string storeNo1;//仓库编号
cout << endl << endl << "你想报损商品信息如下 : " << endl << endl;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1==name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
shelfNo1 += "(损坏)";
}
tempFile << setiosflags(ios::left) << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
tempFile.close();
storeFile.close();
if (!flag)
{
cout << endl << endl << "对不起,仓库中没有这种商品!!!" << endl << endl;
system("pause");
return;
}
ofstream storeFile1("store.txt");
ifstream tempFile1("temp.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();
cout << endl << endl << "这些商品已经损坏,请尽快从仓库中取出!!!" << endl << endl;
cout << "报损成功,记录已经更改!!!" << endl << endl ;
system("pause");
}
int main()
{
char select;
mana men;
while (select = men.first_face())
{
switch (select)
{
case '1':
men.in_storage();
break;
case '2':
men.out_storage();
break;
case '3':
men.select_ele();
break;
case '4':
men.call_break();
break;
case '5':
cout << "\t" << "谢谢使用!!!!" << endl << endl << "\t\t";
exit( 0 );
break;
default:
break;
}
}
return 0; }
展开阅读全文