Circumference
and area of Circle program in C++
Calculating
the circumference and area of circle in C++ program can easily be done using
the radius. You can say that if you have got the radius, then calculating the
circumference is just simple calculations. We will follow same method, we will
ask the user to enter the radius of circle. The user will enter it and we will
perform the calculation on the simple formula of circumference and area. Let’s
start.
Logic:
We will create
a class name Circle and declare a variable r for taking radius of circle. We
have then created the function In() to take radius. Next we have created the
function out() to print the radius. Then we have created the function area() in
which we have find the area by multiplying the 3.14(value of pie) with the
square of given radius and print it on
screen. Next we have created a function name circum() in which we have multiplied
2 with 3.14 and radius and display it on screen.
Then
we will create main function, create an object and calls the functions in, out,
area and circum respectively. At last control is backed to the system using
return statement.
Code:
#include<iostream>
using
namespace std;
class
Circle{
private:
int r;
public:
void in()
{
cout<<"
Enter Radius "<<endl;
cin>>r;
}
void out()
{
cout<<"
Radius = "<<r<<endl;
}
void area()
{
cout<<" Area = "<<3.14*r*r<<endl;
}
void circum()
{
cout<<"
Circumference = "<<2*3.14*r<<endl;
}
};
int
main()
{
Circle t;
t.in();
t.out();
t.area();
t.circum();
return 0;
}
Output:
Then
we have executed this code on our dev C++ compiler IDE by pressing f11 function
key. A black box is prompted ask to enter radius. We have entered it gives us
the area and circumference. And we have captured it for you.
Thanks
for learning from this page. We demands that anyone who visit this page becomes
able to run that code we will help him if he is in any type of error.
Post a Comment
Feel Free to Comment Us