-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLASSSTATICOBJECT.CPP
More file actions
41 lines (36 loc) · 922 Bytes
/
CLASSSTATICOBJECT.CPP
File metadata and controls
41 lines (36 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream.h>
#include<conio.h>
class Box
{
public:
static int objectCount;
// Constructor definition
Box(double l=2.0, double b=2.0, double h=2.0)
{
cout <<"Constructor called." << endl;
length = l;
breadth = b;
height = h;
// Increase every time object is created
objectCount++;
}
double Volume()
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
// Initialize static member of class Box
int Box::objectCount = 0;
void main(void)
{
Box Box1(3.3, 1.2, 1.5); // Declare box1
Box Box2(8.5, 6.0, 2.0); // Declare box2
Box b3(1.2,3.4,5.6);
// Print total number of objects.
cout << "Total objects: " << Box::objectCount << endl;
getch();
}