In this lab you will practice prompting the user for a value, reading the value as a double from the user/keyboard into a variable, using arithmetic expressions to calculate a value, and formatting the output using manipulators. Be sure to read this lab thoroughly, especially the Hand-in Procedure.
Write a complete program that:
Creates a global constant to hold pi (π = 3.141592).
Prompts the user to enter a radius and reads in a radius from the keyboard as a double.
Calculates the circumference of a circle.
Calculates the area of a circle.
Writes the answers from (3) and (4) out to the display using <iomanip>
. See the example output for formatting.
The equation for circumference of a circle is:
The equation for area of a circle is:
See the example output for examples and formatting. Output values should be fixed with 2 digits of precision. You will need to use <iomanip>
to match the output.
An example of an interaction with your program is shown below, your output should match these examples exactly.
Alexs-iMac:lab2b alex$ ./a.out Enter the radius of a circle **35.2458 +--------+---------------+---------+ | radius | circumference | area | +--------+---------------+---------+ | 35.25 | 221.46 | 3902.69 | +--------+---------------+---------+
See CodeGrade for more examples.
Note: The line breaks after the inputs in the example output formatting above are the default ones C++’s cin
and getline()
automatically apply after reading an input from the user. CodeGrade supplies input in a different manner (Linux redirection) to programs so in CodeGrade's auto tests there will not be line breaks after the inputs.
main.cpp
. Do not ignore this step or save your file(s) with different names..cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.