Write a program to ask theuser to enter the width and length of a rectangle, and
ID: 3614717 • Letter: W
Question
Write a program to ask theuser to enter the width and length of a rectangle, and displaythe
rectangle’s area.The main function in this program should call the followingfunctions:
getLength – thisfunction should ask the user to enter the rectangle’s length,and then return
that values as adouble.
getWidth – thisfunction should ask the user to enter the rectangle’s width,and then return
that values as adouble.
getArea – thisfunction should accept the rectangle’s length and width asarguments, and then
return therectangle’s area. The area is calculated by multiplying thelength by width.
displayData – thisfunction should accept the rectangle’s length, width, andarea as
arguments, and then display them in anappropriate message on the screen.
Explanation / Answer
//Hope this will helpyou. #include<iostream>using namespace std;
double getLength(){
double d;
cout<<"Enterlength:";
cin>>d;
return d;
}
double getWidth(){
double d;
cout<<"EnterWidth:";
cin>>d;
return d;
}
double getArea(double l,double w)
{
return l*w;
}
void displayData(double l,double w,double a)
{
cout<<"Area of rectangle withlen="<<l<<" & width = "<<w<<" is"<<a<<endl;
}
int main()
{
double l,w,a;
l=getLength();
w=getWidth();
a=getArea(l,w);
displayData(l,w,a);
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.