-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTicketManager.cpp
More file actions
53 lines (47 loc) · 1.99 KB
/
TicketManager.cpp
File metadata and controls
53 lines (47 loc) · 1.99 KB
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
#include "TicketManager.h"
#include "TrainScheduler.h"
#include "DataStructure/List.h"
namespace trainsys {
TicketManager::TicketManager(const std::string &filename) : ticketInfo(filename) {
}
TicketManager::~TicketManager() {
}
int TicketManager::querySeat(const TrainID &trainID, const Date &date, const StationID &stationID) {
/* Question */
seqList<TicketInfo> relatedInfo = ticketInfo.find(trainID);
for (int i = 0; i < relatedInfo.length(); ++i) {
if (relatedInfo.visit(i).date == date && relatedInfo.visit(i).departureStation == stationID) {
return relatedInfo.visit(i).seatNum;
}
}
return -1; //没有找到符合条件的车票
}
int TicketManager::updateSeat(const TrainID &trainID, const Date &date, const StationID &stationID, int delta) {
/* Question */
return 0;
}
void TicketManager::releaseTicket(const TrainScheduler &scheduler, const Date &date) {
/* Question */
int passingStationNum = scheduler.getPassingStationNum();
for (int i = 0; i + 1 < passingStationNum; ++i) {
TicketInfo newTicket;
newTicket.trainID = scheduler.getTrainID();
newTicket.departureStation = scheduler.getStation(i);
newTicket.arrivalStation = scheduler.getStation(i + 1);
newTicket.seatNum = scheduler.getSeatNum();
newTicket.price = scheduler.getPrice(i);
newTicket.duration = scheduler.getDuration(i);
newTicket.date = date;
ticketInfo.insert(newTicket.trainID, newTicket);
}
}
void TicketManager::expireTicket(const TrainID &trainID, const Date &date) {
/* Question */
seqList<TicketInfo> relatedInfo = ticketInfo.find(trainID);
for (int i = 0; i < relatedInfo.length(); ++i) {
if (relatedInfo.visit(i).date == date) {
ticketInfo.remove(trainID, relatedInfo.visit(i));
}
}
}
}