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

C++ Programming Add 4 new Functions to this Project: 1. calcAreaCircle() 2. calc

ID: 3678491 • Letter: C

Question

C++ Programming

Add 4 new Functions to this Project:

1. calcAreaCircle()

2. calcAreaSquare()

3. calAreaRectangle()

4.. calAreaTriangle()

Each of these functions will process an Area calculation:

(i.e. for a Circle, your function would do the following 4 steps:

1. prompt the User for to enter a radius.

2. Read in the radius,

3. calculate the area by using the formula a=pi*Radius squared.     

4. Then print out the area of the circle. )

Lastly, modify the switch statement in the main function. Your main function will no longer do all the work to process the area calculations. Your main() function will call the 4 new functions that you just built. If the uses enters a ‘C’, call the function “calcAreaCircle()” to process the calculation of the area of a circle. Do the same for the other 3 figures.

__________________________________________________________________

#include
using namespace std;
int main()
{
char ch;
float radius = 0.0, side = 0.0, width =0.0, length = 0.0, base =0.0, height = 0.0;
float pi = 3.14159;
double area = 0.0;
while(ch !='X' || ch !='x')
{
cout << " ************* MENU ***************" << endl;
cout << " R. Rectangle C. Circle T. Trianle S. Square X. Exit Enter a letter to find area ";
cin>>ch;
switch(ch)
{
case 'C':
cout<<"Enter Radius: "< cin>>radius;
area = pi * radius * radius;
cout<<"Circle Area is : "< area = 0.0;
break;
case 'c':
cout<<"Enter Radius: "< cin>>radius;
area = pi * radius * radius;
cout<<"Circle Area is : "< area = 0.0;
break;
case 'S':
cout<<"Enter side: "< cin>>side;
area = side * side ;
cout<<"Square Area is : "< area = 0.0;
break;
case 's':
cout<<"Enter side: "< cin>>side;
area = side * side;
cout<<"Square Area is : "< area = 0.0;
break;
case 'R':
cout<<"Enter Width : "< cin>>width;
cout<<"Enter length : "< cin>>length;
area = width * length;
cout<<"Rectangle Area is : "< area = 0.0;
break;
case 'r':
cout<<"Enter Width : "< cin>>width;
cout<<"Enter length : "< cin>>length;
area = width * length;
cout<<"Rectangle Area is : "< area = 0.0;
break;
case 'T':
cout<<"Enter Base : "< cin>>base;
cout<<"Enter Height : "< cin>>height;
area = (base * height)/2;
cout<<"Triangle Area is : "< area = 0.0;
break;
case 't':
cout<<"Enter Base : "< cin>>base;
cout<<"Enter Height : "< cin>>height;
area = (base * height)/2;
cout<<"Triangle Area is : "< area = 0.0;
break;
case 'X':
exit(0);
case 'x':
exit(0);
}
}
return 0;
}

Explanation / Answer

#include<iostream.h>
#include<conio.h>

using namespace std;
void cir()
{
   cout<<"Enter Radius: "< cin>>radius;
   area = pi * radius * radius;
   cout<<"Circle Area is : "< area = 0.0;
}

void sq()
{
   cout<<"Enter side: "< cin>>side;
   area = side * side ;
   cout<<"Square Area is : "< area = 0.0;
}

void rect()
{
   cout<<"Enter Width : "< cin>>width;
   cout<<"Enter length : "< cin>>length;
   area = width * length;
   cout<<"Rectangle Area is : "< area = 0.0;
}

void tri()
{
   cout<<"Enter Base : "< cin>>base;
   cout<<"Enter Height : "< cin>>height;
   area = (base * height)/2;
   cout<<"Triangle Area is : "< area = 0.0;
}

int main()
{
   char ch;
   float radius = 0.0, side = 0.0, width =0.0, length = 0.0, base =0.0, height = 0.0;
   float pi = 3.14159;
   double area = 0.0;
   while(ch !='X' || ch !='x')
   {
       cout << " ************* MENU ***************" << endl;
       cout << " R. Rectangle C. Circle T. Trianle S. Square X. Exit Enter a letter to find area ";
       cin>>ch;
       switch(ch)
       {
           case 'C':
               cir();
               break;
           case 'c':
               cir();
               break;
           case 'S':
               sq();              
               break;
           case 's':
               sq();
               break;
           case 'R':
               rect();
               break;
           case 'r':
               rect();
               break;
           case 'T':
               tri();
               break;
           case 't':
               tri();
               break;
           case 'X':
               exit(0);
           case 'x':
               exit(0);
       }
   }
   return 0;
}

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