In: Computer Science
C++ Question:
write a program that prompts the user for the length and width of a rectangle in inches. The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively.
Sample output
from one instance of the program is shown below:
```html
Welcome to the Foot-To-Meter Rectangle Calculator
=================================================
Enter the rectangle length in feet: 2
Enter the rectangle width in feet: 3
The rectangle dimensions are: 0.61 meters by 0.91 meters.
The rectangle perimeter is: 3.05 meters.
The rectangle area is: 0.56 square meters.
Your solution to this problem must meet the following criteria.
1. You must prototype and define three functions.
Examples of the function prototypes are shown below.
Within the `feetToMeters` function, declare a constant
with value 0.3048 (the number of meters in a foot) to assist with the conversion.
```c++
// return the perimeter of a rectangle with a given length (1st parameter)
// and width (2nd parameter)
float perimeter(float, float);
// return the area of a rectangle with a given length (1st parameter)
// and width (2nd parameter)
float area(float, float);
// return the number of meters of a given dimension (2nd parameter) that
// corresponds to a number of feet (1st parameter) of the same dimension
// (dimension 1 = linear, 2 = square, 3 = cubic, etc.)
float feetToMeters(float,short);
// Program to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively by using functions.
#include <iostream>
#include <cmath>
using namespace std;
float mtrlength,mtrbreadth;
float feetToMeters(float l,float b)
{
//float
mtrlength=l*0.3048;
mtrbreadth=b*0.3048;
cout<<"the rectangle dimensions are"
<<mtrlength<<"meter"<<mtrbreadth<<"meter";
//return mtrbreadth;
}
float perimeter(float mtrlength,float mtrbreadth)
{
float p=2*(mtrlength+mtrbreadth);
return p;
}
double area(float mtrlength,float mtrbreadth)
{
double a=mtrlength*mtrbreadth;
return a;
}
int main()
{
float length,breadth;
cout<<"Enter the rectangle length in feet";
cin>>length;
cout<<"Enter the rectangle width in feet";
cin>>breadth;
float finallength=feetToMeters(length,breadth);
float peri=perimeter(mtrlength,mtrbreadth);
cout<<"\nthe rectangle perimeter is"<< peri;
double are=area(mtrlength,mtrbreadth);
cout<<"\nthe rectangle area is"<< are;
return 0;
}
Screen Shot:
Another Example: