-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataModel.h
163 lines (151 loc) · 2.98 KB
/
dataModel.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
156
157
158
159
160
161
162
163
#ifndef DATAMOCEL
#define DATAMODEL
#include<fstream>
#define BOUNDCHECK i>=12||i<0
using namespace std;
class DataModel{
private:
//总消费 消费次数 单笔最大 最小
//卡内余额最大 最小 和
float _data[12][7];
//12种消费 每种的总额
float goodType[12][12];
//12种消费 次数
int goodCnt[12][12];
//平时消费与周末消费 平时 周末
float weekConsume[12][2];
//平时与周末消费金额
int weekCnt[12][2];
public:
//12种消费
static const string Good[12];
DataModel(){
for (int i = 0; i < 12; i++){
for (int j = 0; j < 7; j++){
_data[i][j] = 0;
}
}
for (int i = 0; i < 12; i++){
//init the min
_data[i][3] = (float)10000;
_data[i][5] = (float)10000;
}
memset(goodType, 0, sizeof(goodType));
memset(goodCnt, 0, sizeof(goodCnt));
memset(weekConsume, 0, sizeof(weekConsume));
memset(weekCnt, 0, sizeof(weekCnt));
}
void consume(int month,float money,float remain,string goodType,int weekDay);
void outputData(ofstream& of);
bool isAvailable(){
int cnt = 0;
for (int i = 0; i < 12; i++){
if (_data[i][0] == 0){
cnt++;
}
}
if (cnt >= 5){
return false;
}
else
{
return true;
}
}
int getTotalConsume(int i){
if (BOUNDCHECK) return 0;
return _data[i][0];
}
int getConsumeTime(int i){
if (BOUNDCHECK) return 0;
return _data[i][1];
}
int getMaxConsume(int i){
if (BOUNDCHECK) return 0;
return _data[i][2];
}
int getMinConsume(int i){
if (BOUNDCHECK) return 0;
if (_data[i][3] == 10000) return 0;
return _data[i][3];
}
int getMaxRemain(int i){
if (BOUNDCHECK) return 0;
return _data[i][4];
}
int getMinRemain(int i){
if (BOUNDCHECK) return 0;
if (_data[i][5] == 10000) return 0;
return _data[i][5];
}
int getAvgConsume(int i){
if (getConsumeTime(i) == 0){
return 0;
}
else{
return getTotalConsume(i) / getConsumeTime(i);
}
}
int getAvgRemain(int i){
if (getConsumeTime(i) == 0){
return 0;
}
else{
return _data[i][6] / getConsumeTime(i);
}
}
int getGootTime(int i,string good){
if(BOUNDCHECK) return 0;
int type = search(good);
if (type == -1) return 0;
return goodCnt[i][type];
}
int getGoodConsume(int i, string good){
if (BOUNDCHECK) return 0;
int type = search(good);
if (type == -1) return 0;
return goodType[i][type];
}
int getWeekdayCnt(int i){
if (BOUNDCHECK) return 0;
return weekCnt[i][0];
}
int getWeekendCnt(int i){
if (BOUNDCHECK) return 0;
return weekCnt[i][1];
}
int getWeekdayConsume(int i){
if (BOUNDCHECK) return 0;
return weekConsume[i][0];
}
int getWeekendConsume(int i){
if (BOUNDCHECK) return 0;
return weekConsume[i][1];
}
int getWeekdayAvg(int i){
if (getWeekdayCnt(i) == 0){
return 0;
}
else{
return getWeekdayConsume(i) / getWeekdayCnt(i);
}
}
int getWeekendAvg(int i){
if (getWeekendCnt(i) == 0){
return 0;
}
else{
return getWeekendConsume(i) / getWeekendCnt(i);
}
}
private:
int search(string s){
for (int i = 0; i < 12; i++){
if (s.compare(Good[i]) == 0){
return i;
}
}
return -1;
}
};
#endif