Write a Rectangle class that has the following fields: Length (L): a double Width (W): a double The class should have the following functions: Constructor: accepts the length (L) and the width (W) of a rectangle as arguments. Constructor: does not take any parameters and initializes the length(L) and width(W) to zero. A function called getArea which returns the area of the rectangle. A function called getPerimeter which returns the perimeter of the rectangle. {note: The area of a rectangle =L*W, and its perimeter = 2*(L+W) } Then, write a program to ask the user to enter the length and width of a rectangle, and then use the above class to calculate and print the area and perimeter of the rectangle.

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 6PE
icon
Related questions
Question
Write a Rectangle class that has the following fields:
Length (L): a double
- Width (W): a double
The class should have the following functions:
Constructor: accepts the length (L) and the width (W) of a rectangle as arguments.
Constructor: does not take any parameters and initializes the length(L) and width(W)
to zero.
- A function called getArea which returns the area of the rectangle.
A function called getPerimeter which returns the perimeter of the rectangle.
{note: The area of a rectangle =L*W, and its perimeter = 2*(L+W) }
Then, write a program to ask the user to enter the length and width of a rectangle, and then
use the above class to calculate and print the area and perimeter of the rectangle.
Transcribed Image Text:Write a Rectangle class that has the following fields: Length (L): a double - Width (W): a double The class should have the following functions: Constructor: accepts the length (L) and the width (W) of a rectangle as arguments. Constructor: does not take any parameters and initializes the length(L) and width(W) to zero. - A function called getArea which returns the area of the rectangle. A function called getPerimeter which returns the perimeter of the rectangle. {note: The area of a rectangle =L*W, and its perimeter = 2*(L+W) } Then, write a program to ask the user to enter the length and width of a rectangle, and then use the above class to calculate and print the area and perimeter of the rectangle.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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