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; }
#include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
