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

You have to write a program that will take as input from the command line two pa

ID: 3882364 • Letter: Y

Question

You have to write a program that will take as input from the command line two pairs of coordinates: the location of the robot and the location of the gold coin. These must be whole number

1. echo the input

2. output the number of step (i.e, squares )that the robot has to travel horizontally and verticallt to reach the gold coin;

3. specify the orientation for the robot to travel both horizontally (i.e left or right)or and vertically (i.e up and down);

4. calculate and output which direction travelled( horizontal or vertical) is greater.

5. Implement the program using arrays and loops to let user decides when to quit the program

You can assume that the grid squares are numbered like a Cartesian(X-Y) graph, with positive X going horizontally to the right and positive Y going vertically upwards Input coordinates can be negative, but they must be whole numbers. The output distance must be possitive and must be expressed in whole numbers

Explanation / Answer

#include<iostream>
#include<sstream>
#include<string>
#include<stdlib.h>

using namespace std;

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

   int data[4];

   for(int i = 1; i <5; i++){
      stringstream iss(argv[i]);
      iss >> data[i];
      cout << data[i] << " ";
   }
   cout << "Robot location :" << data[1] << " " << data[2] << endl;
   cout << "Gold coin location :" << data[3] << " " << data[4] << endl;
   int steps = abs(data[3]-data[1]) + abs(data[4]-data[2]);
   cout << " Total number of steps :" << steps<< endl;
   cout << "Horizontal step : " << abs(data[3]-data[1]) << endl;
   cout << "Vertical step : " << abs(data[4]-data[2]) << endl;
   if (abs(data[3]-data[1]) > abs(data[4]-data[2]))
      cout << "Horizontal steps are more than vertical steps" << endl;
   if (abs(data[3]-data[1]) < abs(data[4]-data[2]))
      cout << "Vertical steps are more than horizontal steps" << endl;
   if (abs(data[3]-data[1]) == abs(data[4]-data[2]))
      cout << "Vertical steps are equal to horizontal steps" << 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