Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the C++ code given below. // This program reads three points (x1,y1), (x2,y2) and (x3,y3) // in the plane from the standard input,

I have the C++ code given below.

// This program reads three points (x1,y1), (x2,y2) and (x3,y3) // in the plane from the standard input, in format // // x1 y1 // x2 y2 // x3 y3 // // Then it writes, to the standard output, the two of those points // that are closest. If there are two or more equally close pairs, // then all shows all closest pairs. #include  #include  using namespace std; // Echo writes points (x1,y1), (x2,y2) and (x3,y3), as the // original three points. void echo(double x1, double y1, double x2, double y2, double x3, double y3) { } // Distance returns the distance between the points (x1,y1) and (x2,y2). double distance(double x1, double y1, double x2, double y2) { // stub: return 0; } // ShowClosest writes that points (x1,y1) and (x2, y2) // are the closest points, and the distance between them // is d. void ShowClosest(double x1, double y1, double x2, double y2, double d) { } // If (x1,y1) and (x2,y2) are a closest pair among points // (x1,y1), (x2,y2) and (x3,y3), then 'consider' writes that // they are closest points. // // Otherwise, 'consider' does not write anything. void consider(double x1, double y1, double x2, double y2, double x3, double y3) { } int main() { return 0; }

I need to finish the code by

Make 'echo' show the three input points in a readable format. Be sure that the output clearly labels them as the input points.

Make 'main' read the 6 real numbers and show them on the standard output by calling 'echo'. Test your program Test it before continuing to the next step.

Make 'distance' do what its contract says it does.

Note. Any time any function other than 'distance' needs to know the distance between two points, itmust use 'distance' to get that information.

Make 'main' show the distance between (x1, y1) and (x2, y2). Test your program. Is the result correct? Do not countinue until it is correct.

7. Define 'showClosest'.

Make 'showClosest' show points (x1, y1) and (x2, y2) as the closest, and show d as the distance between them. 'ShowClosest' is not responsible for determining whether (x1, y1) and (x2, y2) are closest. Its job is just to write that they are.

Make 'main' show (x1, y1) and (x2, y2) as the closest points by calling showClosest. Don't be worried that those two points aren't necessarily closest.

Test your program. Does it show the first two points as the closest? Do not countinue until it is works correctly, according to what it is designed to do at this step.

Make 'consider' do what its contract says it does.

Remove the test prints from prior tests and add three calls to 'consider', one with (x1, y1) and (x2, y2) as the first two points, another with (x1, y1) and (x3, y3) as the first two points and a third with (x2, y2) and (x3, y3) as the first two points.

Do not use any global or static variables. All variables must either be parameters or created inside a function.

Do not change the value of any parameter. If x1 is a parameter to a function then the function must not contain

 x1 =  

or any other kind of statement that changes the value of x1.

The last character that your program writes on the standard output should be an end-of-line character (' ').The body of every if-statement must be a compound statement. That is, it must be surrounded by braces.

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

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions

Question

Classify each chemical reaction

Answered: 1 week ago