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
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 << "\tR. Rectangle \tC. Circle \tT. Trianle \tS. Square \tX. 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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started