Lab 1

Output Requirements

Output the radius, diameter, circumference, and area of a circle. Each value is to be displayed on a separate line and labeled and formatted as illustrated below.

Sample Run

Input Requirements

Ask the user to enter the value of the radius.

Process Requirements

Calculate the diameter (2r), the circumference (2πr), and the area (πr2) of the corresponding circle. You may assume that the user will enter a numeric value.

Miscellaneous Requirements


Your program should display the instructions for using the program as illustrated in the sample run shown above.

Store π as a Constant

Define π as a named double constant (PI) with a value of 3.14159265358979.

Output Format

The numeric output is to be displayed in a fixed point format to 5 decimal places.

Error Handling

As long as the user enters  a negative value or zero for the radius, display an appropriate error message and prompt the user to enter another value. You are to implement this error-handling using the try/catch structure. I suggest you model your program after the try/catch code we looked at in class. The try clause should contain most of your program code (everything except for the code for displaying the instructions and the return statement). If the user enters a radius that is not positive, your program should throw the value of the radius.

In the example code, the catch clause was written to catch anything. In your program, the catch clause should catch a double value (e.g., "catch (double val)") and display an appropriate message based on whether the value that is caught is negative or zero. As in the example code, the try/catch structure should be within a looping structure so that the user has a chance to re-enter the value of the radius.

If you get stuck, the try/catch structure is covered in chapter 15 of our text which includes several example programs.

File Submission

Name your program file "Lab01.cpp" and submit it to me as an email attachment.