Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. class Box {
  4.     static int counter;
  5.     double width, length, height;
  6. public:
  7.     //Constructors-----------------------------------
  8.     Box();
  9.     //lista arxikopoihshs*************************************************************
  10.     Box(double dimension) : height(dimension), width(dimension), length(dimension) { counter++; }
  11.     //********************************************************************************
  12.     Box(double width, double length, double height);
  13.     //copy constuctor++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14.     Box(const Box & box) : height(box.height),length(box.length) ,width(box.width) {
  15.         counter++;
  16.     }
  17.     //Distructor
  18.     ~Box() {
  19.         cout << "Destructor Called " << counter<<endl;
  20.         counter--; };
  21.     //
  22.     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  23.     //-----------------------------------------------
  24.     //Setters and Getters.--------------
  25.     void setWidth(double width) { this->width = width; }
  26.     void setLength(double length) { this->length = length; }
  27.     void setHeight(double height) { this->height = height; }
  28.     double getWidth() { return width; }
  29.     double getLength() { return length; }
  30.     double getHeight() { return height; }
  31.     static int getCounter() { return counter; }
  32.     //-----------------------------------
  33. };
  34. //The stuct of constructors.-----------------------------
  35. Box::Box() {
  36.     width = 1;
  37.     length = 1;
  38.     height = 1;
  39.     counter++;
  40. }
  41. Box::Box(double width, double length, double height) {
  42.     this->width = width;
  43.     this->length = length;
  44.     this->height = height;
  45.     counter++;
  46. }
  47. //--------------------------------------------------------
  48. int Box::counter = 0;
  49.  
  50. int main() {
  51.     double width,length,height;
  52.     //An instance of the Box class.---------------------
  53.     Box cube;
  54.     Box * cube1 = new Box(2.0);
  55.     Box *boxes = new Box[10];
  56.     Box cube2(cube);
  57.     //-------------------------------------------------
  58.     cout << Box::getCounter()<<endl;
  59.     delete cube1;
  60.     delete [] boxes ;
  61.     cout << Box::getCounter() << endl;
  62.     system("PAUSE");
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement