c++收银系统

这个博客展示了如何使用C++编程实现一个简单的收银系统,包括定义商品类CGoods和商店类CStore,实现了添加商品、查找商品、计算总价和找零等功能。此外,系统还考虑了会员日的折扣优惠。
摘要由CSDN通过智能技术生成
#include<iostream>
#include<vector>
#include<iomanip>
#include<string>
#include<fstream>
  #include <time.h>
using namespace std;
class CGoods {
int index;
double price;
public:
string goodsname;
CGoods(int in,string na,double pr):index(in),goodsname(na),price(pr) {}
~CGoods() {}
string Getname();
int Getindex();
void Setprice(double);
double Getprice();
CGoods *Clone();
};
//CGoods的实现
string CGoods::Getname() { //获取商品名字
return goodsname;
}
int CGoods::Getindex() { //获取商品索引号
return index;
}
void CGoods::Setprice(double uprice) { //设置商品单价
price=uprice;
}
double CGoods::Getprice() { //获取商品单价
return price;
}
CGoods *CGoods::Clone() { //复制商品信息
return new CGoods(index,goodsname,price);
}
typedef struct tagStoreElement { //货架元素
CGoods *pGoods;
int iNum;
} StoreElement,*pStoreElement;
//类CStore的定义
class CStore {
private:
vector<pStoreElement> m_vStore;
public:
CStore() {}
~CStore() {
Deleteall();
}
bool AddGoods(CGoods *,int);
int FindGoods(int);
void DeleteGoods(string,int);
void DeleteGoods(int,int);
void Deleteall();
vector<pStoreElement>* getAllGoods();
pStoreElement getGoods(int);
void Print();
};
//CStore的实现
bool CStore::AddGoods(CGoods *pGoods, int iNum) { //添加商品
int size = m_vStore.size();
bool exist = false;
if ( !exist ) { //没有同类商品,则增加此类商品
pStoreElement p = new StoreElement;
p->pGoods= pGoods;
p->iNum=iNum;
m_vStore.push_back(p);
}
for(int i=0; i<size; i++) {
pStoreElement pSE=m_vStore[i];
if(pSE->pGoods!=NULL&&pSE->pGoods->Getindex()==pGoods->Getind
  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值