Programming Problem Write a C++ program that calculates and prints the diameter,
ID: 3631376 • Letter: P
Question
Programming ProblemWrite a C++ program 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 character - 'D' (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 echo-print the input data. The output should be
labeled appropriately and formatted to two decimal places. 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 = 2*r
Circumference = 2*pi*r
Area of a circle = pi*r*r
where r is the radius. Use 3.14159265 for pi.
Use meaningful variable names, proper indentation, and appropriate comments.
Use the format and style described in the assignment guidelines.
In order to demonstrate that your program works, you must collect the output of your program.
Use three runs to demonstrate all components of your program work.
Explanation / Answer
please rate - thanks
any problems message me
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{char operation;
double radius,PI=3.14159265;
cout<<"Enter A for area, C for circumference, or D for diameter followed by the radius: ";
cin>>operation;
cin>>radius;
cout<<setprecision(2)<<fixed;
switch(operation)
{case 'A':
case 'a': cout<<"The area of a circle with radius "<<radius<<" is "<<
PI*radius*radius<<endl;
break;
case 'C':
case 'c': cout<<"The circumference of a circle with radius "<<radius<<" is "<<
2*PI*radius<<endl;
break;
case 'D':
case 'd': cout<<"The diameter of a circle with radius "<<radius<<" is "<<
2*radius<<endl;
break;
default: cout<<"Invalid operation entered ";
break;
}
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.