Question
// Program Id: CircleCalculator.cpp Starting File // Author: // Date: // Description: // This program demonstrates using a C++ Structure called Circle. // Using various
// Program Id: CircleCalculator.cpp Starting File
// Author:
// Date:
// Description:
// This program demonstrates using a C++ Structure called Circle.
// Using various functions, it prompts the user for a radius and
// calculates and displays the diameter, area, and circumference.
#include
#include
#include
using namespace std;
struct Circle // Declare what a Circle structure looks like
{
double radius;
double diameter;
double area;
double circumference;
//default constructor
Circle()
{
radius = 0;
diameter = 0;
area = 0;
circumference = 0;
}
};
//Function prototypes
Circle getCircleData();
void calculateCircleData(Circle &cc);
void displayCircleData(Circle cc);
const double PI = 3.14159; //can use in main and functions
int main()
{
int cNumber = 1;
cout << "Welcome to our Circle Calculator" << endl;
cout << "--------------------------------" << endl << endl;
Circle c; // Define a Circle structure variable
cout << "Circle # " << cNumber << endl << endl; //display the circle number
c = getCircleData();
calculateCircleData(c);
displayCircleData(c);
cout << " Goodbye!" << endl;
return 0;
}
//complete the implementation of the following functions
Circle getCircleData()
{
//This function prompts the user for a Circle's radius.
//Accept only values greater than 0 for the radius.
//This function returns a Circle structure variable.
Circle cTemp; //define a local Circle variable
/***Your code goes here***/
return cTemp;
}
void calculateCircleData(Circle &cc)
{
//This function takes the Circle reference argument &cc
//and calculates the rest of the members:
//diameter, circumference, and area.
/***Your code goes here***/
}
void displayCircleData(Circle cc)
{
// This function takes the Circle argument cc and displays
// all of its members using cout. Displays the radius, area, and
// circumference, all with 2 decimal places.
/***Your code goes here***/
}
/* Your code must generate the following output.
Welcome to our Circle Calculator
--------------------------------
Circle # 1
Enter the radius of the circle (number greater than 0): 3
The circle data is
Radius: 3.00
Diameter: 6.00
Circumference: 18.85
Area: 28.27
Do you want to try again? (Y or N) y
Circle # 2
Enter the radius of the circle (number greater than 0): 0
Radius must be a number greater than 0. Please re-enter radius: 4.5
The circle data is
Radius: 4.50
Diameter: 9.00
Circumference: 28.27
Area: 63.62
Do you want to try again? (Y or N) y
Circle # 3
Enter the radius of the circle (number greater than 0): -2
Radius must be a number greater than 0. Please re-enter radius: 32
The circle data is
Radius: 32.00
Diameter: 64.00
Circumference: 201.06
Area: 3216.99
Do you want to try again? (Y or N) n
Goodbye!
Press any key to continue . . .
*/
*******************************************************************************************
Complete the implementation of the following functions. There are stubs in the starting file.
1. Prototype: Circle getCircleData(); This function prompts for a radius only. Accept only values greater than 0. It returns a Circle structure variable.
2. Prototype: void calculateCircleData(Circle &cc); This function takes the Circle reference argument and calculates the rest of the attributes; diameter, circumference, and area.
3. Prototype: void displayCircleData(Circle cc); This function takes the Circle argument and displays all of the attributes. Displays the radius, diameter, area and circumference, all with 2 decimal places. Output formatting and layout must resemble the example output.
[3] Add a loop to allow users to get as many circles as wanted until the user indicates otherwise
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started