Question: #include #include using namespace std; // This program will demonstrate the scope rules. // PLACE YOUR NAME HERE const double PI = 3.14; const double
#include #include using namespace std; // This program will demonstrate the scope rules. // PLACE YOUR NAME HERE const double PI = 3.14; const double RATE = 0.25; void findArea(float, float&); void findCircumference(float, float&); int main() { continues
102 LESSON SET 6.2 Functions that Return a Value cout << fixed << showpoint << setprecision(2); float radius = 12; cout <<" Main function outer block" << endl; cout <<" LIST THE IDENTIFIERS THAT are active here" << endl << endl; { float area; cout << "Main function first inner block" << endl; cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl; // Fill in the code to call findArea here cout << "The radius = " << radius << endl; cout << "The area = " << area << endl << endl; } { float radius = 10; float circumference; cout << "Main function second inner block" << endl; cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl; // Fill in the code to call findCircumference here cout << "The radius = " << radius << endl; cout << "The circumference = " << circumference << endl << endl; } cout << "Main function after all the calls" << endl; cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl; return 0; } // ********************************************************************* // findArea // // task: This function finds the area of a circle given its radius // data in: radius of a circle // data out: answer (which alters the corresponding actual parameter) // // ******************************************************************** void findArea(float rad, float& answer) { cout << "AREA FUNCTION" << endl << endl; cout << "LIST THE IDENTIFIERS THAT are active here"<< endl << endl;
Lesson 6.2A 103 // FILL in the code, given that parameter rad contains the radius, that // will find the area to be stored in answer } // ****************************************************************************** // findCircumference // // task: This function finds the circumference of a circle given its radius // data in: radius of a circle // data out: distance (which alters the corresponding actual parameter) // // ***************************************************************************** void findCircumference(float length, float& distance) { cout << "CIRCUMFERENCE FUNCTION" << endl << endl; cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl; // FILL in the code, given that parameter length contains the radius, // that will find the circumference to be stored in distance } Exercise 1: Fill in the following chart by listing the identifiers (function names, variables, constants)
| Global | main | main (inner 1)
| main (inner 2) | Area | circumference |
Exercise 2: For each cout instruction that reads: cout << " LIST THE IDENTIFIERS THAT are active here" << endl; Replace the words in all caps by a list of all identifiers active at that location. Change it to have the following form: cout << "area, radius and PI are active here" << endl; Exercise 3: For each comment in bold, place the proper code to do what it says. NOTE: area = r2 circumference = 2r
104 LESSON SET 6.2 Functions that Return a Value Exercise 4: Before compiling and running the program, write out what you expect the output to be. What value for radius will be passed by main (first inner block) to the findArea function? What value for radius will be passed by main function (second inner block) to the findCircumference function? Exercise 5: Compile and run your program. Your instructor may ask to see the program run or obtain a hard copy.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
