-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTrainSystem.cpp
More file actions
130 lines (107 loc) · 3.94 KB
/
TrainSystem.cpp
File metadata and controls
130 lines (107 loc) · 3.94 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
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
#include "TrainSystem.h"
#include <iostream>
#include <cstring>
namespace trainsys {
UserInfo currentUser;
UserManager *userManager;
RailwayGraph *railwayGraph;
SchedulerManager *schedulerManager;
TicketManager *ticketManager;
PrioritizedWaitingList *waitingList;
TripManager *tripManager;
StationManager *stationManager;
RedBlackTree<String, StationID> stationNameToIDMapping;
void addTrainScheduler(const TrainID &trainID, int seatNum, int passingStationNumber,
const StationID *stations, const int *duration, const int *price) {
/* Question */
}
void queryTrainScheduler(const TrainID &trainID) {
/* Question */
}
void releaseTicket(const TrainScheduler &scheduler, const Date &date) {
/* Question */
}
void expireTicket(const TrainID &trainID, const Date &date) {
/* Question */
}
int queryRemainingTicket(const TrainID &trainID, const Date &date, const StationID &departureStation) {
/* Question */
}
bool trySatisfyOrder() {
/* Question */
}
void queryMyTicket() {
/* Question */
}
void orderTicket(const TrainID &trainID, const Date &date, const StationID &departureStation) {
/* Question */
}
void refundTicket(const TrainID &trainID, const Date &date, const StationID &departureStation) {
/* Question */
}
void findAllRoute(const StationID departureID, const StationID arrivalID) {
/* Question */
}
void findBestRoute(const StationID departureID, const StationID arrivalID, int preference) {
/* Question */
}
void login(const UserID userID, const char *password) {
/* Question */
}
void logout() {
/* Question */
}
void addUser(const UserID userID, const char *username, const char* password) {
if (userManager->existUser(userID)) {
std::cout << "User ID existed." << std::endl;
return ;
}
if (currentUser.userID == -1) {
std::cout << "Permission denied." << std::endl;
return ;
}
userManager->insertUser(userID, username, password, 0);
std::cout << "User added." << std::endl;
}
void findUserInfoByUserID(const UserID userID) {
if (!userManager->existUser(userID)) {
std::cout << "User not found." << std::endl;
return;
}
UserInfo res = userManager->findUser(userID);
if (currentUser.privilege <= res.privilege) {
std::cout << "Permission denied" << std::endl;
return;
}
std::cout << "UserID: " << res.userID << std::endl;
std::cout << "UserName: " << res.username << std::endl;
std::cout << "Password: " << res.password << std::endl;
std::cout << "Privilege: " << res.privilege << std::endl;
}
void modifyUserPassword(const UserID userID, const char *newPassword) {
if (!userManager->existUser(userID)) {
std::cout << "User not found." << std::endl;
return;
}
UserInfo res = userManager->findUser(userID);
if (currentUser.privilege <= res.privilege) {
std::cout << "Modification forbidden." << std::endl;
return;
}
userManager->modifyUserPassword(userID, newPassword);
std::cout << "Modification succeeded." << std::endl;
}
void modifyUserPrivilege(const UserID userID, int newPrivilege) {
if (!userManager->existUser(userID)) {
std::cout << "User not found." << std::endl;
return;
}
UserInfo res = userManager->findUser(userID);
if (currentUser.privilege <= res.privilege) {
std::cout << "Modification forbidden." << std::endl;
return;
}
userManager->modifyUserPrivilege(userID, newPrivilege);
std::cout << "Modification succeeded." << std::endl;
}
} // namespace trainsys