Question
Write code in c++ that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two
Write code in c++ that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two data items. The first is a characterD (for diameter), C (for circumference), or A (for area)to indicate the calculation needed. The next data value is a floating-point number indicating the radius of the particular circle. The program should print the input data. The output should be labeled appropriately. For example, if the input is: A 6.75 your program should print something like this: The area of a circle with radius 6.75 is 143.14. Here are the formulas you need: Diameter = 2r, Circumference = 2r, Area of a circle = r2 where r is the radius. Use 3.14159265 for . Modify your program to perform input validation by making sure that the first character is A or C or D and the value of the radius is greater than zero. An appropriate error message should be printed if invalid data was entered.
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