//------------------------------------------- // Filename : Quadrilateral.H // Author : DL Frey // Date : 2/20/03 // Project : CMSC 202 Spring 2003 Project 2 // Section : 1234 // SSN : xxx-xx-1234 // // This file provides the interface for // the Quadrilateral class required for project 2 // The Quadrilateral uses Point objects to store // x- and y-coordinates of it's corners // // Per the project specification, the implementation // of this class assumes // 1. the base (LL to LR) is parallel to the x-axis // 2. for trapezoids, the parallel sides are also // paralled to one of the axes //--------------------------------------------- // // This version of Quadrilateral.H supports the // notion of well-formed Quadrilaterals by declaring // a new private data member and new private method //------------------------------------------------- #ifndef QUADRILATERAL_H #define QUADRILATERAL_H #include "Point.H" using namespace std; class Quadrilateral { public: // -------------------------------- // Method: Default constructor // PreConditions: none // PostConditions: // A new quadrilateral is created with // all corners constructed per Point's // default constructor Quadrilateral( void ); // mutators for the corners //----------------------------------- // Method: SetUpperLeft // PreConditions: none // PostConditions: UpperLeft corner set to p //----------------------------------- void SetUpperLeft (const Point& p); //----------------------------------- // Method: SetUpperRight // PreConditions: none // PostConditions: UpperRight corner set to p //----------------------------------- void SetUpperRight (const Point& p); //----------------------------------- // Method: SetLowerLeft // PreConditions: none // PostConditions: LowerLeft corner set to p //----------------------------------- void SetLowerLeft (const Point& p); //----------------------------------- // Method: SetLowerRight // PreConditions: none // PostConditions: LowerRight corner set to p //----------------------------------- void SetLowerRight (const Point& p); // accessors for corners //------------------------------------------ // Method: GetUpperLeft // PreConditions: none // PostConditions: UpperLeft corner returned //------------------------------------------ const Point& GetUpperLeft ( void ) const; //------------------------------------------ // Method: GetUpperRight // PreConditions: none // PostConditions: UpperRight corner returned //------------------------------------------ const Point& GetUpperRight ( void ) const; //------------------------------------------ // Method: GetLowerLeft // PreConditions: none // PostConditions: LowerLeft corner returned //------------------------------------------ const Point& GetLowerLeft ( void ) const; //------------------------------------------ // Method: GetLowerRight // PreConditions: none // PostConditions: LowerRight corner returned //------------------------------------------ const Point& GetLowerRight ( void ) const; // Quadrilateral Categorization Methods //-------------------------------- // Method: IsParallelogram // PreConditions: // The Quadrilateral must be well-formed // PostConditions: // returns true if both pairs of sides // are equal in length // returns false if not well-formed //--------------------------------- bool IsParallelogram( void ) const; //-------------------------------- // Method: IsRectangle // PreConditions: none // PostConditions: // returns true if the Quadrilateral // is a prallelogram with one right angle // which implies it has 4 right angles //--------------------------------- bool IsRectangle( void ) const; //--------------------------------------- // Method: IsSquare // PreConditions: none // PostConditions: // returns true if the Quadrilateral // is a rectangle with equal length sides //---------------------------------------- bool IsSquare (void ) const; //--------------------------------------- // Method: IsTrapezoid // PreConditions: // Quadrilateral must be well-formed // PostConditions: // returns true if the Quadrilateral // has exactly one pair of parallel sides // returns false if not well-formed //---------------------------------------- bool IsTrapezoid (void) const; //--------------------------------------- // Method: IsIrregular // PreConditions: none // PostConditions: // returns true if the Quadrilateral // is none of the above //---------------------------------------- bool IsIrregular (void) const; //--------------------------------------- // Method: Area // PreConditions: // The Quadrilateral must be well-formed // PostConditions: // calculates and returns the area of // the quadrilateral // returns 0.0 if not well-formed // returns 0.0 for irregular quadrilateral // per project 2 spec //---------------------------------------- double Area( void ) const; //--------------------------------------- // Method: Perimeter // PreConditions: none // PostConditions: // calculates and returns the perimeter of // the quadrilateral //---------------------------------------- double Perimeter (void ) const; private: double TrapezoidArea (void ) const; Point m_upperLeft; Point m_upperRight; Point m_lowerLeft; Point m_lowerRight; // for well-formed support bool wellFormed; bool IsWellFormed( void ) const; }; #endif