You are on page 1of 5

#ifndef ROBOT_H

#define ROBOT_H

#include <string>
#include <iostream>

using namespace std;

class Robot {
public:
Robot();
Robot(int x, int y, bool z);
void goLeft();
void goRight();
void goUp();
void goDown();
double distance();
void goToOrgin();
void goToLocation(int x, int y);
void pickUpLoad();
void dropLoad();
int getX();
int getY();
void getLoad();
bool robotMenu();

private:
int locationX;
int locationY;
bool load;
};

#endif ROBOT_H

#ifndef ROBOT_H
#define ROBOT_H

#include <string>
#include <iostream>

using namespace std;

class Robot {
public:
Robot();
Robot(int x, int y, bool z);
void goLeft();
void goRight();
void goUp();
void goDown();
double distance();
void goToOrgin();
void goToLocation(int x, int y);
void pickUpLoad();
void dropLoad();
int getX();
int getY();
void getLoad();
bool robotMenu();

private:
int locationX;
int locationY;
bool load;
};

#endif ROBOT_H

#ifndef ROBOT_H
#define ROBOT_H

#include <string>
#include <iostream>

using namespace std;

class Robot {
public:
Robot();
Robot(int x, int y, bool z);
void goLeft();
void goRight();
void goUp();
void goDown();
double distance();
void goToOrgin();
void goToLocation(int x, int y);
void pickUpLoad();
void dropLoad();
int getX();
int getY();
void getLoad();
bool robotMenu();

private:
int locationX;
int locationY;
bool load;
};

#endif ROBOT_H

#include "Robot.h"

using namespace std;

Robot::Robot(){
locationX = 0;
locationY = 0;
load = false;
}

Robot::Robot(int x, int y, bool z){


locationX = x;
locationY = y;
load = z;
}

void Robot::goLeft(){
locationX--;
}

void Robot::goRight(){
locationX++;
}

void Robot::goUp(){
locationY++;
}

void Robot::goDown(){
locationY--;
}

void Robot::goToOrgin(){
bool more = true;
while (more){
if (locationX > 0)
locationX--;
if (locationX < 0)
locationX++;
if (locationY > 0)
locationY--;
if (locationY < 0)
locationY++;
if (locationX == 0 && locationY == 0)
{
cout << "you have arrived at the orgin" << endl;
more = false;
}
}
}

int Robot::getX(){
return locationX;
}

int Robot::getY(){
return locationY;
}

double Robot::distance(){
return sqrt(pow(locationX, 2.0) + pow(locationY, 2.0));
}

void Robot::goToLocation(int x, int y){


bool more = true;
while (more){
if (locationX > x)
locationX--;
if (locationX < x)
locationX++;
if (locationY > y)
locationY--;
if (locationY < y)
locationY++;
if (locationX == x && locationY == y)
{
cout << "you have arrived at your location" << endl;
more = false;
}
}

void Robot::pickUpLoad(){
load = true;
}

void Robot::dropLoad(){
load = false;
}

bool Robot::robotMenu(){
int input = 0;
int x, y;
cout << "Please enter a selection from the items below.\n1. To find Location
of Robot.\n2. To move the robot to a destination.\n3. To pick up item.\n4. To drop
item.\n5. To return to start.\n6. to calculate distance.\n7. To enter location of
item and destination of item\n8. to exit menu\n\n";
cin >> input; cout << endl;
switch (input)
{
case 1: cout << "Your robot is at " << getX() << "x.\n" << "Your robot is at
" << getY() << "y.\n"; break;
case 2: cout << "Enter the X location of robot"; cin >> x; cout << "\nEnter
the Y location of robot"; cin >> y; goToLocation(x, y); break;
case 3: pickUpLoad(); break;
case 4: dropLoad(); break;
case 5: goToOrgin(); cout << endl; break;
case 6: cout << "You are"<< distance() << " away.\n"; break;
case 7: cout << "What is the X , Y location of the item to pick up"; cin >>
x >> y; goToLocation(x, y); pickUpLoad(); cout << "What is the X and Y you like it
to put the item.\n"; cin >> x >> y; goToLocation(x, y); dropLoad(); break;
case 8: return false; break;
default: cout << "Please enter a valid selection\n"; break;
}

#include "Robot.h"
//#include <iostream>
//#include <string>

using namespace std;

int main(){

Robot robot1;
while (robot1.robotMenu()){

robot1.robotMenu();
}

return 0;
}

You might also like