The purpose of this lab is to design and implement a stand-alone "console mode" program that incorporates at least one function in addition to main().
In this lab, you will:
You have been asked to design and implement a C++ program to calculate the area of a triangle, given the 2-dimensional coordinates of its vertices. Your program must also output some additional information.
Your program will be given the x- and y-coordinates of the three triangle vertices. It should output:
Graphically, the problem looks like this:

The distance between two points (a and b) is given by:

The distance from a point p to a line with endpoints a and b is given by:

Read the input from a text file named "lab3in.txt"; write the output to a text file named "lab3out.txt". For a simple test case, the input might look like this:
0 0 3 0 6 4 |
The corresponding output file would be:
| Point 1: (0,0) Point 2: (3,0) Point 3: (6,4) Distance 1-2: 3 Distance 1-3: 7.2111 Distance 2-3: 5 Triangle height is measured from point 3 to the baseline connecting points 1 and 2. Triangle height: 4 Triangle area: 6 |
Your program output should match the format of the sample output file. If you wish, you may enhance the program (e.g., format the output so numbers line up and have a consistent width), but be sure you meet the problem specifications first. You may round off all printed answers to two decimal places, and assume that no coordinate value magnitude will exceed 999.99.
If you have difficulties with any part of the lab, consult the instructor for assistance. The basic sequence is:
double Distance (double xa, double ya, double xb, double yb);
// Arguments:
// xa - X-coordinate of the first point.
// ya - Y-coordinate of the first point.
// xb - X-coordinate of the second point.
// yb - Y-coordinate of the second point.
// Returns: The magnitude of the distance between the two points.
double LineDistance (double xp, double yp,
double xa, double ya,
double xb, double yb);
// Arguments:
// xp - X-coordinate of the point.
// yp - Y-coordinate of the point.
// xa - X-coordinate of the origin of the line segment.
// ya - Y-coordinate of the origin of the line segment.
// xb - X-coordinate of the end of the line segment.
// yb - Y-coordinate of the end of the line segment.
// ASSUME: The length of the line segment is not zero.
// Returns: The magnitude of the perpendicular distance
// between the point and the line containing
// the line segment.
The lab report should consist of the following:
You may submit this report in hard-copy form, or email it to the instructor. If you choose email, it may be convenient to put the textual portion of the report directly in the message, and to attach the other files. Ask the instructor for the details on this procedure if you wish to try it. Be sure to keep copies of all your files, in case something gets lost; it may be wise to keep a diskette backup as well.
The lab report is due by the beginning of the following lab period, though you are encouraged to submit it sooner if you can. Your grade will depend on quality of design and clarity of the code and documentation, as well as whether your program produces the correct results. If you have any questions, consult the instructor.
This page was last updated on October 08, 1997; send comments to Mark Sebern.