Study of Default Constructor

C++ Program.

The following is a program in C++ to study default constructor. You can compile this in Borland C++ or Turbo C compiler to get the output. The code for the program is as follows:

#include

#include

#define pi 3.14

class circle

{

float r,a,c,x,y;

public: circle()

{

r=x=y=a=c=0;

}

void access()

{

cout<<”nEnter circle details:”;

cout<<”nRadius:”;

cin>>r;

cout<<”nEnter x and y coordinates of circle:”;

cin>>x>>y;

}

void area()

{

a=pi*r*r;

}

void circumference()

{

c=2*pi*r;

}

void disp()

{

cout<<”nCircle details:”;

cout<<”nRadius:”<

cout<<”nCoordinates:”<

cout<<”nArea:<

cout<<”nCircumference”<

}

};

void main()

{

clrscr();

circle c1;

c1.access();

c1.area();

c1.circumference();

c1.disp();

getch();

}

The output of the above program is:

Enter circle details

Radius: 5

Enter x and y coordinates: 5 6

Circle details:

Radius: 5

Coordinates: 5 6

Area: 78.5

Circumference: 31.4

Hope this helped

Also have a look at my other C++ Programs:

Search Element Using Binary Search Technique

Swap Two Numbers Using Call by Reference

Reverse of a String

Traverse an Array with a Pointer

Study The Structure of a Class

Study of Multiple Constructors

Study of Destructor

comments powered by Disqus
Loading