Skip to content

Commit eff423f

Browse files
authored
Implemented the twelfth and thirteenth menu options
In function.h file: Declared: - new functions for 12 & 13 menu options In function.cpp file: Implemented: - new functions for 12 & 13 menu options In data.h file: Added: - some new functionality In data.cpp file: Implemented: - some new functionality In main.cpp file: Added: - new functionality
1 parent dd273b6 commit eff423f

File tree

6 files changed

+192
-21
lines changed

6 files changed

+192
-21
lines changed

Database/data.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ void Train::setNumOfSoldTickets(int num)
476476
{
477477
this->numOfSoldTickets = num;
478478
}
479+
void Train::setTotalNumOfTickets(int num)
480+
{
481+
this->totalNumOfTickets = num;
482+
}
479483

480484
//getters for the "Locomotive" class
481485
int Train::getSerialNum()
@@ -554,6 +558,10 @@ int Train::getNumOfSoldTickets()
554558
{
555559
return numOfSoldTickets;
556560
}
561+
int Train::getTotalNumOfTickets()
562+
{
563+
return totalNumOfTickets;
564+
}
557565

558566
//output function for the "Locomotive" class
559567
void Locomotive::outputLoc(Locomotive &el)
@@ -608,7 +616,7 @@ Locomotive::Locomotive(int serialNum, int workspaceNum, int dateOfProd, int maxs
608616
std::string brand, std::string fuel, int numOfRoutes, int numOfRoutesBeforeRepair,
609617
int numOfRepair, std::string dateOfComeBack, int daysOnStation, std::string yearOfTechExam,
610618
std::string routeStatus, std::string routeReason, std::string category, int routeDuration,
611-
std::string route, int numOfSoldTickets, int numOfHandedTickets)
619+
std::string route, int numOfSoldTickets, int numOfHandedTickets, int totalNumOfTick)
612620
{
613621
this->setSerialNum(serialNum);
614622
this->setWorkspaceNum(workspaceNum);
@@ -629,6 +637,7 @@ Locomotive::Locomotive(int serialNum, int workspaceNum, int dateOfProd, int maxs
629637
this->setRoute(route);
630638
this->setNumOfSoldTickets(numOfSoldTickets);
631639
this->setNumOfHandedTickets(numOfHandedTickets);
640+
this->setTotalNumOfTickets(totalNumOfTick);
632641
};
633642

634643
//default destructor for "Locomotive" class

Database/data.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class Train
208208
int routeDuration;
209209
int numOfSoldTickets;
210210
int numOfHandedTickets;
211+
int totalNumOfTickets;
211212

212213
public:
213214
Train();
@@ -233,6 +234,8 @@ class Train
233234
void setRoute(std::string route);
234235
void setNumOfHandedTickets(int num);
235236
void setNumOfSoldTickets(int num);
237+
void setTotalNumOfTickets(int num);
238+
236239

237240
//getters
238241
int getSerialNum();
@@ -254,6 +257,7 @@ class Train
254257
std::string getRouteReason();
255258
int getNumOfHandedTickets();
256259
int getNumOfSoldTickets();
260+
int getTotalNumOfTickets();
257261
};
258262

259263
class Locomotive : public Train
@@ -265,7 +269,7 @@ class Locomotive : public Train
265269
std::string brand, std::string fuel, int numOfRoutes, int numOfRoutesBeforeRepair,
266270
int numOfRepair, std::string dateOfComeBack, int daysOnStation, std::string yearOfTechExam,
267271
std::string routeStatus, std::string routeReason, std::string category, int routeDuration,
268-
std::string route, int numOfSoldTickets, int numOfHandedTickets);
272+
std::string route, int numOfSoldTickets, int numOfHandedTickets, int totalNumOfTick);
269273
~Locomotive();
270274

271275
void outputLoc(Locomotive &el);

Database/function.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,98 @@ void outputTickByPrice(std::vector<Locomotive> &vec, std::vector<Ticket> &ticket
852852
}
853853
}
854854

