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
The class Robot must have the following public functions:
#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();
}
This is for a grade and Is a Project for my Computer Programming Class using Microsoft...
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 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 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 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 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 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, 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, 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 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 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...