|
|
Program 6 - February 19In this assignment, you will develop a simple base class and then make use of inheritance to upgrade it with added functionality. You will also get some more practice using operator overloading. There are two required parts and an extra credit assignment for those interested in doing it. Note: This assignment was originally posted with errors in it. Check for corrections below in red. Click here for an explanation.Part 1The following class declaration represents a rectangle which lives in a cartesian coordinate system. Positive values of coordinates increase from bottom to top and left to right. class Rect public: void
Normalize(); // make
bottom less than top int
Width(); // return the width of the
rectangle // Move the upper left corner while
maintaining the size // Change the width and height without moving
it const Rect & operator=(const Rect &); protected:
// Why? Put the above code into a header file. Develop a cpp file which
implements the class. Develop a short program that exercises all the functions.
You may use any format you desire to output the numbers that make up a rect. One
way is to print Part 2Publicly derive a new class from Rect called SmartRect. Give it the following new functions: // True if point (x,y) is inside the rect // Return the union of two rects // Return the intersection of two rects Create a new header file and an implementation file for
SmartRect. Don't change any code for Rect. Modify your test Why the Changes?
Extra CreditModify your TicTacToe program to use inheritance. Develop a class called Player which has the same interface as your human and computer players. Put anything that is common between the two existing classes into player. Modify your human and computer player classes so that they each derive from Player. Since we have not yet learned about virtual functions, your Player::MakeMove() routine could just give an error message since it should never be called. Don't change your main program, until we have virtual functions, you should still make all your calls through derived class objects or pointers. You'll get another shot at this when we get to chapter 10. |
|
Copyright © 2000 Charlie Poole. All rights reserved.
|