The assignment is to create three different raceways and populate them with obstacles, N = waves in Seaway, M = oil in Raceway, and O = fog in Airway. Three different vehicles on three different raceways, a boat, a car, and a plane are racing each others. They move at different speeds and the obstacles slow move them back by different amounts. The exact instructions are posted here: CS320 Programming Languages: Program Three
We've managed to create the three raceways and populate them with the obstacles at random. The question is how do we access the Raceway class in our Vehicle class to let the sub-classes know there is an obstacle that it's about to hit and therefor will be moved back by a certain amount of units.
Code://Great Vehicle Race //Written by Douglas Oonk & Jack Trocinski #include <iostream> #include <cstdlib> using namespace std; class Raceway { public: char seaway[3][100]; char roadway[3][100]; char airway[3][100]; void race() { srand(time(0)); for(int i=0; i < 3; i++){ for(int j = 0; j < 100; j++){ seaway[i][j] = '-'; roadway[i][j] = '-'; airway[i][j] = '-'; } } for(int i=0; i < 3; i++){ for(int n = 0; n< 4; n++) { int j = rand()%100; roadway[i][j] = 'M'; //oil spills } } for(int i=0; i < 3; i++){ for(int n = 0; n< 4; n++) { int j = rand()%100; seaway[i][j] = 'N'; //large waves } } for(int i=0; i < 3; i++){ for(int n = 0; n< 4; n++) { int j = rand()%100; airway[i][j] = 'O'; //fog } } } ////////////////////////////////////////////print arrays////////////////////////////////////// void printSeaway() { cout << "The Seaway race" << endl; for(int i=0; i < 3; i++){ for(int j = 0; j < 100; j++){ cout << seaway[i][j]; } cout << endl; } } void printRoadway() { cout << "The Roadway race" <<endl; for(int i=0; i < 3; i++){ for(int j = 0; j < 100; j++){ cout << roadway[i][j]; } cout << endl; } } void printAirway() { cout << "The Airway race" << endl; for(int i=0; i < 3; i++){ for(int j = 0; j < 100; j++){ cout << airway[i][j]; } cout << endl; } } }; //end class race class Vehicle { public: virtual int move() = 0; }; class Wheeled: public Vehicle { public: int move() { return 3; } }; class Propellored: public Vehicle { public: int move() { return 4; } }; class FourWD: public Wheeled { public: int move() { return 2; //if hits oil spills } }; class Cycle: public Wheeled { public: int move() { return 0; //if hits oil spills } }; class Boat: public Propellored { public: int move() { return 2; //if hits large waves } }; class Plane: public Propellored { public: int move() { return 2; //if hits fog } }; int main() { cout << "Welcome to the Great Raceway!" << endl; cout << "Written by Doug Oonk and Jack Trocinski" << endl; Raceway raceObject; raceObject.race(); raceObject.printSeaway(); raceObject.printRoadway(); raceObject.printAirway(); return 0; }