Question: Need help a with C++ programming problem. Will rate highly: C++ CODE (COPY/PASTE): /*-------------------------------------------------------------------------* *--- ---* *--- Train.h ---* *--- ---* *--- This file declares

Need help a with C++ programming problem. Will rate highly:

Need help a with C++ programming problem. Will rate highly: C++ CODE

(COPY/PASTE): /*-------------------------------------------------------------------------* *--- ---* *--- Train.h ---* *--- ---* *--- This file

declares a class that implements a Train object. ---* *--- ---* *---

---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1.0 Joseph Phillips 2018 February 11---* *--- ---* *-------------------------------------------------------------------------*/ class Train { // I. Member vars: // PURPOSE: To hold the name of

C++ CODE (COPY/PASTE):

/*-------------------------------------------------------------------------* *--- ---* *--- Train.h ---* *--- ---* *--- This file declares a class that implements a Train object. ---* *--- ---* *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1.0 Joseph Phillips 2018 February 11---* *--- ---* *-------------------------------------------------------------------------*/ class Train { // I. Member vars: // PURPOSE: To hold the name of '*this' Train. std::string name_; // PURPOSE: To hold the time it takes '*this' Train to go from one // Station to another (in microseconds). int pauseTimeUsecs_; public : // PURPOSE: To initialize '*this' Train to have name 'newName' and to have // transit time between platforms 'newPauseTimeUsecs'. Also notes to // std::cout that '*this' Train is leaving the trainyard. No return // value. Train (const std::string& newName, int newPauseTimeUsecs ) { name_ = newName; pauseTimeUsecs_ = newPauseTimeUsecs; std::cout getName() getName() getName() getName() getName() getName()  #include  #include  #include  #include  #include "Train.h" #include "Station.h" const int NUM_TRAINS = 4; const int NUM_NORTHERNLY_TRAINS = NUM_TRAINS / 2; const int NUM_SOUTHERNLY_TRAINS = NUM_TRAINS - NUM_NORTHERNLY_TRAINS; const int NUM_LOOPS = 16; const char* TRAIN_NAME_ARRAY[NUM_TRAINS] = { "Thomas the Tank-Engine", "Engine No. 9", "California Zephyr", "Tokaido Shinkansen" }; const int TRAIN_TRANSIT_TIME_MSECS[NUM_TRAINS] = { 10000, // Thomas 10000, // Engine no. 9 5000, // CA Zephyr 1000 // Bullet train }; Station northTerminal("North Station"); Station southTerminal("South Station"); // PURPOSE: To make the Train object pointed to by 'vPtr' do 'NUM_LOOP' times: // * arrive at 'northTerminal' // * leave at 'northTerminal' // * pause // * arrive at 'southTerminal' // * leave at 'southTerminal' // * pause // Returns a pointer to the Train it used. void* initiallyNorthernly (void* vPtr) { // YOUR CODE HERE } // PURPOSE: To make the Train object pointed to by 'vPtr' do 'NUM_LOOP' times: // * arrive at 'southTerminal' // * leave at 'southTerminal' // * pause // * arrive at 'northTerminal' // * leave at 'northTerminal' // * pause // Returns a pointer to the Train it used. void* initiallySouthernly (void* vPtr) { // YOUR CODE HERE } int main (int argc, char* argv[] ) { if (argc > 1) srand(strtol(argv[1],NULL,10)); pthread_t tidArray[NUM_TRAINS]; Train* trainArray[NUM_TRAINS]; for (int i = 0; i YOUR CODE HERE // Please make 'NUM_SOUTHERNLY_TRAINS' threads // (tidArray[NUM_NORTHERNLY_TRAINS] to tidArray[NUM_TRAINS-1]) run // 'initiallySouthernly()'. Each thread should get a pointer to its own // Train instance (trainArray[NUM_NORTHERNLY_TRAINS] to / trainArray[NUM_TRAINS-1], this is an array of POINTERS to trains, not / trains themselves). for ( ; trainInd YOUR CODE HERE // Leave this loop here. I want to make sure you get the Train pointers // back from initiallyNorthernly and initiallySouthernly(). for (int i = 0; i YOUR CODE HERE return(EXIT_SUCCESS); } 

Purpose: To practice Posix-Threads trainLine.cpp Four trains of varying speeds run north-and-south on their own tracks. They visit different the two stations at either end: northTerminal after going north and southTerminal after going south. Because each train runs on its own track, they will not collide on the tracks. However, both station can only handle one train at a time. So if two trains are ever at the same station at the same time then there will be a CRASH More specifically, it is not the actual Station instance that should be locked, rather, it is the act of arrive ) -ing and leave ) -ing the Station that should be locked. Each train is implemented with its own thread. Please make the trains run both safely and on time. Note: Besides the C++ code in Station.h and trainiine.opp, this program requires you to give short answers for (b), (d) and (f) in the comments. Be sure these answers are clearly labeled! a. Making the Train Line multi-threaded Right now not much will happen. Therefore, please finish the following Finish main to make and join the Threads. I already have created NUM TRAINS for you. They are in trainArrayu. Please make NUM_NORTHERNLY_TRAINS threads (tidArray[O] to tidArray[NUM NORTHERNLY_TRAINS-1]) run 'initiallyNorthernly0'. Each thread should get a pointer to its own Train instance (trainArray[O] to trainArraylNUM_NORTHERNLY_TRAINS-1]. this is an array of POINTERS to trains, not trains themselves) Purpose: To practice Posix-Threads trainLine.cpp Four trains of varying speeds run north-and-south on their own tracks. They visit different the two stations at either end: northTerminal after going north and southTerminal after going south. Because each train runs on its own track, they will not collide on the tracks. However, both station can only handle one train at a time. So if two trains are ever at the same station at the same time then there will be a CRASH More specifically, it is not the actual Station instance that should be locked, rather, it is the act of arrive ) -ing and leave ) -ing the Station that should be locked. Each train is implemented with its own thread. Please make the trains run both safely and on time. Note: Besides the C++ code in Station.h and trainiine.opp, this program requires you to give short answers for (b), (d) and (f) in the comments. Be sure these answers are clearly labeled! a. Making the Train Line multi-threaded Right now not much will happen. Therefore, please finish the following Finish main to make and join the Threads. I already have created NUM TRAINS for you. They are in trainArrayu. Please make NUM_NORTHERNLY_TRAINS threads (tidArray[O] to tidArray[NUM NORTHERNLY_TRAINS-1]) run 'initiallyNorthernly0'. Each thread should get a pointer to its own Train instance (trainArray[O] to trainArraylNUM_NORTHERNLY_TRAINS-1]. this is an array of POINTERS to trains, not trains themselves)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!