便利店管理系统
【题目】便利店管理系统
【目的】
通过设计一个小型的便利店管理系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。
【要求】
1、每个学生必须独立完成;
2、课程设计时间为1周;
3、设计语言采用C++;
4、学生有事离校必须请假。课程设计期间,无故缺席按旷课处理;缺席时间达四分之一以上者,未按规定上交实验报告的学生,其成绩按不及格处理。
【内容简介】
有一家小芳便利店,现在需要你为这个便利店开发一个简单的便利店管理系统,方便顾客自己购买商品,并提供对便利店销售情况的统计和管理功能。
【考核标准】
该系统为两种角色的用户提供服务,一种是便利店管理员,一种是顾客。便利店管理员根据账号、密码登录系统,顾客无需登录即可使用系统。
1、 顾客通过该系统购买商品,可实现多次购买一次性结账, 商品信息包括商品编号、商品名称、商品价格,商品包括普通商品和进口商品,进口同类商品价格是普通商品的1.2倍, 系统能够根据顾客的要求正确打印订单,订单内容包括订单编号、商品名称、商品的价格、商品数量、折扣等,显示进口商品名称时,在名称后加;管理员可以查看当天以及当月的所有订单,成绩≥60;
2、 系统退出后能保存当天的销售信息,要求每天一个文档,文档名按照日期命名。管理员可以根据订单编号查找删除修改某个订单,订单可以按照下单时间先后排序,成绩≥70;
3、 能够实现管理员对商品名称和价格的管理,包括对商品和对应价格的增加、修改、删除、查找,成绩≥80;
4、 系统可根据历史记录对销售情况进行统计,根据管理员的输入日期统计某天的销售情况并显示(包括一共销售多少单,销售额是多少,各种商品的销售情况),成绩≥90.
5、 有能力的话,可以考虑会员和非会员的情况.
要求:
用面向对象的程序设计方法设计该系统。本系统涉及的基本对象有订单对象、订单管理对象、商品对象、进口商品对象、购物篮对象、商店对象。实现对这些对象的合理抽象和封装,正确定义类之间的关系。界面合理,代码文件组织清晰,命名符合规范,代码注释清楚,课设报告书质量高。
【工作内容及工作计划】
一、 题目
便利店管理系统
二、 需求分析
1、 用户分析
管理员:
- 商品名称和价格的管理,包括对商品和对应价格的增加、修改、删除、查找;
- 输入日期统计某天的销售情况并显示;
- 管理员可以根据订单编号查找删除修改某个订单,订单可以按照下单时间先后排序;
- 查看当天以及当月的所有订单。
顾客: - 非会员和会员不同权限;
- 查看、选择、购买商品;
- 修改、删除、查找顾客购物车订单;
- 结账付款。
2、 文件系统分析 - 每天一个文档,文档名按照日期命名;
- 管理员账号、密码;
- 会员信息;
- 单个订单信息。
3、 对象分析 - 商店对象、列表对象、订单对象、订单管理对象、商品对象、购物篮对象、用户对象、管理员用户对象、顾客用户对象、时间日期对象、菜单对象、商品目录对象。
- 对象的合理抽象和封装,正确定义类之间的关系;
三、 系统结构图
四、 类的设计
五、 程序代码与说明
码云
UserClass.h
#ifndef USERCLASS_H
#define USERCLASS_H
#include <string>
using namespace std;
class UserClass
{
public:
/** Default constructor */
UserClass();
/** Default destructor */
virtual ~UserClass();
/** Access name * \return The current value of name */
string Getname() { return name; }
/** Set name * \param val New value to set */
void Setname(string val) { name = val; }
/** Access password * \return The current value of password */
string Getpassword() { return password; }
/** Set password * \param val New value to set */
void Setpassword(string val) { password = val; }
/** Access user_type * \return The current value of user_type */
int Getuser_type() { return user_type; }
/** Set user_type * \param val New value to set */
void Setuser_type(int val) { user_type = val; }
protected:
private:
string name; //!< Member variable "name"
string password; //!< Member variable "password"
/** *0-管理员 *1-顾客 */
int user_type; //!< Member variable "user_type"
};
#endif // USERCLASS_H
UserClass.cpp
#include "UserClass.h"
UserClass::UserClass()
{
//ctor
}
UserClass::~UserClass()
{
//dtor
}
Order_List.h
#ifndef ORDER_LIST_H
#define ORDER_LIST_H
#include "Order.h"
#include <io.h>
#include "List.h"
#include <cstdio>
#include <algorithm>
using namespace std;
class Order_List
{
public:
/** Default constructor */
Order_List();
/** Default destructor */
virtual ~Order_List();
/** Add Order * \param 添加订单 */
void Add_Order(Order new_order);
/** Read Order Messages in data/Order/Order * \param 读取文件内的订单信息 */
void Read_Order(string filename);
/** Write Order Messages To File in data/Order/Order * \param 写入文件内的订单信息 */
void Write_Order();
/** Delete Order * \param 删除订单 */
void del_Order(string del_orderID);
/** Print All Order Goods List * \param 输出订单列表 */
void Print_List();
/** Search Order And Return A Iterator Of Vector * \param 搜索订单,并且返回Vector的迭代器 */
vector<Order>::iterator Search_Order_ID(string order_ID);
/** Search Order * \param 搜索订单 */
void Search_Order(string order_ID);
/** Edit Order * \param 编辑订单 */
void Edit_Order(string order_ID);
/** Search Order * \param 搜索订单 */
void Search_Order();
/** Rank Order * \param 排序订单 */
void Rank_Order();
/** Count Order * \param 统计订单 */
void Count_Order_Date();
/** Clear Order * \param 清空订单列表 */
void clear();
protected:
private:
int ordernum;
vector<Order>order;
};
#endif // ORDER_LIST_H
Order_List.cpp
#include "Order_List.h"
Order_List::Order_List()
{
ordernum=0;
//order.resize(1000);
//ctor
}
Order_List::~Order_List()
{
//Write_Order();
//dtor
}
void Order_List::Add_Order(Order new_order){
//order[ordernum]=new_order;
order.push_back(new_order);
ordernum++;
}
void Order_List::Read_Order(string filename){
ifstream infile("data/Order/"+filename);
cout<<"正在读取订单信息..."<<endl;
string order_id,goods_id,goods_name,title[7];
int goods_is_enterport=0,goods_num;
double goods_price,goods_dicount;
for(int i=0;i<7;i++){
infile>>title[i];
}
//cout<<title[0]<<"\t"<<title[1]<<"\t"<<title[2]<<"\t"<<title[3]<<"\t"<<title[4]<<"\t"<<title[5]<<"\t"<<endl;
while(!infile.eof()){
infile>>order_id>>goods_id>>goods_name>>goods_price>>goods_num>>goods_is_enterport>>goods_dicount;
Goods tempgoods;
tempgoods.SetID(goods_id);
tempgoods.Setname(goods_name);
tempgoods.Setprice(goods_price);
tempgoods.Setnum(goods_num);
tempgoods.Setis_enterport(goods_is_enterport);
tempgoods.Setdiscount(goods_dicount);
tempgoods.Setis_cut(goods_dicount<1.00);
vector<Order>::iterator item=Search_Order_ID(order_id);
//tempgoods.Print_Col_Goods();
if(item==order.end()){
Order temporder(order_id);
temporder.List::Add_Goods(tempgoods);
Add_Order(temporder);
}else{
item->List::Add_Goods(tempgoods);
}
}
infile.close();
remove(("data/Order/"+filename).c_str());
}
void Order_List::Write_Order(){
int i=0;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
it->Fileout_List();
}
}
void Order_List::del_Order(string del_order_ID){
if(ordernum==0){
cout<<"没有任何订单"<<endl;
return;
}
vector<Order>::iterator item=Search_Order_ID(del_order_ID);
if(item==order.end()){
cout<<"没有此订单"<<endl;
}else{
order.erase(item);
ordernum--;
}
}
void Order_List::Print_List(){
if(ordernum==0){
cout<<"没有任何订单"<<endl;
return;
}
for(int i=0;i<ordernum;i++){
order[i].Print_Order();
order[i].Cal_Goods_List();
}
}
vector<Order>::iterator Order_List::Search_Order_ID(string order_ID){
for(vector<Order>::iterator it=order.begin();it!=order.end();it++){
if(order_ID==it->GetOrderID()){
return it;
}
}
return order.end();
}
void Order_List::Search_Order(string order_ID){
if(ordernum==0){
cout<<"没有任何订单"<<endl;
return;
}
vector<Order>::iterator item=Search_Order_ID(order_ID);
if(item==order.end()){
cout<<"没有此订单"<<endl;
}else{
item->Print_Order_All();
}
}
void Order_List::Edit_Order(string order_ID){
if(ordernum==0){
cout<<"没有任何订单"<<endl;
return;
}
vector<Order>::iterator item=Search_Order_ID(order_ID);
if(item==order.end()){
cout<<"没有此订单"<<endl;
}else{
//item->Edit_Goods();
item->Print_Order_All();
}
}
void Order_List::Search_Order(){
string OrderID_Str=CDate().GetDateString().substr(0,8);
int month[13]={0,1,1,1,2,2,2,3,3,3,4,4,4};
bool over=1;
while(over){
int op;
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<<" ---------------------- "<<endl;
scanf("%d",&op);
switch(op){
case 1:
{
cout<<" ----请输入订单编号---- "<<endl;
string seletID;
cin>>seletID;
vector<Order>::iterator tempitem=Search_Order_ID(seletID);
if(tempitem!=order.end()){
tempitem->Print_Order_All();
}else{
cout<<" ----查无此编号订单---- "<<endl;
}
break;
}
case 2:
{
int cnt=0,i=0;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(OrderID_Str.substr(0,8)==(it->GetOrderID()).substr(0,8)){
it->Print_Order_All();
cnt++;
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
break;
}
case 3:
{
int cnt=0,i=0;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(OrderID_Str.substr(0,6)==(it->GetOrderID()).substr(0,6)){
it->Print_Order_All();
cnt++;
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
break;
}
case 4:
{
int cnt=0,i=0;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(OrderID_Str.substr(0,4)==(it->GetOrderID()).substr(0,4)){
int a,b;
a=atoi(OrderID_Str.substr(4,2).c_str());
b=atoi((it->GetOrderID()).substr(4,2).c_str());
if(month[a]==month[b]){
it->Print_Order_All();
cnt++;
}
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
break;
}
case 5:
{
int cnt=0,i=0;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(OrderID_Str.substr(0,4)==(it->GetOrderID()).substr(0,4)){
it->Print_Order_All();
cnt++;
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
break;
}
case 6:
{
Print_List();
break;
}
case 7:
{
int cnt=0,i=0;
cout<<" --请输入订单编号前缀-- "<<endl;
string seletID;
cin>>seletID;
int len=seletID.size();
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(OrderID_Str.substr(0,len)==(it->GetOrderID()).substr(0,len)){
it->Print_Order_All();
cnt++;
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
break;
}
case 8:over=0;break;
default:
{
cout<<" -------无效操作------- "<<endl;
break;
}
}
}
}
void Order_List::Rank_Order(){
sort(order.begin(),order.end());
}
void Order_List::clear(){
order.clear();
ordernum=0;
}
void Order_List::Count_Order_Date(){
List Count_List;
int cnt=0,i=0,j=0;
cout<<" ----请输入订单日期---- "<<endl;
string seletID;
cin>>seletID;
for(vector<Order>::iterator it=order.begin();it!=order.end()&&i<ordernum;i++,it++){
if(seletID==(it->GetOrderID()).substr(0,8)){
it->Print_Order_All();
j=0;
for(vector<Goods>::iterator item=it->begin();item!=it->end()&&j<it->size();j++,item++){
Count_List.Add_Goods(*item);
}
cnt++;
}
}
if(!cnt)cout<<"没有任何订单"<<endl;
else{
cout<<"订单总数:"<<cnt<<endl;
cout<<"订单总销售额:"<<Count_List.GetAmount()<<endl;
Count_List.Print_List();
}
}
Order.h
#ifndef ORDER_H
#define ORDER_H
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
using namespace std;
#include "date.h"
#include "Goods.h"
#include <List.h>
class Order : public List
{
public:
/** Default constructor */
Order();
Order(string _OrderID);
/** Default destructor */
virtual ~Order();
/** Access OrderID * \return The current value of OrderID */
string GetOrderID() { return OrderID; }
/** Set OrderID * \param val New value to set */
void SetOrderID(string val) { OrderID = val; }
/** Create New Order * \param 新建订单 */
void New_Order();
/** Add Goods * \param 添加商品 */
void Add_Goods(Goods new_goods,int num);
/** Print Order ID And Order Goods List * \param 输出订单编号和订单商品列表 */
void Print_Order();
/** Print Order All Message * \param 输出订单所有信息 */
void Print_Order_All();
/** Save Order Message To File * \param 保存订单信息到文件 */
void Fileout_List();
/** Calculate All Goods Price And Print * \param 计算所有商品的总金额并且输出 */
void Cal_Goods_List();
/** Edit Goods Only Goods Num * \param 编辑商品 */
void Edit_Goods(vector<Goods>::iterator item);
/** Overload Operator * \param 重载<运算符 */
bool operator < (const Order &ord)const;
protected:
private:
string OrderID; //!< Member variable "OrderID"
string OrderDate; //!< Member variable "OrderDate"
};
#endif // ORDER_H
Order.cpp
#include "Order.h"
Order::Order()
{
//ctor
clear();
OrderID=CDate().GetDateString();//新建订单编号
OrderDate=CDate().GetDateOfCN(OrderID);//获取订单日期
amount=0;
}
Order::Order(string _OrderID):OrderID(_OrderID)
{
//ctor
OrderDate=CDate().GetDateOfCN(OrderID);//获取订单日期
amount=0;
}
Order::~Order()
{
//dtor
}
void Order::New_Order(){
Order();
}
void Order::Add_Goods(Goods new_goods,int num){
vector<Goods>::iterator it=Search_Goods_ID(new_goods.GetID());
if(it!=end()){
it->Setnum(it->Getnum()+num);
}else{
//goods[goodsnum]=new_goods;
goods.push_back(new_goods);
goods[goodsnum].Setnum(num);
goodsnum++;
}
}
void Order::Print_Order(){
cout<<"订单编号:"<<OrderID<<endl;
Print_List();
List::Cal_Goods_List();
cout<<"订单总金额:"<<amount<<endl;
cout<<"订单日期:"<<OrderDate<<endl;
}
void Order::Fileout_List(){
if(goodsnum==0){
cout<<"没有任何商品"<<endl;
return;
}
ofstream outfile("data/Order/"+OrderID);
outfile<<"订单编号:"<<OrderID<<endl;
if(goodsnum==0){
outfile<<"此订单没有任何商品"<<endl;
outfile.close();
return;
}
outfile<<std::left<<setw(20)<<"商品编号"<<
std::left<<setw(20)<<"商品名称"<<
std::left<<setw(20)<<"商品价格"<<
std::left<<setw(20)<<"数量"<<
std::left<<setw(20)<<"进口"<<
std::left<<setw(20)<<"折扣"<<endl;
for(int i=0;i<goodsnum;i++){
outfile<<std::left<<setw(20)<<goods[i].GetID()<<
std::left<<setw(20)<<goods[i].Getname()<<
std::left<<setw(20)<<goods[i].Getprice()<<
std::left<<setw(20)<<goods[i].Getnum()<<
std::left<<setw(20)<<(goods[i].Getis_enterport()?"YES":"NO")<<
std::left<<setw(20)<<goods[i].Getdiscount()<<endl;
}
List::Cal_Goods_List();
outfile<<"订单总金额:"<<amount<<endl;
outfile<<"订单日期:"<<OrderDate<<endl;
outfile.close();
string Orderdata=OrderID.substr(0,8);
ifstream _file("data/Order/"+Orderdata);
outfile.open("data/Order/"+Orderdata,std::ios::app | std::ios::out );
if(!_file){
outfile<<std::left<<setw(20)<<"订单编号"<<
std::left<<setw(20)<<"商品编号"<<
std::left<<setw(20)<<"商品名称"<<
std::left<<setw(20)<<"商品价格"<<
std::left<<setw(20)<<"数量"<<
std::left<<setw(20)<<"进口"<<
std::left<<setw(20)<<"折扣"<<endl;
}else{
outfile<<endl;
}
for(int i=0;i<goodsnum;i++){
outfile<<std::left<<setw(20)<<OrderID<<
std::left<<setw(20)<<goods[i].GetID()<<
std::left<<setw(20)<<goods[i].Getname()<<
std::left<<setw(20)<<goods[i].Getprice()<<
std::left<<setw(20)<<goods[i].Getnum()<<
std::left<<setw(20)<<goods[i].Getis_enterport()<<
goods[i].Getdiscount();
if(i<goodsnum-1)outfile<<endl;
}
outfile.close();
_file.close();
}
void Order::Cal_Goods_List(){
List::Cal_Goods_List();
cout<<"订单总金额:"<<amount<<endl;
}
void Order::Edit_Goods(vector<Goods>::iterator item){
cout<<" ----请输入购买数量---- "<<endl;
int seletnum;
cin>>seletnum;
while(seletnum<0||seletnum>(1<<30)||seletnum>item->Getnum()){
cout<<" --商品购买数量不合法-- "<<endl;
cout<<" ----请输入购买数量---- "<<endl;
cin>>seletnum;
}
item->Setnum(seletnum);
}
bool Order::operator < (const Order &ord)const{
return OrderID<ord.OrderID;
}
void Order::Print_Order_All(){
Print_Order();
Cal_Goods_List();
}
Goods_List.h
#ifndef GOODS_LIST_H
#define GOODS_LIST_H
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Goods.h"
#include <List.h>
class Goods_List : public List
{
public:
/** Default constructor */
Goods_List();
/** Default destructor */
virtual ~Goods_List();
protected:
private:
};
#endif // GOODS_LIST_H
Goods_List.cpp
#include "Goods_List.h"
Goods_List::Goods_List()
{
ifstream infile("data/Goods/Goods");
cout<<"正在读取商品信息..."<<endl;
string goods_id,goods_name,title[6];
int goods_is_enterport=0,goods_num;
double goods_price,goods_dicount;
for(int i=0;i<6;i++){
infile>>title[i];
}
//cout<<title[0]<<"\t"<<title[1]<<"\t"<<title[2]<<"\t"<<title[3]<<"\t"<<title[4]<<"\t"<<title[5]<<"\t"<<endl;
while(!infile.eof()){
infile>>goods_id>>goods_name>>goods_price>>goods_num>>goods_is_enterport>>goods_dicount;
Goods tempgoods;
tempgoods.SetID(goods_id);
tempgoods.Setname(goods_name);
tempgoods.Setprice(goods_price);
tempgoods.Setnum(goods_num);
tempgoods.Setis_enterport(goods_is_enterport);
tempgoods.Setdiscount(goods_dicount);
tempgoods.Setis_cut(goods_dicount<1.00);
Add_Goods(tempgoods);
}
infile.close();
//ctor
}
Goods_List::~Goods_List()
{
cout<<"正在存储商品信息..."<<endl;
ofstream outfile("data/Goods/Goods");
outfile<<std::left<<setw(20)<<"商品编号"<<
std::left<<setw(20)<<"商品名称"<<
std::left<<setw(20)<<"商品价格"<<
std::left<<setw(20)<<"数量"<<
std::left<<setw(20)<<"进口"<<
std::left<<setw(20)<<"折扣"<<endl;
for(int i=0;i<goodsnum;i++){
outfile<<std::left<<setw(20)<<goods[i].GetID()<<
std::left<<setw(20)<<goods[i].Getname()<<
std::left<<setw(20)<<goods[i].Getprice()<<
std::left<<setw(20)<<goods[i].Getnum()<<
std::left<<setw(20)<<goods[i].Getis_enterport()<<
goods[i].Getdiscount();
if(i<goodsnum-1)outfile<<endl;
}
outfile.close();
//dtor
}
List.h
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Goods.h"
class List
{
public:
/** Default constructor */
List();
/** Default destructor */
virtual ~List();
/** Add Goods * \param 添加商品 */
void Add_Goods(Goods new_goods);
/** Delete Goods * \param 删除商品 */
void del_Goods(string del_goodsID);
/** Print List * \param 输出列表 */
void Print_List();
/** Search Goods * \param 搜索商品 */
void Search_Goods(string goods_ID);
/** Edit Goods * \param 编辑商品 */
void Edit_Goods(vector<Goods>::iterator item);
/** Search Goods And Return A Iterator Of Vector * \param 搜索商品,并且返回Vector的迭代器 */
vector<Goods>::iterator Search_Goods_ID(string goods_ID);
/** Return Iterator Of Vector Begin * \param 返回Vector开始的迭代器 */
vector<Goods>::iterator begin();
/** Return Iterator Of Vector End * \param 返回Vector结束的迭代器 */
vector<Goods>::iterator end();
/** Return Size Of Vector * \param 返回Vector大小 */
int size();
/** Clear Vector * \param 清空Vector */
void clear();
/** Calculate All Goods Price * \param 计算所有商品的总金额 */
void Cal_Goods_List();
/** Return Amount * \param 获取总金额 */
double GetAmount();
protected:
int goodsnum;
vector<Goods>goods;
double amount;
private:
};
#endif // GOODS_LIST_H
List.cpp
#include "List.h"
List::List()
{
goodsnum=0;
//goods.resize(1000);
//ctor
}
List::~List()
{
//dtor
}
void List::Add_Goods(Goods new_goods){
vector<Goods>::iterator it=Search_Goods_ID(new_goods.GetID());
if(it!=end()){
it->Setnum(it->Getnum()+new_goods.Getnum());
}else{
//goods[goodsnum]=new_goods;
goods.push_back(new_goods);
goodsnum++;
}
}
void List::del_Goods(string del_goods_ID){
if(goodsnum==0){
cout<<"没有任何商品"<<endl;
return;
}
vector<Goods>::iterator item=Search_Goods_ID(del_goods_ID);
if(item==goods.end()){
cout<<"没有此商品"<<endl;
}else{
goods.erase(item);
goodsnum--;
}
}
void List::Print_List(){
if(goodsnum==0){
cout<<"没有任何商品"<<endl;
return;
}
cout<<std::left<<setw(15)<<"商品编号"<<
std::left<<setw(15)<<"商品名称"<<
std::left<<setw(15)<<"商品价格"<<
std::left<<setw(15)<<"数量"<<
std::left<<setw(15)<<"进口"<<
std::left<<setw(15)<<"折扣"<<endl;
for(int i=0;i<goodsnum;i++){
goods[i].Print_Row_Goods();
}
}
vector<Goods>::iterator List::Search_Goods_ID(string goods_ID){
for(vector<Goods>::iterator it=goods.begin();it!=goods.end();it++){
if(goods_ID==it->GetID()){
return it;
}
}
return goods.end();
}
void List::Search_Goods(string goods_ID){
if(goodsnum==0){
cout<<"没有任何商品"<<endl;
return;
}
vector<Goods>::iterator item=Search_Goods_ID(goods_ID);
if(item==goods.end()){
cout<<"没有此商品"<<endl;
}else{
item->Print_Col_Goods();
}
}
void List::Edit_Goods(vector<Goods>::iterator item){
string goods_name,title[6];
int goods_is_enterport=0,goods_num;
double goods_price,goods_dicount;
cout<<" ----请输入商品名称---- "<<endl;
cin>>goods_name;
cout<<" ----请输入商品数量---- "<<endl;
cin>>goods_num;
while(goods_num<0||goods_num>(1<<30)){
cout<<" ----商品数量不合法---- "<<endl;
cout<<" ----请输入商品数量---- "<<endl;
cin>>goods_num;
}
cout<<" ----请输入商品价格---- "<<endl;
cin>>goods_price;
while(goods_price<=0||goods_price>(1<<30)){
cout<<" ----商品价格不合法---- "<<endl;
cout<<" ----请输入商品价格---- "<<endl;
cin>>goods_price;
}
cout<<" --请输入是否进口(0/1)-- "<<endl;
cin>>goods_is_enterport;
while(goods_is_enterport!=0&&goods_is_enterport!=1){
cout<<" ----输入信息不合法----- "<<endl;
cout<<" --请输入是否进口(0/1)-- "<<endl;
cin>>goods_is_enterport;
}
cout<<" ----请输入商品折扣---- "<<endl;
cin>>goods_dicount;
while(goods_dicount<=0||goods_dicount>1){
cout<<" ----商品折扣不合法---- "<<endl;
cout<<" ----请输入商品折扣---- "<<endl;
cin>>goods_dicount;
}
cout<<" ----正在存储商品...--- "<<endl;
item->Setname(goods_name);
item->Setprice(goods_price);
item->Setnum(goods_num);
item->Setis_enterport(goods_is_enterport);
item->Setdiscount(goods_dicount);
item->Setis_cut(goods_dicount<1.00);
cout<<" -----存储商品完成----- "<<endl;
}
vector<Goods>::iterator List::begin(){
return goods.begin();
}
vector<Goods>::iterator List::end(){
return goods.end();
}
int List::size(){
return goodsnum;
}
void List::clear(){
goodsnum=0;
goods.clear();
}
void List::Cal_Goods_List(){
amount=0;
for(int i=0;i<goodsnum;i++){
amount+=goods[i].Getprice()*goods[i].Getnum()*goods[i].Getdiscount();
}
}
double List::GetAmount(){
Cal_Goods_List();
return amount;
}
Goods.h
#ifndef GOODS_H
#define GOODS_H
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
class Goods
{
public:
/** Default constructor */
Goods();
/** Default constructor */
Goods(string _ID,string _name, bool _is_enterport,int _num,bool _is_cut,double _discount,double _price);
/** Default destructor */
virtual ~Goods();
/** Copy constructor * \param other Object to copy from */
Goods(const Goods& other);
/** Assignment operator * \param other Object to assign from * \return A reference to this */
Goods& operator=(const Goods& other);
/** Access ID * \return The current value of ID */
string GetID() { return ID; }
/** Set ID * \param val New value to set */
void SetID(string val) { ID = val; }
/** Access name * \return The current value of name */
string Getname() { return name; }
/** Set name * \param val New value to set */
void Setname(string val) { name = val; }
/** Access is_enterport * \return The current value of is_enterport */
bool Getis_enterport() { return is_enterport; }
/** Set is_enterport * \param val New value to set */
void Setis_enterport(bool val) { is_enterport = val; }
/** Access num * \return The current value of num */
int Getnum() { return num; }
/** Set num * \param val New value to set */
void Setnum(int val) { num = val; }
/** Access is_cut * \return The current value of is_cut */
bool Getis_cut() { return is_cut; }
/** Set is_cut * \param val New value to set */
void Setis_cut(bool val) { is_cut = val; }
/** Access discount * \return The current value of discount */
double Getdiscount() { return discount; }
/** Set discount * \param val New value to set */
void Setdiscount(double val) { discount = val; }
/** Access price * \return The current value of price */
double Getprice() { return price; }
/** Set price * \param val New value to set */
void Setprice(double val) { price = val; }
/** Print Goods * \param Print Goods Message Using Row */
void Print_Row_Goods();
/** Print Goods * \param Print Goods Message Using Col */
void Print_Col_Goods();
protected:
private:
string ID; //!< Member variable "ID" 商品编号
string name; //!< Member variable "name" 商品名称
bool is_enterport; //!< Member variable "is_enterport" 进口标记
int num; //!< Member variable "num" 商品数量
bool is_cut; //!< Member variable "is_cut" 打折标记
double discount; //!< Member variable "discount" 折扣
double price; //!< Member variable "price" 商品价格
const float rate=1.2;
};
#endif // GOODS_H
Goods.cpp
#include "Goods.h"
Goods::Goods()
{
//ctor
}
Goods::Goods(string _ID,string _name, bool _is_enterport,int _num,bool _is_cut,double _discount,double _price):ID(_ID),name(_name),is_enterport(_is_enterport),num(_num),is_cut(_is_cut),discount(_discount),price(_price)
{
//ctor
}
Goods::~Goods()
{
//dtor
}
Goods::Goods(const Goods& other)
{
//copy ctor
if (this == &other) return ; // handle self assignment
//assignment operator
this->ID=other.ID;
this->name=other.name;
this->is_enterport=other.is_enterport;
this->num=other.num;
this->is_cut=other.is_cut;
this->discount=other.discount;
this->price=other.price;
return ;
}
Goods& Goods::operator=(const Goods& rhs)
{
if (this == &rhs) return *this; // handle self assignment
//assignment operator
this->ID=rhs.ID;
this->name=rhs.name;
this->is_enterport=rhs.is_enterport;
this->num=rhs.num;
this->is_cut=rhs.is_cut;
this->discount=rhs.discount;
this->price=rhs.price;
return *this;
}
void Goods::Print_Row_Goods(){
cout<<left<<setw(15)<<ID<<name<<
left<<setw(15)<<(is_enterport?"<I>":"")<<
left<<setw(15)<<price<<
left<<setw(15)<<num<<
left<<setw(15)<<(is_enterport?"YES":"NO")<<
left<<setw(15)<<discount<<endl;
}
void Goods::Print_Col_Goods(){
cout<<std::left<<setw(15)<<"商品编号:"<<ID<<endl;
cout<<std::left<<setw(15)<<"商品名称:"<<name<<(is_enterport?"<I>":"")<<endl;
cout<<std::left<<setw(15)<<"商品价格:"<<price<<endl;
cout<<std::left<<setw(15)<<"数量:"<<num<<endl;
cout<<std::left<<setw(15)<<"进口:"<<(is_enterport?"YES":"NO")<<endl;
cout<<std::left<<setw(15)<<"折扣:"<<discount<<endl;
}
date.h
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include<ctime>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
class CDate{
int d,m,y,hh,mm,ss;
const string df_s;//xxxx-xx-xx
const string df_l;//xxxx年xx月xx日
const string df_h;//xxxx年xx月xx日xx时xx分xx秒
public:
/** Default constructor */
CDate();
/** Default constructor */
~CDate();
/** Return Date String * \param 获取固定格式日期字符串 */
string format(string df);
/** Return Only Number Date String * \param 获取纯数字日期字符串 */
string GetDateString();
/** Return Date Form Only Number Date String * \param 获取数字日期字符串的日期 */
string GetDateOfCN(string DateString);
private:
/** Return At Least Two Bit Digit Form A Number * \param 获取固定格式日期字符串 */
string twobitstr(int x);
};
#endif
date.cpp
#include"date.h"
CDate::CDate():df_s("ddd"),df_l("DDD"),df_h("HHMMSS") //初始化
{
time_t now;
time(&now);
struct tm *t_now;
t_now = localtime(&now);
y = t_now -> tm_year + 1900;
m = t_now -> tm_mon + 1;
d = t_now -> tm_mday;
hh = t_now -> tm_hour;
mm = t_now -> tm_min;
ss = t_now -> tm_sec;
}
CDate::~CDate()
{
//dtor
}
string CDate::format(string df)
{
char c_df[20];
if(df == df_s)
{
sprintf(c_df, "%d-%d-%d", y, m, d);
return string(c_df);
}
if(df == df_l)
{
sprintf(c_df, "%d年%d月%d日", y, m, d);
return string(c_df);
}
if(df == df_h)
{
sprintf(c_df, "%d年%d月%d日%d时%d分%d秒", y, m, d,hh,mm,ss);
return string(c_df);
}
return string("");
}
string CDate::GetDateString(){
return twobitstr(y)+twobitstr(m)+twobitstr(d)+twobitstr(hh)+twobitstr(mm)+twobitstr(ss);
}
string CDate::GetDateOfCN(string DateString){
char c_df[20];
int year,month,day,hour,minute,second;
sscanf(DateString.substr(0,4).c_str(),"%d",&year);
sscanf(DateString.substr(4,2).c_str(),"%d",&month);
sscanf(DateString.substr(6,2).c_str(),"%d",&day);
sscanf(DateString.substr(8,2).c_str(),"%d",&hour);
sscanf(DateString.substr(10,2).c_str(),"%d",&minute);
sscanf(DateString.substr(12,2).c_str(),"%d",&second);
sprintf(c_df, "%d年%d月%d日%d时%d分%d秒", year, month, day,hour,minute,second);
return string(c_df);
}
string CDate::twobitstr(int x){
string res="";
int xx=x;
while(x){
res=char('0'+(x%10))+res;
x/=10;
}
if(xx<10)
res='0'+res;
return res;
}
Store.h
#ifndef STORE_H
#define STORE_H
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <io.h>
#include <windows.h>
using namespace std;
#include "date.h"
#include "Goods.h"
#include "Order.h"
#include "UserClass.h"
#include "Goods_List.h"
#include "Order_List.h"
class Store
{
public:
Store();
~Store();
/** Start System * \param 启动系统 */
void Start();
protected:
private:
/** Error Messages * \param 提示用户的非法操作 */
void err();
/** Exit System * \param 退出系统 */
void exit();
/** Menu * \param 系统操作菜单 */
void menu(int item);
/** Read Goods Messages in data/Goods/Goods * \param 读取文件内的商品信息 */
//void Read_Goods();
/** Read Order Messages in data/Order/ * \param 读取文件内的订单文件信息 */
void Read_Order_List();
/** Purchase Goods * \param 购买商品 */
void Purchase();
/** Manage Goods * \param 管理商品 */
void Manage_Goods();
/** Manage Order * \param 管理订单 */
void Manage_Order();
/** Check User Messages * \param 验证身份信息 */
bool check_login(string user,string psd);
/** Set User Messages * \param 设置当前系统用户的身份信息 */
void setuser(string username,string password,int type);
/** Login * \param 登录 */
void login();
/** Logout * \param 登出 */
void logout();
/** Admin Main Page * \param 系统主页面 */
void admin_run();
/** Ghost Main Page * \param 系统主页面 */
void ghost_run();
/** Initialize * \param 初始化系统信息 */
void init();
CDate StoreData;//时间日期对象
bool on;//系统开启状态标记
bool online;//用户在线标记
UserClass NowUser;//当前用户
Goods_List AllGoods_List;//商品列表
Order_List AllOrder_List;//订单列表
};
#endif // STORE_H
Store.cpp
#include "Store.h"
Store::Store()
{
cout<<"系统初始化中..."<<endl;
on=false;
online=false;
init();//初始化系统
//ctor
}
Store::~Store()
{
if(on)exit();//非正常退出存储数据
//dtor
}
void Store::Read_Order_List(){
char * path = "data/Order";//自己设置目录
cout<<"正在读取订单信息..."<<endl;
vector<string> files;
//文件句柄
long hFile = 0;
//文件信息,声明一个存储文件信息的结构体
struct _finddata_t fileinfo;
string p;//字符串,存放路径
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1){//若查找成功,则进入
do{
files.push_back(fileinfo.name);
} while (_findnext(hFile, &fileinfo) == 0);
//_findclose函数结束查找
_findclose(hFile);
}
int size = files.size();
for (int i = 0; i < size; i++){
cout << files[i].c_str() << endl;
if(files[i].size()==8){//读取订单
AllOrder_List.Read_Order(files[i]);
}
}
}
void Store::Purchase(){
AllGoods_List.Print_List();
Order order;//新建订单对象
bool over=1;
while(over&&on){
int op;
menu(4);
scanf("%d",&op);
switch(op){
case 1://选择商品
{
cout<<" ----请输入商品编号---- "<<endl;
string seletID;
cin>>seletID;
//询问是否存在此商品
vector<Goods>::iterator tempitem=AllGoods_List.Search_Goods_ID(seletID);
if(tempitem!=AllGoods_List.end()){
cout<<" ----请输入购买数量---- "<<endl;
int seletnum;
cin>>seletnum;
vector<Goods>::iterator item=order.Search_Goods_ID(seletID);
int nownum= item!=order.end()?item->Getnum():0;
//判断数量合法性
while(seletnum+nownum<0||seletnum+nownum>(1<<30)||seletnum+nownum>tempitem->Getnum()){
cout<<" --商品购买数量不合法-- "<<endl;
cout<<" ----请输入购买数量---- "<<endl;
cin>>seletnum;
}
order.Add_Goods(*tempitem,nownum+seletnum);
cout<<" -----添加商品成功----- "<<endl;
}else{
cout<<" ----查无此编号商品---- "<<endl;
}
break;
}
case 2:AllGoods_List.Print_List();break;
case 3:order.Print_Order();break;
case 4://订单管理
{
order.Print_Order();
cout<<" ----请输入商品编号---- "<<endl;
string seletID;
cin>>seletID;
vector<Goods>::iterator tempitem=order.Search_Goods_ID(seletID);
if(tempitem!=order.end()){
cout<<" ------请选择操作------ "<<endl;
cout<<" | 1.详情 | "<<endl;
cout<<" | 2.修改 | "<<endl;
cout<<" | 3.删除 | "<<endl;
cout<<" ---------------------- "<<endl;
int edit_op;
scanf("%d",&edit_op);
switch(edit_op){
case 1:tempitem->Print_Col_Goods();break;
case 2:order.Edit_Goods(tempitem);break;
case 3:order.del_Goods(seletID);break;
default:err();break;
}
}else{
cout<<" ----查无此编号商品---- "<<endl;
}
break;
}
case 5:
{
//检查订单正确性
int flag=0;
for(vector<Goods>::iterator it=order.begin();it!=order.end();it++){
vector<Goods>::iterator tempitem=AllGoods_List.Search_Goods_ID(it->GetID());
if(tempitem!=AllGoods_List.end()){
tempitem->Setnum(tempitem->Getnum()-it->Getnum());
}else{
cout<<" -------错误订单------- "<<endl;
flag=1;
break;
}
}
if(flag)break;
cout<<" -------结账中...------ "<<endl;
order.Print_Order();
order.Cal_Goods_List();
//order.Fileout_List();
AllOrder_List.Add_Order(order);
order.clear();
cout<<" -------结账完成------- "<<endl;
cout<<" -是否开始新订单?(0/1) "<<endl;
cin>>over;
if(over)order.New_Order();
break;
}
case 6:err();break;
case 7:err();break;
case 8:over=0;break;
case 9:exit();break;
default:err();break;
}
}
}
void Store::Manage_Goods(){
AllGoods_List.Print_List();
bool over=1;
while(over&&on){
int op;
menu(6);
scanf("%d",&op);
switch(op){
case 1:AllGoods_List.Print_List();break;
case 2:
{
string goods_id,goods_name,title[6];
int goods_is_enterport=0,goods_num;
double goods_price,goods_dicount;
cout<<" ----请输入商品编号---- "<<endl;
cin>>goods_id;
vector<Goods>::iterator tempitem=AllGoods_List.Search_Goods_ID(goods_id);
while(tempitem!=AllGoods_List.end()){
cout<<" ----商品编号已存在---- "<<endl;
cout<<" ----请输入商品编号---- "<<endl;
cin>>goods_id;
tempitem=AllGoods_List.Search_Goods_ID(goods_id);
}
cout<<" ----请输入商品名称---- "<<endl;
cin>>goods_name;
cout<<" ----请输入商品数量---- "<<endl;
cin>>goods_num;
while(goods_num<0||goods_num>(1<<30)){
cout<<" ----商品数量不合法---- "<<endl;
cout<<" ----请输入商品数量---- "<<endl;
cin>>goods_num;
}
cout<<" ----请输入商品价格---- "<<endl;
cin>>goods_price;
while(goods_price<=0||goods_price>(1<<30)){
cout<<" ----商品价格不合法---- "<<endl;
cout<<" ----请输入商品价格---- "<<endl;
cin>>goods_price;
}
cout<<" --请输入是否进口(0/1)-- "<<endl;
cin>>goods_is_enterport;
while(goods_is_enterport!=0&&goods_is_enterport!=1){
cout<<" ----输入信息不合法----- "<<endl;
cout<<" --请输入是否进口(0/1)-- "<<endl;
cin>>goods_is_enterport;
}
cout<<" ----请输入商品折扣---- "<<endl;
cin>>goods_dicount;
while(goods_dicount<=0||goods_dicount>1){
cout<<" ----商品折扣不合法---- "<<endl;
cout<<" ----请输入商品折扣---- "<<endl;
cin>>goods_dicount;
}
cout<<" ----正在存储商品...--- "<<endl;
Goods tempgoods;
tempgoods.SetID(goods_id);
tempgoods.Setname(goods_name);
tempgoods.Setprice(goods_price);
tempgoods.Setnum(goods_num);
tempgoods.Setis_enterport(goods_is_enterport);
tempgoods.Setdiscount(goods_dicount);
tempgoods.Setis_cut(goods_dicount<1.00);
AllGoods_List.Add_Goods(tempgoods);
cout<<" -----存储商品完成----- "<<endl;
break;
}
case 3:
{
cout<<" ----请输入商品编号---- "<<endl;
string seletID;
cin>>seletID;
vector<Goods>::iterator tempitem=AllGoods_List.Search_Goods_ID(seletID);
if(tempitem!=AllGoods_List.end()){
cout<<"商品删除中..."<<endl;
AllGoods_List.del_Goods(seletID);
cout<<"商品删除完成..."<<endl;
}else{
cout<<" ----查无此编号商品---- "<<endl;
}
break;
}
case 4:
{
cout<<" ----请输入商品编号---- "<<endl;
string seletID;
cin>>seletID;
vector<Goods>::iterator tempitem=AllGoods_List.Search_Goods_ID(seletID);
if(tempitem!=AllGoods_List.end()){
cout<<"商品编辑中..."<<endl;
AllGoods_List.Edit_Goods(tempitem);
cout<<"商品编辑完成..."<<endl;
}else{
cout<<" ----查无此编号商品---- "<<endl;
}
break;
}
case 5:break;
case 6:err();break;
case 7:err();break;
case 8:over=0;break;
case 9:exit();break;
default:err();break;
}
}
}
void Store::Manage_Order(){
AllOrder_List.Print_List();
bool over=1;
while(over&&on){
int op;
menu(5);
scanf("%d",&op);
switch(op){
case 1:
{
AllOrder_List.Search_Order();
break;
}
case 2:
{
Purchase();break;
}
case 3:
{
cout<<" ----请输入订单编号---- "<<endl;
string seletID;
cin>>seletID;
AllOrder_List.del_Order(seletID);
break;
}
case 4:
{
cout<<" ----请输入订单编号---- "<<endl;
string seletID;
cin>>seletID;
AllOrder_List.Edit_Order(seletID);
break;
}
case 5:
{
cout<<" ----请输入订单编号---- "<<endl;
string seletID;
cin>>seletID;
AllOrder_List.Search_Order(seletID);
break;
}
case 6:
{
AllOrder_List.Rank_Order();
AllOrder_List.Print_List();break;
}
case 7:
{
AllOrder_List.Count_Order_Date();break;
}
case 8:over=0;break;
case 9:exit();break;
default:err();break;
}
}
}
void Store::err(){
cout<<" -------无效操作------- "<<endl;
}
void Store::exit(){
logout();
on=false;//关闭系统
cout<<" -----欢迎下次使用----- "<<endl;
}
void Store::menu(int item){
/* 1:登录菜单 2:管理员主页面菜单 3:顾客主页面菜单 4:购买菜单 */
switch(item){
case 1://用户选择页面
{
cout<<" ----请选择用户类型---- "<<endl;
cout<<" | 1.管理员 | "<<endl;
cout<<" | 2.顾客 | "<<endl;
cout<<" | 3.退出 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
case 2://管理员主页面
{
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<<" | 9.退出系统 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
case 3://顾客主页面
{
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<<" | 9.退出系统 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
case 4://购买页面
{
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<<" | 9.退出系统 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
case 5://订单管理页面
{
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<<" | 9.退出系统 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
case 6://商品管理页面
{
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<<" | 9.退出系统 | "<<endl;
cout<<" ---------------------- "<<endl;
break;
}
default:err();break;
}
}
void Store::logout(){
AllOrder_List.Write_Order();
AllOrder_List.clear();
cout<<" -----退出登录成功----- "<<endl;
online=false;
}
void Store::admin_run(){
Read_Order_List();
cout<<" ------欢迎"<<NowUser.Getname()<<"------ "<<endl;
while(on&&online){
int op;
menu(2);
scanf("%d",&op);
switch(op){
case 1:AllGoods_List.Print_List();break;
case 2:Manage_Order();break;
case 3:Manage_Goods();break;
case 4:err();break;
case 5:err();break;
case 6:err();break;
case 7:err();break;
case 8:logout();break;
case 9:exit();break;
default:err();break;
}
}
}
void Store::ghost_run(){
AllGoods_List.Print_List();
cout<<" ------欢迎"<<NowUser.Getname()<<"------ "<<endl;
while(on&&online){
int op;
menu(3);
scanf("%d",&op);
switch(op){
case 1:Purchase();break;
case 2:AllGoods_List.Print_List();break;
case 3:AllOrder_List.Print_List();break;
case 4:err();break;
case 5:err();break;
case 6:err();break;
case 7:err();break;
case 8:logout();break;
case 9:exit();break;
default:err();break;
}
}
}
bool Store::check_login(string user,string psd){
ifstream infile("data/User/Admin");
cout<<"正在验证身份..."<<endl;
string fname,fpsd;
infile>>fname>>fpsd;//抛弃文件标题行
bool res=0;//正确性标记
while(!infile.eof()){
infile>>fname>>fpsd;
//cout<<fname<<" "<<fpsd<<endl;
if(user==fname&&psd==fpsd){
res=1;
break;
}
}
infile.close();
return res;
}
void Store::setuser(string username,string password,int type){
NowUser.Setname(username);//set now system user
NowUser.Setpassword(password);
NowUser.Setuser_type(type);
online=true;
}
void Store::login(){
if(online){
cout<<" --------已登录-------- "<<endl;
return;
}
while(on){
menu(1);
int op;
scanf("%d",&op);
switch(op){
case 1://管理员登录
{
cout<<" -----请输入账号----- "<<endl;
string username="";
cin>>username;
cout<<" -----请输入密码----- "<<endl;
string password="";
cin>>password;
if(check_login(username,password)){
setuser(username,password,0);
cout<<" ------登录成功------ "<<endl;
admin_run();
}else{
cout<<" ---账号或密码错误--- "<<endl;
}
break;
}
case 2://顾客登录
{
setuser("ghost","123456",1);
ghost_run();//运行主程序
break;
}
case 3:exit();break;
default:err();break;
}
}
}
void Store::init(){
on=true;//打开系统
SetConsoleTitle("浙江理工大学便利店管理系统");
cout<<"今天是"<<StoreData.format("HHMMSS")<<endl;
cout<<"欢迎您的使用便利店管理系统!"<<endl;
cout<<endl;
}
void Store::Start(){
login();//调用登录
}
main.cpp
/* *@Author: STZG *@Language: C++ */
#include "Store.h"
Store mystore;
int main()
{
mystore.Start();
//cout << "Hello world!" << endl;
return 0;
}
六、 运行结果与分析
七、 心得与体会
- 掌握类的概念、类的定义格式、类与结构的关系、类的成员属性和类的封装性;
- 掌握类对象的定义;
- 理解类的成员的访问控制的含义,公有、私有和保护成员的区别;
- 掌握构造函数和析构函数的含义与作用、定义方式和实现,能够根据要求正确定义和重载构造函数。能够根据给定的要求定义类并实现类的成员函数;
- 学会通过建立类及对象,用类的成员函数和对象访问类的成员;
- 学会利用建立类的构造函数,完成类的成员的初始化工作;
- 掌握单继承和多重继承的概念。
- 理解不同的继承类型:public、protected和private,掌握何时使用何种继承类型。
- 掌握类层次中构造函数的定义方式和建立对象时构造和析构次序。
- 掌握sort排序。
- 掌握封装变量基本权限设置原则。
- 掌握通过接口函数访问私有变量。
- 掌握重载类内运算符。
- 掌握重写父类函数、父类与子类之间相同函数名的调用。
- 掌握简单项目的研发;
- 掌握文件的读写方法;
- 掌握不同类之间的调用以及功能划分。