The area and perimeter of an arbitrary rectangle can be computed using: area=l*w
ID: 3655174 • Letter: T
Question
The area and perimeter of an arbitrary rectangle can be computed using: area=l*w perimeter=2*(l+w) where l and w are the length and width of the rectangle, respectively. You are to write a void function called Compute(float,float,float&,float&) that takes in two values (length and width of a rectangle). The function computes the area and perimeter for the rectangle. This function will share the area and perimeter with the main function via reference. Below is the prototype of the void function. void Compute(float length, float width, float &area;, float &perimeter;); Write also a main() function that ask the user for length and width of a rectangle and then invoke your void function described above. Finally print the area and permiter. Note the user input the data and print the area and perimeter in the main, not in the void function. So your submission should have the main and the subfunction.Explanation / Answer
#include <iostream>
using namespace std;
void Compute( float length, float width, float& perimeter, float& area ) {
perimeter = 2 * ( length + width );
area = length * width;
}
int main( int argc, char** argv ) {
float len, wid, per, a;
cout << "Please enter the length of the rectangle: ";
cin >> len;
cout << "Please enter the width of the rectangle: ";
cin >> wid;
Compute( len, wid, per, a );
cout << endl <<
"The perimeter of the rectangle is: " << per << endl <<
"The area of the rectangle is: " << a << endl;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.