Posted: |
Monday 2/17/03 |
Design Document Due: |
Before midnight, Tuesday 2/25/03 |
Project Due: |
Before midnight, Tuesday 3/4/03 |
Notes |
Feb 22, 2003 8:45am
When investigating this discrepancy we realized that requiring students to make calculations for a trapezoid with this orientation takes away from the focus of the project -- implmenting and using classes and objects in C++. Therefore, students may assume (as was originally the plan) that trapezoids will be oriented as first described and as shown in the diagrams below. The parallel sides are either parallel to the x-axis or parallel to the y-axis.
Feb 18, 2003 2:30pm
Feb 17, 2003
|
In geometry, a 4-sided figure is called a "Quadrilateral". Depending on its exact shape, a quadrilateral can be classified as follows
In this project, you will ask the user to input the x- and y-coordinates of the four corners of a quadrilateral. The corners are called "UpperRight", "UpperLeft", "LowerLeft" and "LowerRight" and hereafter referred to as UR, UL, LL and LR respectively.
Your program will then classify the quadrilateral as above and output some information about the quadrilateral.
This project will require you design and implement two C++ classes as described below. Be sure to consider the OOP principles of encapsulation and data hiding when designing and implementing these classes. main() and other functions are also described.
The Point class will encapsulate the x- and y-coordinates of one point in the coordinate plane. In keeping with the coding standards, the Point class will be defined in Point.H and implemented in Point.C. The Quadrilateral class uses the Point class to represent each of its four corners (an example of aggregation/composition). You may assume that the coordinates are integers (although this has little effect on your code).
The only operations allowed by the Point class are listed. If you find that you don't need all these operations, then you are not required to implement them. No other public methods are permitted. You may provide whatever PRIVATE methods you feel are necessary.
This class represents a quadrilateral in the coordinate plane by using the Point class to store the x- and y-coordinates of its corners. This class will be defined in Quadrilateral.H and implemented in Quadrilateral.C.
The "const"ness of the member functions has purposely been omitted. It's up to you to determine which should be const and which should not.
The operations permitted by the Quadrilateral class are listed. No other public methods are permitted. If you find that you don't need all these operations, then you are not required to implement them. No other public methods are permitted. You may provide whatever PRIVATE methods you feel are necessary.
To ease the coding of the Quadrilateral methods, the following functions are also required. These functions are NOT members of either the Point or Quadrilateral classes; they are "non-member" functions. Since they are related to Points, their prototypes may be defined in Point.H and they may be implemented in Point.C.
The next two definitions rely on the base of the quadrilateral being parallel to the x-axis. Because of this constraint, you can use these functions to find the distance between two parallel lines.
About math functions
Proj2 is invoked with no command line arguments. An appropriate error message must be displayed if command line arguments are provided. Your program should then exit.
Your main() will prompt the user for the coordinates of the four corners of your quadrilateral. You can use whatever prompts you want, but the user must be allowed to input both the x- and y-coordinate on the same line as in the sample output below. You may assume that the user will input the corners in their proper relationship (i.e. "UpperRight" really will be the corner in the relative upper-right position). You may assume the user will enter four distinct corners that really do form a quadrilateral. You may assume that the coordinates are integers and that the user will input integers when requested. Your input validation must check that the base of the quadrilateral (the line between LL and LR) is parallel to the x-axis (see above). If not, produce an error message and reprompt.
Your program will also produce the output shown below and formatted as follows.
The area and perimeter must be printed on separate lines, their labels must be right justified and aligned and their values must be aligned and printed with exactly 4 decimal places of precision. Print trailing zeros if necessary.
The corners must be printed as shown. In particular the labels must be right justified and aligned and the coordinates must be printed in a 3-character field, separated by a comma and enclosed in parentheses.
You should of course use good top-down design for main. If you write any functions called by main, they must be implemented in Proj2Aux.C and their prototypes must be in Proj2Aux.H.
A quadrilateral is a parallelogram if both pairs of
sides are parallel. This is equivalent saying that the lengths of the opposite
sides of each pair of sides are equal.
I.e. if the distance from UL to UR equals the distance from LL to LR
and the distance from UL to LL equals the distance from UR to LR
A quadrilateral is rectangle if it is a parallelogram with four right angles. Note that it is sufficient to test the angle at just one corner, since if a parallelogram has one right angle, it must have four right angles, else it's not a parallelogram.
A quadrilateral is a square if it is a rectangle with four equal sides. Note that since it is a rectangle (and hence a parallelogram) it is only necessary to compare the length of one horizontal side with the length of one vertical side.
A quadrilateral is a trapezoid if it has exactly one
pair of parallel sides.
It's not a parallelogram and the horiztonal distance from UL to UR
equals the horizontal distance from LL to LR,
OR
the vertical distance from UL to LL equals the vertical distance from
UR to LR,
The area of a trapezoid = 1/2 * (sum of the lengths of the parallel sides) * (distance between the parallel sides)
A quadrilateral is irregular if it is none of the above.
You have to match this output almost exactly (see above). Your prompts may vary, but you must allow both coordinates to be input on the same line. The greeting is optional, but if present will be more elaborate than the sample below.
linux3[1]% Proj2 2 3 4
Invalid Command Line: No command line arguments required
Usage: Proj2
linux3[1]% Proj2
This is my optional greeting
Please enter x- and y-coordinates of the UpperLeft corner: 4 5
Please enter x- and y-coordinates of the LowerLeft corner: 4 1
Please enter x- and y-coordinates of the LowerRight corner: 8 4
Y-coordinate must be the same for LowerLeft and LowerRight
Please enter x- and y-coordinates of the LowerRight corner: 8 6
Y-coordinate must be the same for LowerLeft and LowerRight
Please enter x- and y-coordinates of the LowerRight corner: 8 1
Please enter x- and y-coordinates of the UpperRight corner: 8 5
The Quadrilateral's Corners
Upper Left: ( 4, 5) Upper Right: ( 8, 5)
Lower Left: ( 4, 1) Lower Right: ( 8, 1)
This Quadrilateral is a Square
Area: 16.0000
Perimeter: 16.0000
linux3[2]%
linux3[2]% Proj2
This is my optional greeting
Please enter x- and y-coordinates of the UpperLeft corner: 1 4
Please enter x- and y-coordinates of the LowerLeft corner: 1 2
Please enter x- and y-coordinates of the LowerRight corner: 10 2
Please enter x- and y-coordinates of the UpperRight corner: 10 4
The Quadrilateral's Corners
Upper Left: ( 1, 4) Upper Right: ( 10, 4)
Lower Left: ( 1, 2) Lower Right: ( 10, 2)
This Quadrilateral is a Rectangle
Area: 18.0000
Perimeter: 22.0000
linux3[3]%
linux3[3]% Proj2
This is my optional greeting
Please enter x- and y-coordinates of the UpperLeft corner: 6 4
Please enter x- and y-coordinates of the LowerLeft corner: 9 1
Please enter x- and y-coordinates of the LowerRight corner: 16 1
Please enter x- and y-coordinates of the UpperRight corner: 13 4
The Quadrilateral's Corners
Upper Left: ( 6, 4) Upper Right: ( 13, 4)
Lower Left: ( 9, 1) Lower Right: ( 16, 1)
This Quadrilateral is a Parallelogram
Area: 21.0000
Perimeter: 22.4853
linux3[4]%
linux3[4]% Proj2
This is my optional greeting
Please enter x- and y-coordinates of the UpperLeft corner: 5 5
Please enter x- and y-coordinates of the LowerLeft corner: -5 -5
Please enter x- and y-coordinates of the LowerRight corner: 7 -5
Please enter x- and y-coordinates of the UpperRight corner: 7 5
The Quadrilateral's Corners
Upper Left: ( 5, 5) Upper Right: ( 7, 5)
Lower Left: ( -5, -5) Lower Right: ( 7, -5)
This Quadrilateral is a Trapezoid
Area: 70.0000
Perimeter: 38.1421
linux3[5]%
linux3[5]% Proj2
This is my optional greeting
Please enter x- and y-coordinates of the UpperLeft corner: 2 3
Please enter x- and y-coordinates of the LowerLeft corner: 0 1
Please enter x- and y-coordinates of the LowerRight corner: 11 1
Please enter x- and y-coordinates of the UpperRight corner: 7 5
The Quadrilateral's Corners
Upper Left: ( 2, 3) Upper Right: ( 7, 5)
Lower Left: ( 0, 1) Lower Right: ( 11, 1)
This quadrilateral is Irregular
Area: 0.0000
Perimeter: 24.8704
linux3[6]%
Your project design document for project 2 must be named design2.txt. Be sure to read the design specification carefully. Submit your design in the usual way: submit cs202 Proj2 design2.txt
You must validate all user input. If you detect invalid input, output a meaningful error message and reprompt for the input. See the sample output above.
You are required to submit a make file with this project. The grader should simply need to type "make Proj2" and your project should compile and link to an executable called Proj2. The grader should also have the ability to do a "make clean" and "make cleanest." Hint: Start with the makefile from project 1 and modify it.
See the make file tutorial for more information on make files.
The grade for this project will be broken down as follows. A more detailed breakdown will be provided in the grade form you receive with your project grade.
You must use separate compilation for this project. You should submit the following files.
Submit as follows:
submit cs202 Proj2 <list of files>
A complete guide to submit tools is available
on the course website.
More complete documentation for submit and related commands (not including
submitmake and submitrun) can be found here.
Remember -- if you make any change to your program, no matter how
insignificant it may seem, you should recompile and retest your program before
submitting it. Even the smallest typo can cause compiler errors and a reduction
in your grade.