+1 (315) 557-6473 

C++ Program to Create Area Calculation System Assignment Solution.


Instructions

Objective
Write a program to create area calculation system in C++.

Requirements and Specifications

Assignment 3
Write a C++ homework application (including algorithm) that uses a “void” function, “CalculateArea”, to calculate the area of a circle. The function uses two formal parameters (i.e., “radius” [pass by value] and “area” [pass by reference]). The function calculates the area using the formula (i.e., PI * radius2).
The application requires a sentinel controlled loop where program prompts for continuing and expects an entry of ‘Y’ or ‘y’ using the variable “cont”. Within the loop, the application provides for allowing the user to enter the radius of the circle, calls the “CalculateArea” function and displays the value of the circle’s area.
Upload to the Canvas “Assignment 3 Submission” area.
Note: Keep in mind the 3 requirements for functions
  • Function Declaration
  • Function Definition
  • Function Call
Source Code
#include
#define PI 3.1416
using namespace std;
// Function declaration
void CalculateArea(double radius, double &area);
int main() {
    // Define variable to store user input
    char cont;
    double radius;
    // Create variable to store area
    double area;
    // Begin with loop
    while(true) {
        cout << "Please enter the radius of the circle: ";
        cin >> radius;
        // Calculate
        CalculateArea(radius, area);
        cout << "The area of the circle with a radius of " << radius << " is: " << area << endl;
        // Ask if s/he wants to continue
        cout << "Do you want to calculate a new area? (y/n): ";
        cin >> cont;
        if(cont == 'n' || cont == 'N') {
            break;
        }
    }
}
/**
 * @brief Function to calculate the area of a circle given its radius.
 * The function received two parameters. The area (passed by value) and the area (passed by ref)
 *
 */
void CalculateArea(double radius, double &area) {
    // Calculate area
    area = PI*radius*radius;
}