Topical Information

This lab should give you some practice writing your own functions.

Program Information

Write a program that helps the user calculate the midpoint of a line segment in the 2D Cartesian plane. (I know, I know... been there, done that. *phbbt* Keep reading, smarty!)

Try to make your results as readable as possible.

Use a function to calculate the midpoint between two 1D coordinates. The inputs (arguments) for this function should be the coordinates of the two points. The output (return value) for the function should be the calculated midpoint. This function will need to be called twice — once for the x coordinates and once for the y coordinates.


As an example, you might have the program interaction look something like (the parts in this coloration are typed by the user):

$ ./midpointfunc.out

                 Welcome to the 2D Midpoint Program!!!

What is the first end-point?  (3.4, 12.2)
What is the second end-point?  (13.4, 12.2)

Thank you!!  Calculating...  Done.

The midpoint of the line segment between (3.4, 12.2) and (13.4, 12.2)
is (8.4, 12.2).

Thank you for using the TMP!!

Endeavor to have a voracious day!

$

Thought Provoking Questions

  1. How many arguments does your function take? What are the data types of the arguments?

  2. What did you name the arguments to your function? Do the names matter to the compiler? Do the names matter at all?

  3. How many values does the function return? What is the returned value's data type?

  4. How many times do you call this function?

  5. IF you needed to for some reason, could you use this function when working with 3D points?

    (Do NOT alter your program in any way!!! Just answer the question! ...*sweet, oddly-juxtaposed smile*)

This assignment is (Level 3).

Options


Total Level Possible

If you did all above options, this lab could be worth as much as (Level 14.5).