Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Describe the even planning process and explain why it is helpful.

Answered: 1 week ago

Question

=+ Are unions company-wide, regional, or national?

Answered: 1 week ago

Question

=+j Explain the litigation risks in international labor relations.

Answered: 1 week ago