Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a C++ code that does the following First it reads three points in the plane p 1 = ( x 1 , y 1

write a C++ code that does the following

  1. First it reads three points in the plane p1 = (x1, y1), p2 = (x2, y2) and p3 = (x3, y3) from the standard input in the following format.

     x1y1x2y2x3y3
    There are two real numbers per line, giving the x- and y-coordinate of a point in the plane.
  2. The program should show, on the standard output,

    1. the three points that were read,
    2. the two of the three points that are closest together, and
    3. the distance between those two closest points.

For example, if the input is

 1.0 3.0 1.5 7.2 4.0 2.0 

then the output should be

The three points are: 1.000 3.000 1.500 7.200 4.000 2.000 The closest two points are: 1.000 3.000 4.000 2.000 The distance between those two points is: 3.162 

If two or more points are at the same distance from one another, and that distance is the shortest distance, then the program should show the output for them all. For example, on input

 0.0 1.0 0.0 2.0 0.0 3.0 

the program should write

The three points are: 0.000 1.000 0.000 2.000 0.000 3.000 The closest two points are: 0.000 1.000 0.000 2.000 The distance between those two points is: 1.000 The closest two points are: 0.000 2.000 0.000 3.000 The distance between those two points is: 1.000 

Use output format %10.3lf to write each real number. (The last two characters of the format are lower-case ell and lower-case eff.)

Here is a template

// 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; }

ALL YOU NEED TO WRITE IS

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

4. Write part of 'main'.

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.

5. Define function 'distance'.

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, it must use 'distance' to get that information.

6. Modify your 'main' function.

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.

8. Modify 'main' again.

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.

9. Define 'consider'.

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

10. Modify 'main' again.

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.

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_2

Step: 3

blur-text-image_3

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 Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions