Question: / / Lab 1 0 - 1 . cpp - circle calculations / / Created / revised by on #include #include using namespace std; /

//Lab10-1.cpp - circle calculations
//Created/revised by on
#include
#include
using namespace std;
//function prototypes
void displayChoices();
void getArea(double rad, double &area);
void getDiameter(double rad, double &diameter);
int main()
{
int choice =0;
double radius =0.0;
double circleArea =0.0;
double circleDiameter =0.0;
displayChoices();
cout << "Enter your choice (1 or 2): ";
cin >> choice;
if (choice <1|| choice >2)
cout << "Invalid choice" << endl;
else
{
cout << "Radius: ";
cin >> radius;
if (choice ==1)
{
getArea(radius, circleArea);
cout << "Area: "<< circleArea;
}
else
{
getDiameter(radius, circleDiameter);
cout << "Diameter: "<< circleDiameter;
}//end if
cout << endl;
}//end if
return 0;
}//end of main function
//*****function definitions*****
void displayChoices()
{
cout <<"1 Circle area" << endl;
cout <<"2 Circle diameter" << endl;
}//end displayChoices
void getArea(double rad, double &area)
{
const double PI =3.141593;
area = PI * pow(rad,2);
}//end getArea function
void getDiameter(double rad, double &diameter)
{
diameter =2* rad;
}//end getDiameter function
QUeStIoNS1. The main function passes two variables to the getArea function. Which lines in the program indicate whether the variables are passed by value or by reference?
2. Why is the radius variable passed by value? Why are the circleArea and circleDiameter variables passed by reference?
3. Why is the displayChoices function a void function?
4. How do the getArea and getDiameter functions, which are void functions, send information back to the main function?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!