Website Summary Files Commits Branches @commit @diff @stats
path: root / Week04 / Exercise01 / Train.cpp
diff options
context:
space:
mode:
1 files changed, 24 insertions, 0 deletions
-rw-r--r--Week04/Exercise01/Train.cpp24
diff --git a/Week04/Exercise01/Train.cpp b/Week04/Exercise01/Train.cpp
new file mode 100644
index 0000000..5ff2db1
--- /dev/null
+++ b/Week04/Exercise01/Train.cpp
@@ -0,0 +1,24 @@
+#include "Train.h"
+#include <iostream>
+
+void Train::ArriveAtStation(unsigned passengersGettingOff, unsigned passengersGettingOn) {
+ if (passengersGettingOff > passengersOnBoard)
+ passengersOnBoard = 0;
+ else
+ passengersOnBoard -= passengersGettingOff;
+
+ passengersOnBoard += passengersGettingOn;
+ earnings += passengersGettingOn * ticketPrice;
+
+ passedStops++;
+ upcomingStops--;
+}
+
+void Train::Print() {
+ std::cout << "Carriages: " << carriages << ' '
+ << "Seats: " << passengersOnBoard << '/' << seatsAvailable << ' '
+ << "Stops: " << passedStops << " < " << upcomingStops << ' '
+ << "Ticket: " << ticketPrice << ' '
+ << "Earnings: " << earnings
+ << std::endl;
+}