C++ Program Using Functions ( DO NOT USE FSTREAM, OR ARRAYS. USE WHILE STATEMENTS AND TAKE DATA FROM

C++ Program Using Functions (DO NOT USE FSTREAM, OR ARRAYS. USE WHILE STATEMENTS AND TAKE DATA FROM CIN USING CIN >> DATA)

The input for this program will be read from via Linux redirection. (Input will be taken through the extraction operator (cin) and will NOT use filestreams.) Their will be several data sets. Each data set will consist of 2 sets of x and y coordinates (that may be the same). All coordinates will be integer and will be separated by whitespace. For example, the data set 3 5 -1 7 represents Point 1 (3,5) and Point 2 (-1,7).

Design and implement a C++ program (using functions to modularize the task) that will do the following.

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

Read the data from a file (as described above) using Linux redirection and

display the coordinates of the 2 points with labels and in the form: (x,y)

if the points are the same, display a message indicating this

if the points are different,

determine and display the length of the line segment defined by the 2 points (floating point value)

determine and display the coordinates of the midpoint of the line segment (floating point values)

determine and display the slope of the line (as a whole number, a simplified fraction, or undefined)

for example if rise/run = 12/3, display 4, if rise/run = 24/-36, display -2/3, if rise/run = 5/0, display “undefined”

if the line is vertical,

display the equation of the line (x = a, where a is the x-intercept)

if the line is not vertical,

display the equation of the line in slope-intercept form (y = mx + b)

do not display extraneous symbols/values, for example

if m is 0 do not display the x term (y = b)

if b is 0 and m is non-zero do not display the b term (y = mx)

if b is negative, display y = mx – b rather than y = mx + -b

determine and display the slope of the line perpendicular to the line defined by the 2 points (as a whole number, simplified fraction, or undefined – see description of slope above)

display the equation of the perpendicular line passing through point 1

separate the output for each pair of points with at least one blank line

NOTES/REQUIREMENTS:

FUNCTIONS MUST BE USED TO MODULARIZE THE PROGRAM. At least 4 functions (besides main) must be used. The functions must be meaningful – i.e. do not design a function that just adds 1 to a counter.

Assumptions about input: (you do not have to test for these conditions)

all input values will be integers

each data set will consist of 4 integers that represent x1, y1, x2, and y2 in that order

each input value will be separated by whitespace (blanks and/or linefeeds)

the last line in the data file will be terminated with a linefeed ('n')

Program must be designed to run in batch mode (no prompts) via Linux redirection.

Do not use setprecision to control the number of decimal places displayed for floating point values.

Slopes of the 2 lines must be displayed as whole #s, fractions, or undefined.

If the slope cannot be displayed as a whole #, the fraction must be simplified (reduced) to lowest terms (i.e. find largest common divisor).

Fraction must be display in a commonly acceptable format (n/d or -n/d, not n/-d or -n/-d).

When displaying equation of the line, convert the slope from rise/run to a decimal value (do not setprecision).

abs and fabs are library functions that return the absolute value of an int and floating point value, respectively. abs is in cstdlib and fabs is in cmath. If you choose to use either function, make sure you include the header file.

Sample terminal session:

[user@bobby keys]$ more data4four
15 3 60 18
-4 -20 -1 -5
5 0 5 10
3 7 -2 7
[user@bobby keys]$ g++ assign04.cpp
[user@bobby keys]$ ./a.out

Point 1: (15,3)     Point 2: (60,18)
Length of defined line segment: 47.4342
Midpoint of line segment is: (37.5,10.5)
Slope of line: 1/3
Equation: y = 0.333333x – 2
Slope of perpendicular line: -3
Perpendicular line equation: y = -3x + 48

Point 1: (-4,-20)     Point 2: (-1,-5)
Length of defined line segment: 15.2971
Midpoint of line segment is: (-2.5,-12.5)
Slope of line: 5
Equation: y = 5x
Slope of perpendicular line: -1/5
Perpendicular line equation: y = -0.2x – 20.8

Point 1: (5,0)     Point 2: (5,10)
Length of defined line segment: 10
Midpoint of line segment is: (5,5)
Slope of line: undefined
Equation: x = 5
Slope of perpendicular line: 0
Perpendicular line equation: y = 0

Point 1: (3,7)     Point 2: (-2,7)
Length of defined line segment: 5
Midpoint of line segment is: (0.5,7)
Slope of line: 0
Equation: y = 7
Slope of perpendicular line: undefined
Equation of perpendicular line: x = 3

 

Looking for a Similar Assignment? Let us take care of your classwork while you enjoy your free time! All papers are written from scratch and are 100% Original. Try us today! Use Code FREE15