// CIS 235 Class Example on Composition of Classes Lecture 8 #include using std::cout; using std::cin; using std::endl; #include "point.h" #include "window.h" // Client Functions Point makePoint(int xV, int yV); Window makeWindow( int xLeft, int yLeft, int xRight, int yRight); Window makeWindow( const Point & left, const Point & right); Point & inputPoint(Point &); Window & inputWindow(Window &); void main() { Window a(1,4,3,2); a.print(cout); cout << endl; a.moveHor(5).moveVer(7).print(cout); cout << endl << "Perimeter is " << a.perimeter()<< endl; Point b; b = makePoint(50,75); cout << "The point b is " ; b.print(cout); cout << endl; // Example of function chaining makeWindow(Point(4,10),Point(12,18)).moveVer(6).moveHor(-3).print(cout); return; } // end of main Point makePoint(int a, int b) { return Point(a,b); } Window makeWindow( int xLeft, int yLeft, int xRight, int yRight) { return Window(xLeft,yLeft,xRight,yRight); } Window makeWindow( const Point & left, const Point & right) { return Window(left,right); } Point & inputPoint(Point & p) { cout << "Enter row and column for a point "; int workX, workY; cin >> workX >> workY; p.setRow(workX).setColumn(workY); return p; } Window & inputWindow(Window & b) { Point workUleft, workLright; cout << "Enter upper left corner "; inputPoint(workUleft); b.setLeft(workUleft); cout << "Enter lower right corner "; inputPoint(workLright); b.setRight(workLright); return b; } /* My output Upper Left [1,4] Lower Right [3,2] Upper Left [8,9] Lower Right [10,7] Perimeter is 8 The point b is [50,75] Upper Left [10,7] Lower Right [18,15]Press any key to continue . . . */