Starting from:

$30

PROG1385-Assignment 7 Shapes Adding Operators Solved

STEP 1 – Connecting to your Source Repository and Extracting your Starting Point
1.     Since this exercise is based upon A-04 – all you need to do is to sign-out your existing Shape code from your repository

a.     Create a directory on the local machine – e.g. C:\SETRepo

b.     Connect to your repository in the cloud  (remembering your repository’s URL and your login credentials) using the Tortoise SVN client and perform an SVN Checkout.  What you should notice is that you have signed out your DisneyCharacter solution as well as your Shapes solution.

2.     If you like you can erase the DisneyCharacter subdirectory as you won’t be modifying that source in this exercise

3.     Once you have the Shapes solution – you are ready to begin this exercise … so let’s get into the requirements …

 

 

STEP 2 – The Requirements and Programming
 

In this exercise, you will take your existing classes from A-04 and add to them :

The Shape Class

        •      No changes

 

The Circle Class
•              Add the following methods to this class – you can add to the .H file – watch best practices !! o An overloaded + operation

▪  When adding one circle to another, the resultant circle will take on the colour of the left-hand operand (the LHS)

▪  The resultant radius is the sum of the left and right operand’s radii o      An overloaded * operation

▪  When multiplying one circle with another, the resultant  circle will take on the colour of the righthand operand (RHS)

▪  The resultant radius is the product of the left and right operand’s radii o                An overloaded = operation o            An overloaded == operation

▪  Which will return that 2 circles are equal if the radius and colours match

 

 

The Square Class
•              Add the following methods to this class – you can add to the .H file – watch best practices !! o An overloaded + operation

▪  When adding one square to another, the resultant square will take on the colour of the left-hand operand (the LHS)

▪  The resultant sideLength is the sum of the left and right operand’s sideLengths


                       o     An overloaded * operation

▪  When multiplying one square with another, the resultant square will take on the colour of the righthand operand (RHS)

▪  The resultant sideLength is the product of the left and right operand’s sideLengths o       An overloaded = operation o            An overloaded == operation

▪  Which will return that 2 squares are equal if the sideLengths and colours match

 

The myShape Main
•         Modify your testHarness to create the following shapes  o         you can simply instantiate the objects required – no need for user input …  o   Circle shape called “round1” with radius 5.5 cm and colour “red” o Circle shape called “round2” with radius 10.5 cm and colour “blue” o        Circle shape called “playARound” – instantiated with the default constructor of the Circle class

o   Square shape called “square1” with sideLength of 5 cm and colour “orange” o                Square shape called “square2” with sideLength of 12 cm and colour “purple”

o   Square shaped called “playASquare” – instantiated with the default constructor of the Square class

•         After creating these shapes, call the appropriate method to print out the specifics of each shape

•         Then use your overloaded operators to  o      Add round2 to round1 and store it in playAround               (i.e. round1 + round2)

▪  You should end up with playARound being “red” with radius of 16.0 cm o Add square1 to square2 and store in playASquare  (i.e. square2 + square1)

▪  You should end up with playASquare being “purple” with sideLength of 17 cm) o              Print out the specifics of playARound and playASquare

o   Multiply round1 by round2 and store in playARound                (i.e. round1 * round2)

▪  You should end up with a playARound being “blue” with a radius of 57.75 cm o Multiply square2 by square1 and store in playASquare  (i.e. square2 * square1)

▪  You should end up with a playASquare being “orange” with a sideLength of 60 cm o               Print out the specifics of playARound and playASquare

o   Assign round1 to playAround, and then test to see if they are equivalent

▪  i.e. playRound = round1;   followed by if(playAround == round1)

▪  If they are – then print “Hurray !!” to the screen

▪  If they are not equal – then print “Awww !!” to the screen

 

STEP 3 – Putting your Code back into the Repository
When you have made these changes to your class definitions and mainline – you can simply save your VS Solution and commit your files.

•         Start by saving all files in solution and existing Visual Studio.

•         In the previous exercise – you were reminded of repository best-practices  o       Where each source file needs to be committed individually with its own custom / specific comment o    So locate all of your source files (.H files and .CPP files) and commit them one-by-one

•         After committing the source files – you return to the C:\SETRepo directory where you do a final commit on the Shapes folder to pick up any stray files that also need to be committed

 

More products