[SOLVED] 02393 Assignment 8-Fun with shapes

35.00 $

Category: Tags: , , , , , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment-8-Inheritance-iuchzu.zip (951.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Fun with shapes

The goal of the exercise is to implement a family of classes of two-dimensional shapes. You should implement a file shapes.h and a file shapes.cpp and upload them into CodeJudge. Our test cases will use those files (see also the example in class).

The following classes must be implemented: Shape, Rectangle, Square and Circle. There are several possibilities for the design of the classes. Try to think what are the possibilities for inheritance relations among the classes and how to reduce the amount of code. Further hints are provided in the test programs and in the related live code example.

The classes should provide some common methods:

  • Constructors: Rectangle objects are constructed from two doubles, that specify height and width, respectively; Square objects are constructed from one double, that specifies the length of the sides; Circle objects are constructed from one double, that specifies the radius.
  • area should return the area of the shape;
  • perimeter should return the perimeter of the shape;
  • height should return the height of the shape;
  • width should return the width of the shape;
  • rotate should have the effect of rotating a shape by 90 degrees. This may have no effect on some shapes;Further hints can be deduced from the test programs and from the example used in class.

    Challenge. Putting two rectangles of the same height side-by-side yields a new rectangle (possibly a square one). How would you implement such a func- tionality? Also, you could consider the exam example in CampusNet, which contains a related exercise in which the goal is to implement a class of regular polygons.

  • Assignment-8-Inheritance-iuchzu.zip