-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.cpp
164 lines (151 loc) · 4.49 KB
/
Card.cpp
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
164
#include <iostream>
#include "Student.hpp"
#include "Card.hpp"
Record::Record(double amount):Amount(amount){
cout << "\n请输入日期(月、日,用空格隔开):" << endl;
cin >> Month >> Day;
cout << "\n请输入当前时间(时、分、秒,用空格隔开):" << endl;
cin >> Hour >> Minute >> Second;
}
void Record::Print_Record()const{
cout << setfill(' ') << left << setw(10) << Amount;
cout << setfill(' ') << setw(2) << Month << "月" << setfill(' ') << setw(2) << Day << "日";
cout << setfill(' ') << setw(2) << Hour << "时" << setfill(' ') << setw(2) << Minute << "分" << setfill(' ') << setw(2) << Second << "秒 ";
}
ChargeRecord::ChargeRecord(double amount):Record(amount){
cout << endl;
cout << "请选择支付方式:" << endl;
for (int i = 0; i < 3;i++){
cout << i + 1 << ":" << method[i] << endl;
}
cin >> Method;
cout << endl;
cout << "成功充值 " << amount << " 元!" << endl;
}
void ChargeRecord::Print_ChargeRecord()const {
Print_Record();
cout << method[Method - 1] << endl;
}
ConsumeRecord::ConsumeRecord(double amount):Record(amount){
cout << endl;
cout << "请选择消费地点:" << endl;
for (int i = 0; i < 8;i++){
cout << i + 1 << ":" << place[i] << endl;
}
cin >> Place;
}
void ConsumeRecord::Print_ConsumeRecord()const {
Print_Record();
cout << place[Place - 1] << endl;
}
WaterRecord::WaterRecord(int T):Time(T),Record(T*Rate){
}
void WaterRecord::Print_WaterRecord()const {
Print_Record();
cout << Time << endl;
}
Card::Card(int Num, Student * stu):Number(Num),student(stu),Password("000000"){
Value = 0;
WaterAccount = 0;
State = OFF;
cout << endl;
cout << "学号为 " << setfill('0') << setw(4) << stu->getID() << " 的学生成功绑定校园卡 " << setfill('0') << setw(4) << Number << endl;
}
Card::~Card(){
for(int i=0;i<10;i++){
if(!charge_record.empty()){
delete charge_record.front();
charge_record.pop_front();
}
if(!consume_record.empty()){
delete consume_record.front();
consume_record.pop_front();
}
if(!water_record.empty()){
delete water_record.front();
water_record.pop_front();
}
}
}
void Card::add(double amount){
Value += amount;
}
void Card::minus(double amount){
Value -= amount;
}
void Card::addWater(double amount){
WaterAccount += amount;
}
void Card::minusWater(double amount){
WaterAccount -= amount;
}
void Card::setState(state st){
State = st;
}
void Card::setPassword(string newp){
Password = newp;
}
bool Card::isChecked(){
string temp;
for (int i = 9; i >= 0;i--){
cout << endl;
cout << "请输入校园卡密码:" << endl;
cin >> temp;
if(temp==Password){
cout << "密码正确!" << endl;
return true;
}
else
cout << "密码错误!还剩 " << i << " 次机会" << endl;
}
cout << "机会已用完!验证失败。" << endl;
return false;
}
void Card::recordCharge( ChargeRecord *cr){
if(charge_record.size()>=10){
delete charge_record.front();
charge_record.pop_front();
}
charge_record.push_back(cr);
}
void Card::recordConsume( ConsumeRecord *cr){
if(consume_record.size()>=10){
delete consume_record.front();
consume_record.pop_front();
}
consume_record.push_back(cr);
}
void Card::recordWater( WaterRecord *wr){
if(water_record.size()>=10){
delete water_record.front();
water_record.pop_front();
}
water_record.push_back(wr);
}
void Card::printCharge() const{
cout << endl;
cout << "以下是该校园卡的近10条充值记录:" << endl;
cout << "金额 时间 支付方式" << endl;
for (int i = 0; i<charge_record.size(); i++)
{
charge_record.at(i)->Print_ChargeRecord();
}
}
void Card::printConsume() const{
cout << endl;
cout << "以下是该校园卡的近10条消费记录:" << endl;
cout << "金额 时间 消费地点" << endl;
for (int i = 0; i<consume_record.size(); i++)
{
consume_record.at(i)->Print_ConsumeRecord();
}
}
void Card::printWater() const{
cout << endl;
cout << "以下是该校园卡的近10条热水使用记录:" << endl;
cout << "金额 时间 时长(分钟)" << endl;
for (int i = 0; i<water_record.size(); i++)
{
water_record.at(i)->Print_WaterRecord();
}
}