Question

This is for a grade and Is a Project for my Computer Programming Class using Microsoft...

This is for a grade and Is a Project for my Computer Programming Class using Microsoft Visual Studio C++ need to be able to copy code and copy output as well if you dont know how or what this is then please do not work on it Thank you.

In this project you will Define a Robot class and command robot objects to move to different locations within an 10X10 grid (or board) to pickup and drop-off loads in different cells of the grid. The loads are assumed to be characters. For simplicity we assume the grid is a global variable. The Robot class must have the following data members

  1. A private data field xLocation (an int type) : Holds the x-component of the location of the robot object on the grid
  2. A private data field yLocation(an int type) : Holds the y-component of the location of the robot on the grid
  3. A private data field cargoBed (a bool type) : indicates whether the robot has any cargo (load)
  4. A private data field load (a char type) : Holds the content of the load, set to character ‘.’ (a dot) when robot has no load.

The class Robot must have the following public functions:

  1. A constructor that receive parameters to initialize all private date members [16pts]
  2. Include get/set functions for all private data members [32pts]
  3. The function bool MoveTo(int lx, int ly). This function checks to see whether the location (lx, ly) is within the boundary of the grid, if not return false. Otherwise, the function checks the current position of the robot object at (xLocation, yLocation) then using loops moves the robot object (one cell at a time) to the new location given by parameters x and y. The robot can only move one cell at a time to its neighboring cells on the left, right, up, or down [16pts]
  4. The function bool pickup (int lx, int ly). Invoking this function will command robot to pick up a character (load) on the grid at location (lx,ly) and place it in its cargoBed. The robot object must verify that there is a character load at location (lx,ly) and that the robot has empty cargoBed. When a character is picked up, it should be removed from the grid. If the robot is not currently at location (lx,ly), it should be moved to the specified location first, then picking up the load. The function leaves the robot object at the pickup location [16pts]
  5. The function bool dropOff(int lx, int ly). Invoking this function will command the robot object to drop-off a character (load) on the grid location (lx,ly) on the grid. The robot object must verify that there is no character at location (lx,ly) on the board and that the robot has a character in it’s cargoBed to drop-off. When a character is dropped-off, it should be removed from the cargoBed of the robot object and placed at the given location on the board. If the robot is not currently at location (lx,ly), it should be moved to the specified location first and then the drop off should take place. The function leaves the robot at the drop-off location [16pts]
  6. Overload the operator “<<” for the Robot class to print the location of the robot on the grid as well as its load, something like (5, 8) :P indicating that the Robot is at position (5, 8) on the grid and carrying the letter ‘P’ as a load. [16pts]
  7. Write a nonmember function print2D() that reveries a 2D array of characters and displays it in a row/column format. [32pts]
  8. Write a main function to test the operation of the robot. Your program should define a 2D array (or a vector of vectors) representing the grid char grid [10][10]. Make this array global and Initialize all the elements in the 2D array to “.”, which is interpreted as empty cells. Then, place character ‘B’ at location (3, 8) and ‘C’ at (2, 6). Use the print2D() function to print the grid [16pts]
  9. Create two robot objects R1 and R2, please them at a random location on the board with no load. Print the robots [16pts]
  10. Use moveTo() function to place R1 at location (9,2 ) and R2 at location (3, 4). Print the robots and the board. [16pts]
  11. Direct R1 to pick up ‘B’ at location (3, 8) and place it at location (9, 9). Print the robots and the board [16pts]
  12. Direct R2 to pick up ‘C’ at location (2, 6) and place it at location (0, 0). Print the robots and the board [16pts]
  13. Write a nonmember function clear() that receives a 2D array of character type with a void return type. The function traverses through all the elements of the array and if it finds a character at any location it should dynamically create a Robot object, set the robot at that location where the character is located and pick up the load. When this task is done the robot must be deleted. To test this function, in the main call the function clear() and pass the grid array as the argument. After this function call the grid should be clear of all characters. Print the grid [16pts]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
using namespace std;

char grid[10][10];


class Robot{
private:
   int xLoc;
   int yLoc;
   bool cargoBed;
   char load;

public:
   Robot(int x, int y){
       xLoc = x;
       yLoc = y;
       cargoBed = false;
       load = '.';
   }
   int getx(){return xLoc;}
   int gety(){return yLoc;}
   bool getCargoBed(){return cargoBed;}
   char getLoad(){return load;}
   void setx(int x){xLoc = x;}
   void sety(int y){yLoc = y;}
   void setCargoBed(bool x){cargoBed = x;}
   void setLoad(char x){load = x;}

   bool moveTo(int lx, int ly);
   bool pickUp(int lx, int ly);
   bool dropOff(int lx, int ly);

   ostream& operator<< (ostream& os){
       os<<"("<<xLoc<<", "<<yLoc<<") :"<<load<<endl;
       return os;
   }
   friend ostream &operator<<( ostream &output, const Robot &R ) {
output <<"("<<R.xLoc<<", "<<R.yLoc<<") :"<<R.load;
return output;
}
friend void destructRobot(Robot* );
};