855+
//function for sorting data of unpurchased tickets by route
856+
void outputUnpTickByRoute(std::vector<Locomotive> &vec, int route)
857+
{
858+
if(route == 1)
859+
{
860+
for(auto &el : vec)
861+
{
862+
if(el.getRoute() == "Kyiv-Lviv")
863+
{
864+
std::cout << "Unredeemed: " << el.getTotalNumOfTickets() - el.getNumOfSoldTickets() << std::endl;
865+
}
866+
}
867+
}
868+
else if(route == 2)
869+
{
870+
for(auto &el : vec)
871+
{
872+
if(el.getRoute() == "Uzhhorod-Lviv")
873+
{
874+
std::cout << "Unredeemed: " << el.getTotalNumOfTickets() - el.getNumOfSoldTickets() << std::endl;
875+
}
876+
}
877+
}
878+
}
879+
880+
//function for sorting data of unpurchased tickets by date
881+
void outputUnpTickByDate(std::vector<Locomotive> &vec, int choise)
882+
{
883+
for(auto &el : vec)
884+
{
885+
if((choise == 1) && (el.getDateOfComeback() == "20.05.2022"))
886+
{
887+
std::cout << el.getRoute() << std::endl
888+
<< el.getTotalNumOfTickets() - el.getNumOfSoldTickets() << std::endl;
889+
break;
890+
}
891+
else if((choise = 2) && (el.getDateOfComeback() == "22.05.2022"))
892+
{
893+
std::cout << el.getRoute() << std::endl
894+
<< el.getTotalNumOfTickets() - el.getNumOfSoldTickets() << std::endl;
895+
break;
896+
}
897+
}
898+
}
899+
900+
//function for sorting data of handed back tickets by route
901+
void outputHandOverTickByRoute(std::vector<Locomotive> &vec, int route)
902+
{
903+
if(route == 1)
904+
{
905+
for(auto &el : vec)
906+
{
907+
if(el.getRoute() == "Kyiv-Lviv")
908+
{
909+
std::cout << el.getRoute() << std::endl
910+
<< "Handed back: " << el.getNumOfHandedTickets() << std::endl;
911+
}
912+
}
913+
}
914+
else if(route == 2)
915+
{
916+
for(auto &el : vec)
917+
{
918+
if(el.getRoute() == "Uzhhorod-Lviv")
919+
{
920+
std::cout << el.getRoute() << std::endl
921+
<< "Handed back: " << el.getNumOfHandedTickets() << std::endl;
922+
}
923+
}
924+
}
925+
}
926+
927+
//function for sorting data of handed back tickets by date
928+
void outputHandedOverTickByDate(std::vector<Locomotive> &vec, int choise)
929+
{
930+
for(auto &el : vec)
931+
{
932+
if((choise == 1) && (el.getDateOfComeback() == "20.05.2022"))
933+
{
934+
std::cout << el.getRoute() << std::endl
935+
<< el.getNumOfHandedTickets() << std::endl;
936+
break;
937+
}
938+
else if((choise = 2) && (el.getDateOfComeback() == "22.05.2022"))
939+
{
940+
std::cout << el.getRoute() << std::endl
941+
<< el.getNumOfHandedTickets() << std::endl;
942+
break;
943+
}
944+
}
945+
}
946+
855947

856948
//FUNCTIONS FOR SORTING DATA OF CATEGORIES
857949

Database/function.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ void outputTickByDuration(std::vector<Locomotive> &vec);
191191
//function for sorting data of tickets by price
192192
void outputTickByPrice(std::vector<Locomotive> &vec, std::vector<Ticket> &ticket);
193193

194+
//function for sorting data of unpurchased tickets by route
195+
void outputUnpTickByRoute(std::vector<Locomotive> &vec, int route);
196+
197+
//function for sorting data of unpurchased tickets by date
198+
void outputUnpTickByDate(std::vector<Locomotive> &vec, int choise);
199+
200+
//function for sorting data of unpurchased tickets by route
201+
void outputHandOverTickByRoute(std::vector<Locomotive> &vec, int route);
202+
203+
//function for sorting data of handed back tickets by date
204+
void outputHandedOverTickByDate(std::vector<Locomotive> &vec, int choise);
205+
194206

195207
//CATEGORY
196208

0 commit comments

Comments
 (0)