Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is C + + programing question Declare and implement two member functions and a global function that will change the state of a Train
This is C programing question Declare and implement two member functions and a global function that will change the state of a Train object. These functions will NOT change the state of a Train object if it is in a safe empty state. Note: Review the testing program and the sample output in order to understand the behaviour of these three functions. The member function loadPeople changes the number of people on a train. The value of the input parameter is used to increase or decrease the number of people on a train. It must make sure that the number of people will not be negative or exceed MAXPEOPLE. It returns true if the operation succeeds. It returns false if the Train object is in a safe empty state. The member function changeSpeed changes the speed of a train. The value of the input parameter is used to increase or decrease the speed of a train. It must make sure that the speed of a train will not be negative or exceed MAXSPEED. It returns true if the operation succeeds. It returns false if the Train object is in a safe empty state. A global function transfer moves as many passengers as possible from the second Train to the first Train. It has two parameters first second that reference two Train objects. The function must make sure that the number of people on both Train objects will not be negative or exceed MAXPEOPLE. It returns the number of people that have been moved to the first Train. It returns if any of the Train objects is in a safe empty state. Testing Program #include #include #include using namespace std; #include "Train.h using namespace seneca; int main Train trains; trainssetBullet Train", ; trainssetVIA Rail Abitibi", ; trains trains; Watch out! cout endl; cout Testing changeSpeed." endl; cout endl; trainschangeSpeed; trainschangeSpeed; trainsdisplay; trainsdisplay; trainschangeSpeed; trainschangeSpeed; trainsdisplay; trainsdisplay; cout endl endl; cout endl; cout Testing loadPeople." endl; cout endl; trainsloadPeople; trainsloadPeople; trainsdisplay; trainsdisplay; trainsloadPeople; trainsloadPeople; trainsdisplay; trainsdisplay; cout endl endl; cout endl; cout Testing transfer." endl; cout endl; transfertrains trains; trainsdisplay; trainsdisplay; trainsloadPeople; transfertrains trains; trainsdisplay; trainsdisplay; Watch out! cout endl endl; cout endl; cout Testing transfer safe empty states endl; cout endl; trainssetnullptr; safe empty state cout transfer trains trains endl; cout transfer trains trains endl; cout endl endl; return ; Sample Output Testing changeSpeed. NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh Testing loadPeople. NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh Testing transfer. NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : VIA Rail Abitibi NUMBER OF PEOPLE : SPEED : kmh NAME OF THE TRAIN : Bullet Train NUMBER OF PEOPLE : SPEED : kmh Testing transfer safe empty states
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started