02-02-2011, 05:41 PM
/* ID: MC100402622.
Name: M.MOHSIN CH.
*/
#include <iostream.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
class crectangle
{
private:
int itop;
int iright;
int ibot;
int ileft;
public:
static int irefcount;
// default constructor is declared below.
crectangle ();
// copy constructor is declared below.
crectangle (crectangle &, crectangle *);
// destructor is declared below.
~crectangle ();
// methods are declared below.
int getrectanglearea (crectangle &);
void getitop();
void getiright();
void getibot();
void getileft();
void getirefcount();
void setmembrs (int,int,int,int);
void setitop(int);
void setiright(int);
void setibot(int);
void setileft(int);
};
// Methods, constructor and destructor are defined below.
// crectangle () is defined below.
crectangle::crectangle ()
{
itop=0;
iright=0;
ibot=0;
ileft=0;
irefcount++;
}// crectangle ()'s defination ends here.
// crectangle (crectangle &) is defined below.
crectangle::crectangle(crectangle &a, crectangle *pointer)
{
pointer=new crectangle;
pointer->itop=a.itop;
pointer->iright=a.iright;
pointer->ibot=a.ibot;
pointer->ileft=a.ileft;
irefcount++;
}
// destructor ~crectangle () is defined below.
crectangle::~crectangle()
{
irefcount--;
}// ~crectangle ()'s defination ends here.
// getitop () is defined below.
void crectangle:: getitop()
{
cout<<endl<<"Value of ITop is: \t"<<itop<<endl;
}// getitop ()'s defination ends here.
// getiright() is defined here.
void crectangle:: getiright()
{
cout<<endl<<"Value of IRight is: \t"<<iright<<endl;
}// getiright()'s defination ends here.
// getibot () is defined below.
void crectangle:: getibot()
{
cout<<endl<<"Value of IBot is: \t"<<ibot<<endl;
}// getibot ()'s defination ends here.
// getileft () is defined below.
void crectangle:: getileft()
{
cout<<endl<<"Value of ILeft is: \t"<<ileft<<endl;
}// getileft ()'s defination ends here.
// getirefcount () is defined here.
void crectangle:: getirefcount()
{
cout<<endl<<"Value of IREfcount is: \t"<<irefcount<<endl;
}// getirefcount()'s defination ends here.
// getrectangleare () is defined below.
int crectangle::getrectanglearea(crectangle &a)
{
return (a.itop * a.iright * a.ibot * a.ileft);
}// getrectanglearea ()'s defination ends here.
// setmembers (int, int ,int ,int ) is defined below.
void crectangle:: setmembrs(int a, int b, int c, int d)
{
itop=a;
iright=b;
ibot=c;
ileft=d;
} // setmembers ()'s defination ends here.
// setitop (int) is defined below.
void crectangle:
etitop(int a)
{
itop=a;
}//setitop (int) ends here.
// setiright (int) ends here.
void crectangle:: setiright (int b)
{
iright=b;
}// setiright (int)'s defination ends here.
// setibot(int) is defined below.
void crectangle:
etibot(int c)
{
ibot=c;
}//setbot (int)'s defination ends here.
// setileft(int) is defined below.
void crectangle:
etileft(int d)
{
ileft=d;
}// setileft(int)'s defination ends here.
// Static member of class is intialized here.
int crectangle::irefcount=0;
// Main () function starts from here.
main ()
{
int a, b, c, d =0;
crectangle *pointer;
crectangle rectangle1, rectangle2;
a=6;
b=13;
c=14;
d=5;
cout<<endl;
rectangle1.setitop(a);
rectangle1.setiright(b);
rectangle1.setibot©;
rectangle1.setileft(d);
cout<<"Area of rectangle1 is: \t"<<rectangle1.getrectanglearea(rectangle1)<<endl;
a=3;
b=10;
c=8;
d=20;
rectangle2.setmembrs(a,b,c,d);
cout<<endl<<"Area of rectangle2 is: \t"<<rectangle1.getrectanglearea(rectangle2)<<endl;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;
crectangle(rectangle1,pointer);
cout<<endl<<"After using copy-constructor Number of Rectangles is \t"<<crectangle::irefcount<<endl;
delete pointer;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;
}
Name: M.MOHSIN CH.
*/
#include <iostream.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
class crectangle
{
private:
int itop;
int iright;
int ibot;
int ileft;
public:
static int irefcount;
// default constructor is declared below.
crectangle ();
// copy constructor is declared below.
crectangle (crectangle &, crectangle *);
// destructor is declared below.
~crectangle ();
// methods are declared below.
int getrectanglearea (crectangle &);
void getitop();
void getiright();
void getibot();
void getileft();
void getirefcount();
void setmembrs (int,int,int,int);
void setitop(int);
void setiright(int);
void setibot(int);
void setileft(int);
};
// Methods, constructor and destructor are defined below.
// crectangle () is defined below.
crectangle::crectangle ()
{
itop=0;
iright=0;
ibot=0;
ileft=0;
irefcount++;
}// crectangle ()'s defination ends here.
// crectangle (crectangle &) is defined below.
crectangle::crectangle(crectangle &a, crectangle *pointer)
{
pointer=new crectangle;
pointer->itop=a.itop;
pointer->iright=a.iright;
pointer->ibot=a.ibot;
pointer->ileft=a.ileft;
irefcount++;
}
// destructor ~crectangle () is defined below.
crectangle::~crectangle()
{
irefcount--;
}// ~crectangle ()'s defination ends here.
// getitop () is defined below.
void crectangle:: getitop()
{
cout<<endl<<"Value of ITop is: \t"<<itop<<endl;
}// getitop ()'s defination ends here.
// getiright() is defined here.
void crectangle:: getiright()
{
cout<<endl<<"Value of IRight is: \t"<<iright<<endl;
}// getiright()'s defination ends here.
// getibot () is defined below.
void crectangle:: getibot()
{
cout<<endl<<"Value of IBot is: \t"<<ibot<<endl;
}// getibot ()'s defination ends here.
// getileft () is defined below.
void crectangle:: getileft()
{
cout<<endl<<"Value of ILeft is: \t"<<ileft<<endl;
}// getileft ()'s defination ends here.
// getirefcount () is defined here.
void crectangle:: getirefcount()
{
cout<<endl<<"Value of IREfcount is: \t"<<irefcount<<endl;
}// getirefcount()'s defination ends here.
// getrectangleare () is defined below.
int crectangle::getrectanglearea(crectangle &a)
{
return (a.itop * a.iright * a.ibot * a.ileft);
}// getrectanglearea ()'s defination ends here.
// setmembers (int, int ,int ,int ) is defined below.
void crectangle:: setmembrs(int a, int b, int c, int d)
{
itop=a;
iright=b;
ibot=c;
ileft=d;
} // setmembers ()'s defination ends here.
// setitop (int) is defined below.
void crectangle:
etitop(int a){
itop=a;
}//setitop (int) ends here.
// setiright (int) ends here.
void crectangle:: setiright (int b)
{
iright=b;
}// setiright (int)'s defination ends here.
// setibot(int) is defined below.
void crectangle:
etibot(int c){
ibot=c;
}//setbot (int)'s defination ends here.
// setileft(int) is defined below.
void crectangle:
etileft(int d){
ileft=d;
}// setileft(int)'s defination ends here.
// Static member of class is intialized here.
int crectangle::irefcount=0;
// Main () function starts from here.
main ()
{
int a, b, c, d =0;
crectangle *pointer;
crectangle rectangle1, rectangle2;
a=6;
b=13;
c=14;
d=5;
cout<<endl;
rectangle1.setitop(a);
rectangle1.setiright(b);
rectangle1.setibot©;
rectangle1.setileft(d);
cout<<"Area of rectangle1 is: \t"<<rectangle1.getrectanglearea(rectangle1)<<endl;
a=3;
b=10;
c=8;
d=20;
rectangle2.setmembrs(a,b,c,d);
cout<<endl<<"Area of rectangle2 is: \t"<<rectangle1.getrectanglearea(rectangle2)<<endl;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;
crectangle(rectangle1,pointer);
cout<<endl<<"After using copy-constructor Number of Rectangles is \t"<<crectangle::irefcount<<endl;
delete pointer;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;
}
