-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
202 lines (174 loc) · 4.01 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "stdafx.h"
#include <iostream>
#include <string>
#include "SalesSystem.h"
using namespace std;
void showHomeWelcome();
static SalesSystem* salesSystem = NULL;
void pressEnterToMainPage()
{
cout << "按回车键回到主页\n";
char a;
cin >> a;
showHomeWelcome();
}
void inputAndValid(int* startStationIndex, int* endStationIndex)
{
cin >> *startStationIndex;
while (*startStationIndex < 1 || *startStationIndex > 10)
{
cout << "错误的站点名字。请再次输入\n";
cin >> *startStationIndex;
}
cout << "请输入终点站的名字 (1 ~ 10):\n";
cin >> *endStationIndex;
while (*endStationIndex < 1 || *endStationIndex > 10)
{
cout << "错误的站点名字。请再次输入\n";
cin >> *endStationIndex;
}
if (*startStationIndex == *endStationIndex)
{
cout << "错误,起始站和终点站相同!\n";
pressEnterToMainPage();
}
if (*startStationIndex > *endStationIndex)
{
int tempStation = *startStationIndex;
*startStationIndex = *endStationIndex;
*endStationIndex = tempStation;
}
}
void showSearchRemainTicket()
{
cout << "欢迎光临车票查询系统!\n";
cout << "请输入起始站名字 (1 ~ 10):\n";
int startStationIndex;
int endStationIndex;
inputAndValid(&startStationIndex, &endStationIndex);
Station* startStation = salesSystem->stationWithIndex(startStationIndex);
Station* endStation = salesSystem->stationWithIndex(endStationIndex);
RemainedTicketsInfo* remainedTicketsinfo = salesSystem->searchRemainedTickesInfo(startStation, endStation);
cout << "起始站是 " + startStation->m_strStationName + "。终点站是 " + endStation->m_strStationName + " 。\n";
cout << "剩余 " + to_string(remainedTicketsinfo->m_uRemainedTickets) + " 张票。";
pressEnterToMainPage();
}
void showBuyTicket()
{
cout << "欢迎光临购票系统!\n";
cout << "请输入你的名字:\n";
string name;
cin >> name;
cout << "请输入你的身份证号:\n";
int id;
cin >> id;
int startStationIndex;
int endStationIndex;
inputAndValid(&startStationIndex, &endStationIndex);
Station* startStation = salesSystem->stationWithIndex(startStationIndex);
Station* endStation = salesSystem->stationWithIndex(endStationIndex);
RemainedTicketsInfo* remainedTicketsinfo = salesSystem->searchRemainedTickesInfo(startStation, endStation);
Ticket* ticket = NULL;
if (remainedTicketsinfo->m_uRemainedTickets > 0)
{
ticket = salesSystem->buyTicket(new Buyer(name, id), salesSystem->stationWithIndex(startStationIndex), salesSystem->stationWithIndex(endStationIndex));
}
if (ticket)
{
cout << "购买成功 !!!";
}
pressEnterToMainPage();
}
void showSearchPurchaseHistory()
{
cout << "购票历史查询 \n";
cout << "1.姓名查询" << endl << "2.身份证查询" << endl;
int temp = 0;
string tempName;
int tempId;
Buyer * tempBuyer=NULL;
cin >> temp;
switch (temp)
{
case 1:
cout << "请输入你的名字:" << endl;
cin >> tempName;
tempBuyer->m_strName = tempName;
//
break;
case 2:
cout << "请输入你的身份证号:" << endl;
cin >> tempId;
tempBuyer->m_iId = tempId;
//
break;
default:
exit(0);
break;
}
}
void showRefoundTicket()
{
cout << "欢迎来到退票系统" << endl;
cout << "1.姓名退票" << endl << "2.身份证退票" << endl;
int temp = 0;
string tempName;
int tempId;
Buyer * tempBuyer=NULL;
cin >> temp;
switch (temp)
{
case 1:
cin >> tempName;
tempBuyer->m_strName = tempName;
//bool refoundTickets()
break;
case 2:
cin >> tempId;
tempBuyer->m_iId = tempId;
//bool refoundTickets()
break;
default:
exit(0);
break;
}
}
void showHomeWelcome()
{
cout << "欢迎来到火车票销售系统!\n";
cout << "选择你想要的功能:\n";
cout << "1. 查询余票:\n";
cout << "2. 购票:\n";
cout << "3. 查询购票记录:\n";
cout << "4. 退票:\n";
cout << "输入其他按键退出:\n";
int index = 0;
cin >> index;
switch (index)
{
case 1:
showSearchRemainTicket();
break;
case 2:
showBuyTicket();
break;
case 3:
showSearchPurchaseHistory();
break;
case 4:
showRefoundTicket();
break;
default:
exit(0);
break;
}
}
int main(int argc, const char * argv[])
{
salesSystem = new SalesSystem();
while (1)
{
showHomeWelcome();
}
return 0;
}