Answered step by step
Verified Expert Solution
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++
- 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
- 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
- Circle: numOfSides = 1 (the radius is kept in lengthOfSide[0])
- 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
- Instantiate one Circle with a radius of 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started