Question
In C++ modify this Circle Struct into a Circle Class, additionally add a try/catch contruct Copied code: #include #include #include // For the pow function
In C++ modify this Circle Struct into a Circle Class, additionally add a "try/catch" contruct
Copied code:
#include
// Constant for pi. const double PI = 3.14159;
// Structure declaration struct Circle { double radius; double diameter; double area; }; // Function prototype Circle getInfo();
int main() { Circle c; // Get data about the circle. c = getInfo(); // Calulate the circle's area. c.area = PI * pow(c.radius, 2.0); //Display the circle data. cout
//*************************************************************** // Definition of function getInfo. This function uses a local * // variable, tempCircle, which is a circle structure. The user * // enters the diameter of the circle, which is stored in * // tempCircle.diameter. The function then calculates the radius * // which is stored in tempCircle.radius. tempCircle is then * // returned from the function. * //***************************************************************
Circle getInfo() { Circle tempCircle; // Temporary structure variable // Store circle data in the temporary variable. cout > tempCircle.diameter; tempCircle.radius = tempCircle.diameter / 2.0; // Return the temporary variable. return tempCircle; }
#includeStep 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