Welcome to C++ OOPs world !
Here we will solve some problems on oops concept .
1. Write a C++ program to implement a class called
Circle that has private member variables for radius.
Include member functions to calculate the circle's
area and circumference.
Sol.
#include <iostream>
using namespace std;
class circle{
private:
float radius;
public:
void setradius(float t){
radius=t;
}
float circumference(){
float c;
c= 2*3.14*radius;
return c;
}
float area(){
float a;
a=3.14*radius*radius;
return a;
}
};
int main() {
// Write C++ code here
circle c;
float r,circum,area;
cout<<"Enter the radius"<<" "<<endl;
cin>>r;
[Link](r);
circum=[Link]();
area=[Link]();
cout<<"Your circumference of circle is :"<<circum<<"
"<<endl;
cout<<"Your area of circle is :"<<area<<" "<<endl;
return 0;
}
Output:
Enter the radius
4
Your circumference of circle is :25.12
Your area of circle is :50.24
[Link]
continue above link