Question: c++ Create a class called Shape this class must not be instantiable. it has 2 attributes. int numOfSides, float lengthOfSides[] it has 4 methods calculateArea(),

c++

  1. Create a class called Shape
    • this class must not be instantiable.
    • it has 2 attributes. int numOfSides, float lengthOfSides[]
    • it has 4 methods
      • calculateArea(),
      • calculatePerimeter()
      • showData()
      • findLarger(Shape* s2) - this finds the larger of 2 shapes, based on area and uses showData() to print out the data of the larger Shape
  2. Define 2 derived classes of Shape called Circle and Rectangle
    • Circle: numOfSides = 1 (the radius is kept in lengthOfSide[0])
      • Area = *r*r
      • Perimeter = 2 * * r
      • showData() will print out Circle: Radius 5, Area = 78.5375... (it is enough to show only a few decimal digits)
    • Rectangle: numOfSides = 4, opposite sides are equal a, b
      • Area = a*b
      • Perimeter = 2* (a + b)
      • showData() will print out Rectangle: 5,2, 5, 2 Area = 10
      • isSquare() returns true if all the sides are equal
  3. Define a main() in ShapeDriver.cpp and test the following
    • Instantiate one Circle with a radius of 10
      • Run showData() on that circle
      • Run findLarger by comparing with another Circle whose radius is 4.5
    • Instantiate 2 Rectangles
      • rect1 with sides 5,4, 5,4 and rect2 with sides 5,5,5,5
      • Run showData() on rect1
      • findLarger comparing it to rect2
      • Run isSquare() on both rect1 and rect2
    • Add all these Shapes to any kind of STL container you wish to and run showData() on all the objects added to that container

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!