Question: 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
-
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. -
The program should show, on the standard output,
- the three points that were read,
- the two of the three points that are closest together, and
- 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; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
