//----------------------------------- // Filename: Proj2Aux.C // Author : DL Frey // Date : 2/21/03 // Project : CMSC 202, Spring 03, Project 2 // Section : 123 // SSN : xxx-xx-1234 // Description // This file contains functions called from // main() in proj2.C and local functions used // by them // Functions called from main() // InputCorners() // DisplayQuadrilateral() //----------------------------------------------- #include #include #include // for abs() #include // for sqart() #include "Quadrilateral.H" #include "Point.H" using namespace std; // prototypes for functions used only in this file void DisplayCorners (const Quadrilateral& quadrilateral); void DisplayType (const Quadrilateral& quadrilateral); void DisplayStats (const Quadrilateral& quadrilateral); //------------------------------------------------------ // Function: InputCorners // PreConditions: none // PostConditions: // the user is prompted for the x- and y-coordinates // of the four corners of a quadrilateral. // The base between the LowerLeft and LowerRight corners // must be parallel to the x-axis //------------------------------------------------------- void InputCorners (Quadrilateral& quadrilateral) { int x; int y; // input the four corners of the quadrilateral // verify that the base (LowerLeft to LowerRight) is parallel // to the x-axis cout << "Please enter x- and y-coordinates of the UpperLeft corner: "; cin >> x >> y; quadrilateral.SetUpperLeft (Point(x,y)); cout << "Please enter x- and y-coordinates of the LowerLeft corner: "; cin >> x >> y; quadrilateral.SetLowerLeft (Point(x,y)); do { cout << "Please enter x- and y-coordinates of the LowerRight corner: "; cin >> x >> y; if (y != quadrilateral.GetLowerLeft().GetY()) cout << "Y-coordinate must be the same for LowerLeft and LowerRight" <> x >> y; quadrilateral.SetUpperRight (Point(x,y)); } //-------------------------------------------- // Function: DisplayQuadrilateral // PreConditions: // Per Project 2 specs, assumes the the // 4 corners actually form a quadrilateral // PostConditions: // Prints coordinates of the quadrilateral's corners // Prints the quadrilateral type // Prints the quadrilateral area and perimeter //----------------------------------------------- void DisplayQuadrilateral (const Quadrilateral& quadrilateral) { DisplayCorners (quadrilateral); DisplayType (quadrilateral); DisplayStats (quadrilateral); } //-------------------------------------------- // Function: DisplayCorners // PreConditions: none // PostConditions // Prints coordinates of the quadrilateral's corners // per project 2 specification // Called from DisplayQuadrilateral() in this file //----------------------------------------------- void DisplayCorners (const Quadrilateral& quadrilateral) { // output the corners -- two per line with coordinates // in parans separated by commas cout << endl; cout << "The Quadrilateralrilateral's Corners" << endl; cout << setw(20) << "Upper Left: (" << setw(3) << quadrilateral.GetUpperLeft().GetX() << "," << setw(3) << quadrilateral.GetUpperLeft().GetY() << ")"; cout << setw(20) << "Upper Right: (" << setw(3) << quadrilateral.GetUpperRight().GetX() << "," << setw(3) << quadrilateral.GetUpperRight().GetY() << ")"; cout << endl; cout << setw(20) << "Lower Left: (" << setw(3) << quadrilateral.GetLowerLeft().GetX() << "," << setw(3) << quadrilateral.GetLowerLeft().GetY() << ")"; cout << setw(20) << "Lower Right: (" << setw(3) << quadrilateral.GetLowerRight().GetX() << "," << setw(3) << quadrilateral.GetLowerRight().GetY() << ")"; cout << endl << endl; } //-------------------------------------------- // Function: DisplayType // PreConditions: none // PostConditions // Determines and displays the quadrilateral type // per project 2 specification // Called from DisplayQuadrilateral() in this file //----------------------------------------------- void DisplayType (const Quadrilateral& quadrilateral) { // determine and output the type of quadrilateral // start with most specific and move to more general if (quadrilateral.IsSquare()) cout << "This Quadrilateral is a Square" << endl; else if (quadrilateral.IsRectangle()) cout << "This Quadrilateral is a Rectangle" << endl; else if (quadrilateral.IsParallelogram()) cout << "This Quadrilateral is a Parallelogram" << endl; else if (quadrilateral.IsTrapezoid()) cout << "This Quadrilateral is a Trapezoid" << endl; else cout << "This quadrilateral is Irregular" << endl; } //-------------------------------------------- // Function: DisplayStats // PreConditions: none // PostConditions // Prints area and perimeter of the quadrilateral // per project 2 specification // Both are printed in this function to assure // proper formatting and alignment per specs // // Called from DisplayQuadrilateral() in this file //----------------------------------------------- void DisplayStats (const Quadrilateral& quadrilateral) { // output the area and perimeter vertically aligned // with 4 decmial places cout << fixed << setprecision(4); cout << setw(20) << "Area: " << quadrilateral.Area() << endl; cout << setw(20) << "Perimeter: " << quadrilateral.Perimeter() << endl; }