Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Box {
- static int counter;
- double width, length, height;
- public:
- //Constructors-----------------------------------
- Box();
- //lista arxikopoihshs*************************************************************
- Box(double dimension) : height(dimension), width(dimension), length(dimension) { counter++; }
- //********************************************************************************
- Box(double width, double length, double height);
- //copy constuctor++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Box(const Box & box) : height(box.height),length(box.length) ,width(box.width) {
- counter++;
- }
- //Distructor
- ~Box() {
- cout << "Destructor Called " << counter<<endl;
- counter--; };
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //-----------------------------------------------
- //Setters and Getters.--------------
- void setWidth(double width) { this->width = width; }
- void setLength(double length) { this->length = length; }
- void setHeight(double height) { this->height = height; }
- double getWidth() { return width; }
- double getLength() { return length; }
- double getHeight() { return height; }
- static int getCounter() { return counter; }
- //-----------------------------------
- };
- //The stuct of constructors.-----------------------------
- Box::Box() {
- width = 1;
- length = 1;
- height = 1;
- counter++;
- }
- Box::Box(double width, double length, double height) {
- this->width = width;
- this->length = length;
- this->height = height;
- counter++;
- }
- //--------------------------------------------------------
- int Box::counter = 0;
- int main() {
- double width,length,height;
- //An instance of the Box class.---------------------
- Box cube;
- Box * cube1 = new Box(2.0);
- Box *boxes = new Box[10];
- Box cube2(cube);
- //-------------------------------------------------
- cout << Box::getCounter()<<endl;
- delete cube1;
- delete [] boxes ;
- cout << Box::getCounter() << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement