-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.h
155 lines (126 loc) · 2.74 KB
/
printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef _PRINTER_H_
#define _PRINTER_H_
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
class Item;
class Preferential
{
public:
Preferential(int w) : weight(w) {}
bool operator < (Preferential & p)
{
return (weight < p.weight);
}
virtual double pay(Item & it) = 0;
virtual void print(double money, double savemoney)
{
cout<<"小计: "<<money<<"(元)"<<endl;
}
virtual int saveNumber(Item & it){return 0;}
private:
int weight;
};
class Buy2Handsel1 : public Preferential
{
public:
Buy2Handsel1(int we):Preferential(we){}
double pay(Item & it);
int saveNumber(Item & it);
};
class Discounts : public Preferential
{
public:
Discounts(double per, int wei):percent(per),Preferential(wei){}
double pay(Item & it);
virtual void print(double money, double savemoney);
private:
double percent;
};
class Goods
{
public:
Goods(char *pName, char *pUnit, double pr, char *pCode): price(pr)
{
memset(szName, 0, sizeof(szName));
strcpy(szName, pName);
memset(szUnit, 0, sizeof(szUnit));
strcpy(szUnit, pUnit);
memset(szCode, 0, sizeof(szCode));
strcpy(szCode, pCode);
}
public:
char szName[200];
char szUnit[40];
double price;
char szKind[40];
char szCode[20];
};
class Item
{
public:
Item(vector<Preferential *> vec, Goods & gd, double num):prefers(vec),goods(gd), number(num)
{
savemoney = 0;
savenum = 0;
}
void calculate()
{
if (0 == prefers.size()) //没有优惠
{
sum = number*goods.price;
}
else if(1 == prefers.size())
{
Preferential * pPre = prefers[0];
sum = pPre->pay(*this);
savemoney = number*goods.price - sum;
savenum = pPre->saveNumber(*this);
}
else
{
Preferential * pMax = prefers[0];
for (int i = 1; i < prefers.size(); ++i)
{
if (*pMax < *prefers[i])
{
pMax = prefers[i];
}
}
sum = pMax->pay(*this);
savemoney = number*goods.price - sum;
savenum = pMax->saveNumber(*this);
}
}
void print()
{
cout<<"名称:"<<goods.szName<<",数量:"<<number<<goods.szUnit<<",单价:"<<goods.price<<",";
if (0 == prefers.size())
{
cout<<"小计: "<<sum<<"(元)"<<endl;
}
else
{
Preferential * pPre = prefers[0];
pPre->print(sum, savemoney);
}
}
double getNum() {return number;}
double getPrice() {return goods.price;}
double getSum() {return sum;}
double getSaveMoney() {return savemoney;}
int getSaveNum() {return savenum;}
void printSaveNum()
{
cout<<"名称:"<<goods.szName<<",数量:"<<savenum<<goods.szUnit<<endl;
}
private:
double number;
double sum;
double savemoney;
int savenum;
vector<Preferential*> prefers;
Goods & goods;
};
#endif