write a program using class to calculate the area of circle
Answers
Answered by
0
Following program is calculating the area of circle using class circle.
#include<iostream>
using namespace std;
class circle
{
float radius, area; //data members
public:
circle()
{
cout<<"\n Enter the value of Radius : ";
cin>>radius;
}
void calculate(); //member function
void display(); //member function
};
inline void circle :: calculate() //accessing data members of a class circle
{
area = 3.14 * radius * radius;
}
inline void circle :: display()
{
cout<<"\n Area of Circle : "<<area;
}
int main()
{
circle cr; //object created
cr.calculate(); //calling function
cr.display(); //calling function
return 0;
}
I hope It Helps U
#include<iostream>
using namespace std;
class circle
{
float radius, area; //data members
public:
circle()
{
cout<<"\n Enter the value of Radius : ";
cin>>radius;
}
void calculate(); //member function
void display(); //member function
};
inline void circle :: calculate() //accessing data members of a class circle
{
area = 3.14 * radius * radius;
}
inline void circle :: display()
{
cout<<"\n Area of Circle : "<<area;
}
int main()
{
circle cr; //object created
cr.calculate(); //calling function
cr.display(); //calling function
return 0;
}
I hope It Helps U
js8ehwibai:
I m An CS Student
Similar questions