Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a console C++ program that will have the user enter a series of Cartesian points which you will store in a vector, then calculate

Create a console C++ program that will have the user enter a series of Cartesian points which you will store in a vector, then calculate and display the total distance between each point in sequence. This program will require the use of a std::vector.

Initial Steps: You will be using the MyCartesianPoint.h header file provided, which defines the CartesianPoint class. This class has a static method called SetLimit() that you should use to set the coordinate limit for all CartesianPoint objects. Set this limit to 10, which will limit the range of the x and y values to between -10 and +10 inclusive. Create an empty vector of CartesianPoint objects. Add the point (0, 0) to this vector as a starting point. Getting User Input: Explain the input phase to the user (see example below). Then, in a loop, show the user the most recent point in the vector, and ask them what point they want to move to. Prompt for and get valid whole numbers for the x and y values. Then add a point with those x and y values to the vector. You will continue this loop until the user enters the ending point, which is (10, 10). Use the example output as a guide:

You will be travelling from (0, 0) to (10, 10) in as many steps as you like. Enter (10, 10) to end. Move from (0, 0) to where? X: 3 Y: 4 Move from (3, 4) to where? X: -3 Y: -4 Move from (-3, -4) to where? X: chicken * Invalid input. Please try again and enter a numeric value. 11 * Invalid input. Please try again and enter a value between -10 and 10.

10

Y: 10

Processing Function: The calculation of the total distance between each point will take place in a function called TotalDistance(). Pass this function the vector of points. Use a loop to sum the distance between the first and second point, the second and third, the third and fourth, etc. for as many points as there are in the vector. Normally, a processing function will focus strictly on processing, but in this case you will output the distance between each pair of points as you are going along to make debugging easier. Theoretically, you would remove this code once the function was fully tested but you will leave it in for this lab. Finally, the function should return the total distance back to main(). Use the example output as a guide to this step. It is not critical that your output matches this format exactly but the information shown should be there:

DEBUGGING ONLY: (0, 0) -> (3, 4) : 5.00 (3, 4) -> (-3, -4) : 10.00 (-3, -4) -> (10, 10) : 19.10

Final Output: The final output of the program should occur back in main(). Report how many points are in the vector and what the total distance is.

The total distance between 4 points is 34.10.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions