Use the c++ programming language to write a computer program that implement and uses the following two user-defined functions:
i. getcircumference, which promps and accepts the value of a radius r its user, and then computes and returns the circumference for the circle.
ii. getArea, which accepts the value of a circle's circumference in it's parameters, and then computes and return the area of a circle
Your computer program just correctly use the functions to obtain the circumference and area of a circle, and then output the results.
Note: area of a circle = πr2
Circumference = 2πr
#include <iostream>
using namespace std;
const float PI = 3.14159265359;
float getCircumference(){
cout<<"Input the radius: ";
float r; cin>>r;
return 2 * PI * r;
}
float getArea(float circumference){
float r = circumference / (2 * PI);
return PI * r * r;
}
int main(){
float circumference = getCircumference();
cout<<"The circumference is "<<circumference<<endl;
cout<<"The area is "<<getArea(circumference);
return 0;
}
Comments
Leave a comment