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

This is my assignment. Most of the code is already written I just need to do a f

ID: 3758309 • Letter: T

Question

This is my assignment. Most of the code is already written I just need to do a few steps. Help?

// Add the following functions:

// 1. 'getRadius' asks the user to enter the radius of a circle
//     and returns the given value. (should return a double)

// 2. 'calcArea' takes the radius and returns the area of a circle.

// 3. 'printResults' void type function that should print the results to
//    console.

// Your function needs to have a local variable called 'PI' which holds the
// value '3.14159'.

// I have provided the function call, you just need to implement the
// function prototype and function definition.

#include <iostream>
using namespace std;

// TODO - write the prototypes here


int main()
{
    double radius,
           area;
    float PI;


    // TODO - call 'getRadius' function and assign the
   //        returned value to radius.


    area = calc_area(radius);

   // TODO - move the following cout to the 'printResults' function
   //        and call that function here instead.

    cout << "The area of your circle is " << area << " units squared."
             << endl;

    return 0;
}

// TODO - write the functions here

Explanation / Answer

#include <iostream>
using namespace std;
// TODO - write the prototypes here
double getRadius();
double calcArea(double rad);
void printResults(double area);
  
int main()
{
double radius,area;
  
// TODO - call 'getRadius' function and assign the
// returned value to radius.
radius = getRadius();
area = calcArea(radius);
// TODO - move the following cout to the 'printResults' function
// and call that function here instead.
printResults(area);
return 0;
}
// TODO - write the functions here
double getRadius(){
// 1. 'getRadius' asks the user to enter the radius of a circle
// and returns the given value. (should return a double)
double rad;
cout<<"Please enter the radius of circle : ";
cin>>rad;
return rad;
}

double calcArea(double rad){
const float PI = 3.14159;
// 2. 'calcArea' takes the radius and returns the area of a circle.
return PI*rad*rad;
}

void printResults(double area){
// 3. 'printResults' void type function that should print the results to
// console.
cout << "The area of your circle is " << area << " units squared." << endl;
}

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