Problem Constant
PI 3.14159
Problem Input
radius /* radius of a circle */
Problem Outputs
area /* area of a circle */
circum /* circumference of a circle */
Relevant Formulas
area of a circle = * radius2
circumference of a circle = 2 * radius
DESIGN
After identifying the problem inputs and outputs, list the steps necessary to solve
the problem. Pay close attention to the order of the steps.
INITIAL ALGORITHM
1. Get the circle radius.
2. Calculate the area.
3. Calculate the circumference.
4. Display the area and the circumference.
ALGORITHM REFINEMENTS
Next refine any steps that do not have an obvious solution (steps 2 and 3).
Step 2 Refinement
2.1 Assign PI * radius * radius to area.
Step 3 Refinement
3.1 Assign 2 * PI * radius to circum.
PROGRAM
#include <iostream>
using namespace std;
int main(){
const float PI = 3.14159;
float radius; //input: radius of cicle
float area; //output: area of circle
float circum; //output: circumferense of circle
//get the circle radius.
cout<<"Enter the circle radius : ";
cin>>radius;
//compute area of circle
area=PI*radius*radius;
//compute circumference of circle
circum=2*PI*radius;
//display area and circumference
cout<<"the area of the circle is " <<area<<endl;
cout<<"the circumference of the circle is "<<circum<<endl;
return 0;
}