Thursday, February 24, 2011

Constructors and Destructors


#include<iostream.h>
#include<conio.h>

class fixed
{
int a,b;
public:

 fixed()
 {
 cout<<"\nThe Constructor has Zero Arguments\n";
 cout<<"\n";
 }

 fixed(int x)
 {
 a=x;
 cout<<"The Constructor has One Argument"<<"\n\n";
 cout<<a<<"\n\n";
 }

 fixed(int x,int y)
 {
 a=x;
 b=y;
 cout<<"This Constructor Has Two Arguments:"<<"\n\n";
 cout<<a<<"\n"<<b;
 }

 ~fixed()
 {
 cout<<"\n Objects Destroyed";
 cout<<"\n";
 }

};

void main()
{
clrscr();

fixed ob;
fixed ob1(10);
fixed ob2(20);
fixed ob3(10,20);

getch();
}

No comments:

Post a Comment