IN THE FORM OF PROCEDURAL PROGRAMMING;
CREATE A PROGRAM THAT COMPUTES THE AREA OF A GIVEN RECTANGLE AND A CIRCLE.
AREA OF RECTANGLE = LENGTH * WIDTH
AREA OF CIRCLE = 3.1416 * RADIUS 2
1. In procedural programming, create a function named "getArea()" with the following parameters.
a. int length
b. int width
c. int radius
Note. Use the following variable names
2. The function must have 2 main procedures which are:
Solving of the area of the rectangle (Variable name = recta)
Solving for the area of the circle (Variable name = cira)
Note. Printing the answer must be included in the function.
3. In the main() program of the source file, allow user to enter the length of the rectangle (Variable name =rectlength,) , width of the rectangle (variable name =rectwidth, and the radius of the circle (variable name = cirradius)
4. Call "getArea" function using the user input
TEST CASE #1
Length of Rectangle: 7
Width of Rectangle: 5
Radius of Circle: 5
Area of rectangle = 35
Area of rectangle = 78.54
#include <iostream>
#include <cmath>
using namespace std;
void getArea (int length, int width, int radius) {
int recta;
float cira;
recta = length * width;
cira = 3.1416 * pow(radius, 2);
cout << "Area of Rectangle: " << recta << endl;
cout << "Area of Circle: " << cira << endl;
}
int main () {
int rectlength, rectwidth, cirradius;
cout << "Legth of rectangle: ";
cin >> rectlength;
cout << "Width of Rectangle: ";
cin >> rectwidth;
cout << "Radius of Circle: ";
cin >> cirradius;
getArea(rectlength, rectwidth, cirradius);
return 0;
}
Comments
Leave a comment