Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Robot Tracking System Purpose of the assignment: The project is developing robot

ID: 3921873 • Letter: R

Question

Robot Tracking System

Purpose of the assignment: The project is developing robot tracking system. Its purpose is to practice using C++ class and become familiar with OO programming in C++ Introduction: The RobotTrack system is to keep track of Robot operation. Using this system a Robot keeps the distance it has traveled since operation as well as the current position. The purpose of this program is to simulate the operation of a Robot and to generate a report that summarizes the operation of the Robot. For this assignment, there is only one Robot and initially at the location on the first line of data file – robotTravel.txt The value in the file “robotTravel.txt”, after the first line are the movement of the robot, S for move south 1 mile, N for move north for 1 mile. However W is for moving west 2 miles and E is for moving 2 mile to east. After each movement, display the current position and the distance it has traveled since leaving initial location. Requirement: Robot class specification file : robot.h Robot class implementation file: robot.cc Client code file: ola4.cc Robot class has public methods (interface) : void setRobot(int xLocation, int yLocation); void displayRobot(); void moveTo( char ch); Client code may look like: This is not exact C++ code Robot myRobot; read initial location from data file myRobot.setRobot(x, y); read the movement from data file while ( reading data is successful) myRobot.moveTo(movement); myRobot.displayRobot(); read the next movement; sample input data: cp $PUB/ robotTravel.txt . 100 50 initial location S S W W S S S E E E E N N E E Sample Output: Print the current location of the Robot, the total accumulated distance traveled since operation after each travel (each data input). see sample output for details

Explanation / Answer

/*

* Robot.h

*

* Created on: Oct 10, 2016

* Author:

*/

#ifndef ROBOT_H_

#define ROBOT_H_

#include <iostream>

class Robot {

public:

Robot();

virtual ~Robot();

void setRobot(int x,int y);

void displayRobot();

void moveTo(char ch);

int getDst();

private:

int xLocation;

int yLocation;

int dst=0;

};

#endif /* ROBOT_H_ */

//File name robot.cc

/*
* Robot.cc
*
* Created on: Oct 10, 2016
* Author: saurabh
*/

#include "Robot.h"

Robot::Robot() {
this->xLocation = 0;
this->yLocation = 0;

}

Robot::~Robot() {
}
void Robot::displayRobot() {
std::cout << "X Location " << xLocation << " Y Location " << yLocation
<< std::endl;
}
void Robot::moveTo(char ch) {
switch (ch) {
case 'N':
yLocation++;
dst++;
break;
case 'S':
dst++;
yLocation--;
break;
case 'E':
dst++;
dst++;
xLocation += 2;
break;
case 'W':
dst++;
dst++;
xLocation -= 2;
break;
default:
; //do nothing

}
}
void Robot::setRobot(int x, int y) {
xLocation = x;
yLocation = y;
}
int Robot::getDst(){
return dst;
}

//Main file

#include<iostream>

#include"Robot.h"

int main(int argc, char **argv) {

Robot myRobot;

int init_x, init_y;

std::cin >> init_x >> init_y;

myRobot.setRobot(init_x, init_y);

char ch;

   while(std::cin>>ch)

   {

   myRobot.moveTo(ch);

   myRobot.displayRobot();

   std::cout<<"The total accumulated distance traveled "<<myRobot.getDst()<<std::endl;

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote