WRITE A PROGRAM FOR CONSTRUCTOR IN C++

 Que - make a program for calculate area of circle by using constructor?

#include<iostream>
using namespace std;

class construct
{

    float pi,area;
    int radius ;
public:
    construct ()
    {
        pi=3.14;
    }
    void getdata ()
    {
    cout<<"enter radius of circle :";
    cin>>radius;
    area=pi*radius*radius ;
    cout<<"area of circle is :"<<area;
    }
};

int main()
{
    construct ob ;
    ob.getdata();
    return 0;
}

Result:-



Post a Comment

Previous Post Next Post