Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago