Area Calculator: Write a program to calculate the area of some simple geometric
ID: 3845432 • Letter: A
Question
Area Calculator: Write a program to calculate the area of some simple geometric shapes. The shapes required to be included are rectangles, circles, and right triangles. Because we have not covered conditional code yet, we will calculate all the shapes in order. Your program must: Ask the user for the values necessary to compute the area of each shape o Rectangle o Circle You must use an accurate value of pi (3.14159265359) o Right Triangle o The input must accept non-whole numbers Display the results to the user You do not need to attempt to make the program correct for improper input (e.g. negative numbers or non-numbers)
Explanation / Answer
PROGRAM CODE:
#include <iostream>
using namespace std;
#define pi 3.14159265359
void rectangleArea(double l, double w)
{
cout<<" Area of the rectangle is "<<l*w<<endl;
}
void circleArea(double r)
{
cout<<" Area of the circle is "<<(pi*r*r)<<endl;
}
void rightTriangleArea(double h, double b)
{
cout<<" Area of the right triangle is "<<h*b/2<<endl;
}
int main() {
double length, width, radius;
cout<<"Calculating area for rectangle..."<<endl;
cout<<"Enter length: ";
cin>>length;
cout<<" Enter width: ";
cin>>width;
rectangleArea(length, width);
cout<<" Calculating area for circle..."<<endl;
cout<<"Enter radius: ";
cin>>radius;
circleArea(radius);
cout<<" Calculating area for right triangle..."<<endl;
cout<<"Enter base: ";
cin>>width;
cout<<" Enter height: ";
cin>>length;
rightTriangleArea(length, width);
return 0;
}
OUTPUT:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.