Starting from:
$29.99

$23.99

Homework # 5 Solution

In this homework, you will modify your Reversi and Ce l classes of HW4 to make them work with operator overloading.

For the Cell class, overload the following operators

• operators <, , = , =, == and != for comparing two Cells. One Cell object is smaller than the other if the Y components is smaller. If Y components are equal, then check the X component.

• Operators ++ and - - that increment and decrement the X and Y components by one. Overload both

prefix and postfix operators.

• Stream insertion and extraction operators

 

For the Reversi class, you will overload the following operators

• Operator++ (both posfix and prefix) will advance the game by one step for computer. It will return the expected results.

• Operator- - (both posfix and prefix) will undo the game by one step for the last play (user or computer). It will return the expected results. You can undo all the game moves back to the beginning of the game. (Hint: you will need to think about this operator a little).

• Overload the [] operator such that if g is a Reversi object, g[“A5”] will return the Cell at row

5 and column A. If there is no such Cells, then it will return a new Cell with position (-1000,-

1000).

• Operator() with two parameters behaves exactly the same as g[“A5”].

• Operator+= that takes another a Cell object and plays the game for the user.

• Stream insertion operator that prints the game on the screen

Write your main function to test new classes. Make at least 5 objects of class Reversi and show the results of each operator overload.

More products