Create a class named GeometricShape containing Two data fields shapeType (a string) area (of type double)
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a class named GeometricShape containing
Two data fields
shapeType (a string)
area (of type double)
A no-argument constructor to initialize all data fields with default values “NoShape” and 0.0. A member function named show() to display the details associated with an instance of this class . Derive a class named Rectangle from class GeometricShape that includes Data members:
Length(int)
Width(int)
Respective mutater and accessor functions to set and get values of length and width, and function named computeArea() to compute the area of rectangle (length x width) and function named show() to display the details associated with an instance of class Rectangle and also its shape type attribute from parent class .From the Rectangle class, derive a class named Cuboid that contains A data field named height in addition to length and width. A three arguments constructor to initialize the values (use super key word for length and width).Two functions named setHeight() and getHeight() to set and get value of height data field, and function named computeArea() to calculate the area of a cuboid (length x width x height) And function named show() to display the details associated with an instance of class Cuboid and also shape type attribute from Shape class.
Implement these classes and in the main class with main method create instances of each class first set the values through setter function or constructors (take input from user).and then call the computeArea() and show() methods of Rectangle and Cuboid class through there instances.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images