Question

Write a program to display the area of a rectangle after accepting its length and width...

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:

(i)

Enter the length: 29

Enter the width: 34

Rectangle Data

--------------

Length: 29

Width: 34

Area: 986

(ii)

Enter the length: 5.98

Enter the width: 29.345

Rectangle Data

--------------

Length: 5.98

Width: 29.345

Area: 175.483

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <iomanip>

using namespace std;

double getLength();

double getWidth();

double getArea(double l,double w);

void displayArea(double area);

int main()

{

double l,w,area;

l=getLength();

w=getWidth();

area=getArea(l,w);

cout<<"Rectangle Data"<<endl;

cout<<"--------------"<<endl;

cout<<"Length:"<<l<<endl;

cout<<"Width:"<<w<<endl;

displayArea(area);

return 0;

}

double getLength()

{

double len;

cout<<"Enter the length:";

cin>>len;

return len;

}

double getWidth()

{

double width;

cout<<"Enter the width:";

cin>>width;

return width;

}

double getArea(double l,double w)

{

return l*w;

}

void displayArea(double area)

{

cout<<"Area:"<<area<<endl;

}

_______________

Output:

_____________Thank You

Add a comment
Know the answer?
Add Answer to:
Write a program to display the area of a rectangle after accepting its length and width...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use DevC++ to implement a program uses objected oriented programming to calculate the area of a...

    Use DevC++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...

  • Use C++ to implement a program uses objected oriented programming to calculate the area of a...

    Use C++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • I need help with the C++ for the following problem: Write a program uses objected oriented...

    I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...

  • share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00...

    share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...

  • In the code (C++) below, if you input 2 as length and 4 as width, the...

    In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • Hello I have a question. I would like to check if the code follows this requirement....

    Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...

  • C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class...

    C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class    double rectWidth; // Local variable for width    double rectLength; // Local variable for length    string rectColor;    // Get the rectangle's width and length from the user.    cout << "This program will calculate the area of a\n";    cout << "rectangle. What is the width? ";    cin >> rectWidth;    cout << "What is the length? ";    cin >>...

  • Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override...

    Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle {       private double length;    private double width;       public Rectangle(double l, double w)    {        length = l;        width = w;    }       public double getLength()    {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT