Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to display the area of a rectangle after accepting its length an

ID: 3617330 • Letter: W

Question

 Write a program to display the area of a rectangle after accepting its 
length and width from the user by means of the following functions:
getLength -- ask user to enter the length and return it as double
getWidth -- ask user to enter the width and return it as double
getArea -- pass width and length, compute area and return area
displayArea -- pass area and display it in this function.


Expected Output:

Enter the length: 29
Enter the width: 34
Rectangle Data
--------------
Length: 29
Width: 34
Area: 986

Enter the length: 5.98
Enter the width: 29.345
Rectangle Data
--------------
Length: 5.98
Width: 29.345
Area: 175.483


Explanation / Answer


#include<iostream.h> #include<conio.h> class Rectangle { private: double length; double width; public: Rectangle(double lnt, double wdt) { length=lnt; width=wdt; } double getLength() { return length; }
double getWidth() { return width; } double getArea() { double area; area=getLength()*getWidth(); return area; } } main() { double l,w; cout<<"Enter the Length: "; cin>>l; cout<<" Enter the Width: "; cin>>w;
Rectangle r(l,w); cout<<" Length: "<<r.getLength(); cout<<" Width: "<<r.getWidth(); cout<<" Area: "<<r.getArea(); getch(); }
#include<iostream.h> #include<conio.h> class Rectangle { private: double length; double width; public: Rectangle(double lnt, double wdt) { length=lnt; width=wdt; } double getLength() { return length; }
double getWidth() { return width; } double getArea() { double area; area=getLength()*getWidth(); return area; } } main() { double l,w; cout<<"Enter the Length: "; cin>>l; cout<<" Enter the Width: "; cin>>w;
Rectangle r(l,w); cout<<" Length: "<<r.getLength(); cout<<" Width: "<<r.getWidth(); cout<<" Area: "<<r.getArea(); getch(); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote