-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuboid.cpp
More file actions
56 lines (53 loc) · 1.15 KB
/
Copy pathcuboid.cpp
File metadata and controls
56 lines (53 loc) · 1.15 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
int a = 30; // Global Variable
class Cuboid
{
private: //Access specifiers
int l, b, h; //Encapsulation-Binging of data and methods into a single unit
public: //Access specifiers
void setdata(int x, int y, int z) //Member Functions - They are defined inside the class
{
l=x;
b=y;
h=z;
}
void showdata()
{
cout<<"Cuboid length is: ";
cout<<l<<endl;
cout<<"Cuboid breadth is: ";
cout<<b<<endl;
cout<<"Cuboid height is: ";
cout<<h<<endl;
}
void volume();
};
void Cuboid::volume() // :: is scope resolution operator
{
cout<<"Volume of cuboid is: ";
cout<<l*b*h<<endl;
}
class Cube
{
public:
int side;
int getvolume();
};
int Cube::getvolume() // outside class we are giving the body of member function using scope resolution operater
{
return side*side*side;
}
int main()
{
int a = 20; // local variable
cout<<"The value of local variable a is: "<<a<<endl<<endl;
cout<<"The value of Global variable a is: "<<::a<<endl<<endl;
Cuboid c;
Cube c1;
c.setdata(6,7,8);
c.volume();
c1.side = 4;
cout<<"Volume of Cube is : "<<c1.getvolume();
return 0;
}