Question: // SIMPLE AREA CALCULATOR v1.0 #include #include #include using namespace std; // display the area calculator menu // Simple Area Calculator Menu // ----------------------------------- //

// SIMPLE AREA CALCULATOR v1.0

#include #include #include using namespace std;

// display the area calculator menu

// Simple Area Calculator Menu

// -----------------------------------

// 1. Calculate the area of a circle

// 2. Calculate the area of a rectangle: now under development

// 3. Quit to exit the program void display_menu();

// function get_choice reads, validates and returns // the user's choice int get_menu_choice();

// function circle returns the area of a circle with radius r double circle(double r);

// function is_positive returns false if k is strictly negative and true otherwise bool is_positive(double k);

int main() {

int choice; do {

display_menu(); choice = get_menu_choice(); double area = 0; // holds the area of a geometry shape cout << fixed << showpoint << setprecision(5); switch (choice) {

case 1: double radius; // radius of a circle cout << "Enter radius of circle: "; cin >> radius; while (!is_positive(radius))

{ cout << "Enter a non-negative radius: "; cin >> radius;

} area = circle(radius); cout << "Area of circle is: " << area << endl; break;

case 2: cout << "This section is under development" << endl; cout << "by CS 117 students..." << endl; break;

default:break; }

} while (choice != 3);

cout << "Good bye...now. "<< endl;

return 0; }

void display_menu() {

cout << endl; cout << "Simple Surface Area Claculator Menu" << endl; cout << "-----------------------------------" << endl; cout << " 1. Calculate the area of a circle" << endl; cout << " 2. Calculate the area of a rectangle: now under development" << endl; cout << " 3. Quit to exit the program" << endl; cout << endl;

}

int get_menu_choice() {

int choice; cout << "Enter your selection (1, 2, or 3): "; cin >> choice; while(((choice < 1) || (choice > 3)) && (!cin.fail())) {

cout << "Try again (1, 2, or 3): ";

cin >> choice; }

if (cin.fail()) {

cout << "Error: exiting now ... " << endl;

exit(1); }

return choice; }

double circle(double r) {

const double pi = 3.14159; double area = pi * r * r; return (area);

}

bool is_positive(double k) {

if (k < 0) return false;

return true; }

Question 1 Write the function prototype and function definition of function rectangle which takes the length and width of a rectangle and returns the area of the rectangle. Limit your answer to providing a function prototype and its code.

Question 2 Review and revise the implementation of the functions display_menu to reflect the actual simple area calculator v2.0 menu. Limit your answer to providing the revised code for this function.

Question 3 Revise the main program which should ask the user for the length and width of a rectangle, compute and display the area of the rectangle. Do not accept negative values for the rectangles length or width when this new feature is added. Limit your answer to providing the sections that require revisions in your program.

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!