/*

Copyright: 1999, All rights reserved.
Program: Rectangle
Version: 1.0
Created/Revised: 9/22/99 
File: rectangle.cpp
Programmer: C. S. Tritt, Ph.D.
Course: CS-150
Assignment: Example
Compiler: Microsoft Visual C++ 6.0
Target: Win32

Description:

  This program asks the user to enter two points (the corners of a 
  rectangle).  It then draws the complete rectangle and calculates and
  displays its area in the middle of the rectangle.  Using a 15.0 by 
  15.0 cm coordinate system.

Revisions:

  There have been no major revisions of this program.

Constants and Variables:

  See code for constant and variable descriptions.

*/

// Included files.

#include "ccc_win.cpp" 

using namespace std;

int main()
{

	// Define constants.

	const double XMIN = 0.0; // Minimum x coordinate value (cm).
	const double XMAX = 15.0; // Maximum x coordinate value (cm).
	const double YMIN = 0.0; // Minimum y coordinate value (cm).
	const double YMAX = 15.0; // Maximum y coordinate value (cm).
	const double OFFSET = 1.5; // Offset for "Area =" phrase (cm).

	// Set coordinate system.

	cwin.coord(XMIN, YMAX, XMAX, YMIN);

	// Get corners from user.

	Point pul = cwin.get_mouse("Click on upper left corner");
	cwin << pul;
	Point plr = cwin.get_mouse("Click on lower right corner");
	cwin << plr;

	// Complete rectangle.

   Point pll(pul.get_x(), plr.get_y()); // Lower left corner.
   Point pur(plr.get_x(), pul.get_y()); // Upper right corner.
	cwin << pur << pll; // Display points.
	Line left(pll, pul);
	Line top(pul, pur);
	Line right(pur, plr);
	Line bottom(plr, pll);
	cwin << left << top << right << bottom; // Draw lines.

	// Calculate and output area.

	double area = (pul.get_y() - pll.get_y()) * (plr.get_x() - pll.get_x());
   double xm = (pll.get_x() + plr.get_x()) / 2.0;
	double ym = (pll.get_y() + pul.get_y()) / 2.0;
	Point center(xm, ym);
	Point left_of_center(xm - OFFSET, ym);
	cwin << Message(center, area) << Message(left_of_center, "Area =");

	// Everything worked.

	return 0;
}