Use object oriented programming to solve this:   Inheritance/Polymorphism                               Suppose we want to write an application that manages shapes that has these requirements   Shapes can be circles or squares or maybe other things, but we have to be specific as to what kind of a shape we have Shapes exist in some two-dimensional space Shapes can be colored We want to compute areas and perimeters   Writing just one class for all shapes would cause the code to be very messy and cause headaches when we have to add new kinds of shapes.   If we write completely separate classes for circles and squares, then how can we take advantage of similarities? For example methods getColor() and setColor() should be the same for all shapes.   Consider Point class having x-coordinate and y-coordinate values for Square (upper left location) and Circle (center location) classes.   Square class will need “length” and Circle class will need “radius” to calculate area

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 3PE: Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the...
icon
Related questions
Question
100%

Use object oriented programming to solve this:

 

Inheritance/Polymorphism                              

Suppose we want to write an application that manages shapes that has these requirements

 

  • Shapes can be circles or squares or maybe other things, but we have to be specific as to what kind of a shape we have
  • Shapes exist in some two-dimensional space
  • Shapes can be colored
  • We want to compute areas and perimeters

 

Writing just one class for all shapes would cause the code to be very messy and cause headaches when we have to add new kinds of shapes.

 

If we write completely separate classes for circles and squares, then how can we take advantage of similarities? For example methods getColor() and setColor() should be the same for all shapes.

 

Consider Point class having x-coordinate and y-coordinate values for Square (upper left location) and Circle (center location) classes.

 

Square class will need “length” and Circle class will need “radius” to calculate area

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 8 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,