Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to calculate the area of several basic geometric shapes. The pro

ID: 3629476 • Letter: W

Question

Write a program to calculate the area of several basic geometric shapes. The program first asks the user for a shape ( C = Circle, R = Rectangle, S = Square, and T = Triangle). The program then calls one of four user-defined functions to calculate the area of the shape and return the answer to the main for printing to the screen. Depending on the shape, the corresponding function's argument(s) is (are) the necessary parameter(s) for area calculation. Therefore, the main should receive the value(s) of the parameter(s) from the user before calling any function. You must test your program for all shapes. The program should reject request for any other shapes: this option must be tested as well. The following is a list of parameters for each shape and the expression for its area calculation:

Explanation / Answer

please rate - thanks

#include<iostream>
#include <string.h>
#include <math.h>
using namespace std;
double rectangle();
double circle();
   double triangle();
   double square();
double get(string);
int main()
{
double area=0;
char input;
do
{
cout<<"Enter a shape: ";
cout<<"Circle (C) Square (S) Rectangle (R) Triangle (T) exit(E): ";
cin>>input;
switch(input)
   {case 'c':case 'C':
                area=circle();
                break;
    case 's':case 'S':
                area=square();
                break;
    case 'r':case 'R':
                area=rectangle();
                break;
    case 't':case 'T':
                area=triangle();
                break;
     case 'e':case 'E':
              return 0;
    default:
            cout<<"invalid entry ";
    }
cout<<" Area="<<area<<" ";
}while(true);
}

double square()
{double a=get("length");
return a*a;
}
double rectangle()
{double a=get("length");
double b=get("width");
return a*b;
}
double triangle()
{double a=get("side A");
double b=get("side B");
double c=get("side C");
double s=(a+b+c)/2.;
return sqrt(s*(s-a)*(s-b)*(s-c));
}

double circle()
{double a=get("radius");
return a*a*3.14159;
}
double get(string mess)
{double a;
do
{cout<<"Enter a value for "<<mess+": ";
   cin>>a;
    if(a<=0)
    cout<<"Invalid entry- redo";
    }while(a<=0);
    return a;
    }           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote