Question: 1 / / Lab 9 - 1 . cpp circle calculations 2 / / Created / revised by on 3 4 #include 5 #include 6

1//Lab9-1.cpp circle calculations 2//Created/revised by on 34 #include 5 #include 6 using namespace std; 78//function prototypes 9 double getArea(double rad);10 double getDiameter(double rad);1112 int main()13{14 int choice =0;15 double radius =0.0;1617 cout <<"1 Circle area" << endl;18 cout <<"2 Circle diameter" << endl;19 cout << "Enter your choice (1 or 2): ";20 cin >> choice;2122 if (choice <1|| choice >2)23 cout << "Invalid choice" << endl;24 else25{26 cout << "Radius: ";27 cin >> radius;28 if (choice ==1)29 cout << "Area: "<< getArea(radius);30 else31 cout << "Diameter: "<< getDiameter(radius);32//end if33 cout << endl;34}//end if35 return 0;36}//end of main function3738//*****function definitions*****39 double getArea(double rad)40{41 const double PI =3.141593;42 double area =0.0;43 area = PI * pow(rad,2);44 return area;45}//end getArea function4647 double getDiameter(double rad)48{49 return 2* rad;50}//end getDiameter functionFigure 9-26 Code for Lab 9-1QUeStIONS1. Why are the statements on Lines 9 and 10 necessary?2. How else could you write the statement on Line 9?3. If the program does not include the outer selection structure, what will the program display if the user enters the numbers 3 and 10 as the choice and radius, respectively?4. What are the scope and lifetime of the choice and radius variables?5. What are the scope and lifetime of the rad variable used in the getArea function? 6. What are the scope and lifetime of the PI constant and the area variable?7. What scope and lifetime of the rad varible used in to get the diameter 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!