(Solved) : Ve Hired Rugged Robots Complete C Console Application Controls Robotic Floor Vacuum Wayne Q42711822 . . .

You’ve been hired by Rugged Robots to complete a C++ consoleapplication that controls a robotic floor vacuum. Wayne Statesoftware engineers have already developed the following threefiles: File Description Lab20-01-Key.cpp This is the userapplication. RuggedRobotLibrary.h This is the library header file.It contains constant declarations and function prototypes. It isincluded by the other two files. RuggedRobotLibrary.cpp This is thelibrary file. It contains functions that may be used in any userapplication. This is considered an application programmer interface(API). Download these three files into the same folder. Then createor update a development tool project that includes all three files.All coding is complete except for moving the robot. This isaccomplished by calling function moveRobot which has the followingprototype: void moveRobot(char floor[ROW_SIZE][COL_SIZE], intstats[], char move); Where: ● The floor is represented as atwo-dimensional array using the following characters: CharacterMeaning R The current location of the robot. x A dirty portion ofthe floor (it needs vacuuming!). . A clean portion of floor. Hereis a sample 2×3 floor: . R x x x x ● A one-dimensional array isused to store robot statistics including:  Current robot row Current robot column  Current number of total robot moves Current number of “good” robot moves – robot moved to a dirty spot. Current number of “okay” robot moves – robot moved to a cleanspot.  Current number of “bad” robot moves – robot tried to moveoff the floor.  Current game score – percentage calculated usingformula: (good moves – bad moves) / total moves * 100 ● A move isin one of four directions from your perspective (not from therobot’s perspective) including:  UP  RIGHT  DOWN  LEFT Anattempt is made to move the robot one spot in the direction youspecify. There are only four possible calls to moveRobot:moveRobot(floor, stats, UP); moveRobot(floor, stats, RIGHT);moveRobot(floor, stats, DOWN); moveRobot(floor, stats, LEFT); Hereis a sample call to function moveRobot to move the robot one spotto the right: moveRobot(floor, stats, RIGHT); moveRobot firstchecks if the move is possible and then moves the robot one spot tothe right. After each move attempt, moveRobot shows the currentfloor and statistics: Move 1 from [0, 0] RIGHT: GOOD . R x x x x xx x x x x x x x Robot stats: moves – 1, good – 1, okay – 0, bad -0, score – 100%: Code the following two scenarios. Before you codeeach scenario, edit the following global constants in fileRuggedRobotLibrary.h to control the size of the floor: ROW_SIZECOL_SIZE If you run the application and it stops prematurely, youmay have 3×3 floor scenario Insert a code snippet at theappropriate spot in function main (file Lab20-01-Key.cpp, line 45).The code snippet includes calls to moveRobot to clean a 3×3 floor.Try to use a minimum number of calls (three is possible) and try toget a final score of 100%. [just your code snippet here]* Ifpossible, format your code like this: Font “Courier New” Font size“9”s Bold [your program output here]** 5×4 floor scenario Insert acode snippet at the appropriate spot in function main (fileLab20-01-Key.cpp, line 45). The code snippet includes calls tomoveRobot to clean a 5×4 floor. Try to use a minimum number ofcalls (three is possible) and try to get a final score of 100%.Here are the three files: 1. Lab20-01-Key.cpp//========================================================== // //Title: // Course: CSC 1101 // Lab Number: // Author: // Date: //Description: // ////==========================================================#include // For several general-purpose functions #include // Forfile handling #include // For formatted output #include // For cin,cout, and system #include // For string data type #include”RuggedRobotLibrary.h” // For programmer-defined library usingnamespace std; // So “std::cout” may be abbreviated to “cout”//========================================================== //main //==========================================================int main() { // Declare variables char floor[ROW_SIZE][COL_SIZE];int stats[STATS_SIZE]; // Show application header cout <<“Welcome to Rugged Robots” << endl; cout <<“————————” << endl << endl; // Setreal-number formatting cout << fixed <<setprecision(0); // Initialize game printFloorKey();initFloor(floor); initStats(stats); printFloor(floor, stats); //Robot moves // your code snippet here … // Show application closecout << “nEnd of Rugged Robots” << endl; } 2.RuggedRobotLibrary.h//========================================================== // //Title: Rugged Robots Library Header // Description: // This C++header file is paired with file // RuggedRobotsLibrary.cpp, and maybe included in any C++ // application. ////==========================================================#ifndef PROGRAMMER_LIBRARY_H #define PROGRAMMER_LIBRARY_H #include// For several general-purpose functions #include // For filehandling #include // For formatted output #include // For cin,cout, and system #include // For string data type using namespacestd; // So “std::cout” may be abbreviated to “cout”//========================================================== //Global constants//========================================================== //Edit these constants to control the game const int ROW_SIZE = 2;const int COL_SIZE = 2; const bool PRINT_AFTER_MOVE = true; // Noneed to edit the following constants const char ROBOT = ‘R’; constchar DIRTY = ‘x’; const char CLEAN = ‘.’; const char UP = ‘U’;const char RIGHT = ‘R’; const char DOWN = ‘D’; const char LEFT =’L’; const int STATS_SIZE = 7; const int ROBOT_ROW = 0; const intROBOT_COLUMN = 1; const int MOVES = 2; const int GOOD_MOVE = 3;const int OKAY_MOVE = 4; const int BAD_MOVE = 5; const int SCORE =6; //========================================================== //Function prototypes//========================================================== doublecurrentScore(int stats[]); void initFloor(charfloor[ROW_SIZE][COL_SIZE]); void initStats(int stats[]); voidmoveRobot(char floor[ROW_SIZE][COL_SIZE], int stats[], char move);void printFloor(char floor[ROW_SIZE][COL_SIZE], int stats[]); voidprintFloorKey(); void printStats(int stats[]); voidupdateRobot(char floor[ROW_SIZE][COL_SIZE], int stats[], int stat,int row, int col, int newRow, int newCol); #endifPROGRAMMER_LIBRARY_H 3. RuggedRobotLibrary.cpp//========================================================== // //Title: Rugged Robots Library // Description: // This C++ librarycontains functions to control robots. ////==========================================================#include // For several general-purpose functions #include // Forfile handling #include // For formatted output #include // For cin,cout, and system #include // For string data type #include”RuggedRobotLibrary.h” // For programmer-defined library usingnamespace std;//========================================================== //currentScore//========================================================== doublecurrentScore(int stats[]) { if (stats[MOVES] == 0) return 0; elsereturn (stats[GOOD_MOVE] – stats[BAD_MOVE]) / (double) stats[MOVES]* 100; }//========================================================== //initFloor//========================================================== voidinitFloor(char floor[ROW_SIZE][COL_SIZE]) { for (int i = 0; i <ROW_SIZE; i++) for (int j = 0; j < COL_SIZE; j++) if (i == 0&& j == 0) floor[i][j] = ROBOT; else floor[i][j] = DIRTY; }//========================================================== //initStats//========================================================== voidinitStats(int stats[]) { for (int i = 0; i < STATS_SIZE; i++)stats[i] = 0; }//========================================================== //moveRobot//========================================================== voidmoveRobot(char floor[ROW_SIZE][COL_SIZE], int stats[], char move) {// Declare variables int row = stats[ROBOT_ROW];| int col =stats[ROBOT_COLUMN]; // Show move stats[MOVES] = stats[MOVES] + 1;cout << “nMove ” << stats[MOVES] << ” from [“<< row << “, ” << col << “] “; // Processmove switch (move) { case UP: cout << “UP: “; if (row == 0)updateRobot(floor, stats, BAD_MOVE, row, col, row, col); else if(floor[row – 1][col] == CLEAN) updateRobot(floor, stats, OKAY_MOVE,row, col, row – 1, col); else updateRobot(floor, stats, GOOD_MOVE,row, col, row – 1, col); break; case RIGHT: cout << “RIGHT:”; if (col == COL_SIZE) updateRobot(floor, stats, BAD_MOVE, row,col, row, col); else if (floor[row][col + 1] == CLEAN)updateRobot(floor, stats, OKAY_MOVE, row, col, row, col + 1); elseupdateRobot(floor, stats, GOOD_MOVE, row, col, row, col + 1);break; case DOWN: cout << “DOWN: “; if (row == ROW_SIZE)updateRobot(floor, stats, BAD_MOVE, row, col, row, col); else if(floor[row + 1][col] == CLEAN) updateRobot(floor, stats, OKAY_MOVE,row, col, row + 1, col); else updateRobot(floor, stats, GOOD_MOVE,row, col, row + 1, col); break; case LEFT: cout << “LEFT: “;if (col == 0) updateRobot(floor, stats, BAD_MOVE, row, col, row,col); else if (floor[row][col – 1] == CLEAN) updateRobot(floor,stats, OKAY_MOVE, row, col, row, col – 1); else updateRobot(floor,stats, GOOD_MOVE, row, col, row, col – 1); break; default: cout<< “(In moveRobot) ‘” << move << “‘ is an unknownmove.” << endl; } }//========================================================== //printFloor//========================================================== voidprintFloor(char floor[ROW_SIZE][COL_SIZE], int stats[]) { for (inti = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE;j++) cout << ” ” << floor[i][j] << ” “; cout<< endl; } printStats(stats); }//========================================================== //printFloorKey//========================================================== voidprintFloorKey() { cout << “Floor key” << endl; cout<< ROBOT << ” – robot” << endl; cout <<DIRTY << ” – dirty part of floor” << endl; cout<< CLEAN << ” – clean part of floor” << endl<< endl; }//========================================================== //printStats//========================================================== voidprintStats(int stats[]) { cout << “nRobot stats: ” <<“moves – ” << stats[MOVES] << “, good – ” <<stats[GOOD_MOVE] << “, okay – ” << stats[OKAY_MOVE]<< “, bad – ” << stats[BAD_MOVE] << “, score – “<< currentScore(stats) << “%” << endl; cout<< “n————————————-” << endl; }//========================================================== //updateRobot//========================================================== voidupdateRobot(char floor[ROW_SIZE][COL_SIZE], int stats[], int stat,int row, int col, int newRow, int newCol) { stats[stat] =stats[stat] + 1; if (stat == BAD_MOVE) cout << “BAD” <<endl << endl; else { floor[row][col] = CLEAN;floor[newRow][newCol] = ROBOT; stats[ROBOT_ROW] = newRow;stats[ROBOT_COLUMN] = newCol; if (stat == OKAY_MOVE) cout <<“OKAY” << endl << endl; else cout << “GOOD”<< endl << endl; } if (PRINT_AFTER_MOVE)printFloor(floor, stats); }

Expert Answer


Answer to You’ve been hired by Rugged Robots to complete a C++ console application that controls a robotic floor vacuum. Wayne Sta…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?