bool Robot::moveTo(int lx, int ly){
   if(lx>=10 || ly>=10 || ly<0 || lx<0){
       return false;
   }
   while(xLoc!=lx){
       if(lx-xLoc>0){
           xLoc++;
       }else{
           xLoc--;
       }
   }
   while(yLoc!=ly){
       if(ly-yLoc >0){
           yLoc++;
       }else{
           yLoc--;
       }
   }
   return true;
}

bool Robot::pickUp(int lx, int ly){
   if(lx>=10 || ly>=10 || ly<0 || lx<0){
       return false;
   }
   if(cargoBed==true || grid[lx][ly]=='.'){
       return false;
   }
   moveTo(lx, ly);
   cargoBed = true;
   load = grid[lx][ly];
   grid[lx][ly]='.';
   return true;
}

bool Robot::dropOff(int lx, int ly){
   if(lx>=10 || ly>=10 || ly<0 || lx<0){
       return false;
   }
   if(cargoBed==false || grid[lx][ly]!='.'){
       return false;
   }
   moveTo(lx,ly);
   grid[lx][ly]=load;
   load='.';
   cargoBed=false;
   return true;
}

void print2D(){
   for(int i=0; i<10; i++){
       for(int j=0; j<10; j++){
           cout<<grid[i][j]<<" ";
       }
       cout<<endl;
   }
}

void destructRobot(Robot* ptr)
{
delete ptr;
}

void clear(){
   for(int i=0; i<10; i++){
       for(int j =0 ; j<10; j++){
           if(grid[i][j]!='.'){
               Robot *ptr = new Robot(i,j);
               ptr->pickUp(i,j);
               destructRobot(ptr);
           }
       }
   }
}

int main(){
   for(int i=0; i<10; i++){
       for(int j=0; j<10; j++){
           grid[i][j]='.';
       }
   }

   grid[3][8]='B';
   grid[2][6]='C';

   print2D();

   Robot R1(6,7), R2(3,4);
   cout<<"R1="<<R1<<endl;
   cout<<"R2="<<R2<<endl;

   R1.moveTo(9,2);
   R2.moveTo(9,9);
   print2D();
   cout<<"R1="<<R1<<endl;
   cout<<"R2="<<R2<<endl;

   R1.pickUp(3,8);
   R1.dropOff(9,9);
   print2D();
   cout<<"R1="<<R1<<endl;

   R2.pickUp(2,6);
   R2.dropOff(0,0);
   print2D();
   cout<<"R2="<<R2<<endl;

   clear();
   print2D();

}

Add a comment
Know the answer?
Add Answer to:
This is for a grade and Is a Project for my Computer Programming Class using Microsoft...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Having a rough time getting started with the constructors and the display function of this class,...

    Having a rough time getting started with the constructors and the display function of this class, any advice/assitance is appreciated! Task You will write a class called Grid, and test it with a couple of programs. A Grid object will be made up of a grid of positions, numbered with rows and columns. Row and column numbering start at 0, at the top left corner of the grid. A grid object also has a "mover", which can move around to...

  • *Using C++* You will create a program that uses a Critter class to move around a...

    *Using C++* You will create a program that uses a Critter class to move around a Grid, which is also a class. The Critter and the Grid classes will be in separate files. The Critter class will have a data member to count the number of moves made. It will also need data members to hold the current x and y coordinates. It will have a member function that randomly moves it one space in one of 4 directions. You...

  • C++ Programming - Design Process I need to create a flow chart based on the program...

    C++ Programming - Design Process I need to create a flow chart based on the program I have created. I am very inexperienced with creating this design and your help will be much appreciated. My program takes a string of random letters and puts them them order. Our teacher gave us specific functions to use. Here is the code: //list of all the header files #include <iomanip> #include <iostream> #include <algorithm> #include <string> using namespace std; //Here are the Function...

  • PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores...

    PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....

  • Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every...

    Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every part, and include java doc and comments Create a battleship program. Include Javadoc and comments. Grade 12 level coding style using java only. You will need to create a Ship class, Location class, Grid Class, Add a ship to the Grid, Create the Player class, the Battleship class, Add at least one extension. Make sure to include the testers. Starting code/ sample/methods will be...

  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • I need help with keeping it within the range of the board at the edges. Also,...

    I need help with keeping it within the range of the board at the edges. Also, after the missile launch, I would like to scan the entire board for any boats that have sunk. Meaning, I would like to check if any boats in an array of boats exist on the board. If it cannot find a boat of a specific name from the Boat array within the 2D board, I would want it to return false. This seems simple...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • hello, I'm having trouble understanding the problems below for my Computer science class, please include a...

    hello, I'm having trouble understanding the problems below for my Computer science class, please include a work-through and some explanations on how to do it so that I can understand remember how do problems like this on my own. Thank you very much WE ARE USING C++ The following project includes the frequency_start_letter function and a few other functions that work with a string array. Reminder: you could click "Open in Repl.it" on the top right corner to see the...

  • Imagine we are using a two-dimensional array as the basis for creating the game battleship. In...

    Imagine we are using a two-dimensional array as the basis for creating the game battleship. In the game of battleship a '~' character entry in the array represents ocean, a '#' character represents a place ion the ocean where part of a ship is present, and an 'H' character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, a ship with all 'H' characters means the ship has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT