Question: Write a C++ program that outputs a menu and depending on the users choice prompts for the correct number of points then outputs the length
Write a C++ program that outputs a menu and depending on the users choice prompts for the correct number of points then outputs the length of a line segment, perimeter of a triangle, or the perimeter of a rectangle. This program must use the indicated struct and overload the calcPerimeter function.
o The program outputs to the screen and obtains all input from the user. o For each function make sure you are passing properly the parameters by value or by reference as is appropriate. o You must define and use a struct named Point. This type must have two members: a double for the xcoordinate of the point and a double for the ycoordinate of the point. o You must use and define the following functions; you may define more functions if you find it useful to do so. 1) readPoint Parameters: none Return: Point the point entered by the user Read a point 2) calcDistance Parameters: two points Return: double the distance between the points Determine the distance between two points using this formula: To find the distance from (x0,y0) to (x1,y1) calculate d=sqrt[((x1x0)^2)+((y1y0)^2)]. 3) calcPerimeter (to demonstrate your mastery of overloading functions, you will write two versions of this function) Parameters: two points Return: double the perimeter of a rectangle for which the given points are diagonal corners. ie: the points (2,3) and (-1,7) define the rectangle (2,3), (2,7),(-1,7), and (-1,3). For this function to perform meaningfully we make an assumption about the points entered, be sure to describe it in the program comment box. 4) calcPerimeter (to demonstrate your mastery of overloading functions, you will write two versions of this function) Parameters: three points Return: double the perimeter of a triangle Determine the perimeter of the triangle formed by the given points. Use the distance formula to determine the distance between pairs of points. For this function to perform meaningfully we make an assumption about the points entered, be sure to describe it in the program comment box. 5) writePoint Parameters: one point Return: none Write a point in standard (x,y) format to the screen.
Here is how the program should perform:
===================== Point Calculator Menu ===================== A. Length of a line segment B. Perimeter of a triangle C. Perimeter of a rectangle D. Quit ?> A Enter a point as two space delimited real numbers: 1 2 Enter a point as two space delimited real numbers: 3 4 The line segment from (1, 2) to (3, 4) is 2.82843 units long.
===================== Point Calculator Menu ===================== A. Length of a line segment B. Perimeter of a triangle C. Perimeter of a rectangle D. Quit ?> B Enter a point as two space delimited real numbers: 2 4 Enter a point as two space delimited real numbers: 1 5 Enter a point as two space delimited real numbers: 3 6 The triangle (2, 4), (1, 5), (3, 6) has a perimeter 5.88635 units long.
===================== Point Calculator Menu ===================== A. Length of a line segment B. Perimeter of a triangle C. Perimeter of a rectangle D. Quit ?> C Enter a point as two space delimited real numbers: 4 8 Enter a point as two space delimited real numbers: 5 10 The rectangle (4, 8), (4, 10), (5, 10), (5, 8) has a perimeter 4 units long.
===================== Point Calculator Menu ===================== A. Length of a line segment B. Perimeter of a triangle C. Perimeter of a rectangle D. Quit ?> D Good-bye
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
