-
Notifications
You must be signed in to change notification settings - Fork 3
/
1.cpp
36 lines (31 loc) · 675 Bytes
/
1.cpp
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
#include <iostream>
using namespace std;
class Rectangle
{
//private members
int height = 0, width = 0;
public:
void setHeight(int h);
void setWidth(int w);
int getArea() //member functions defined inside class declaration are automatic inline function.
{
return height * width;
}
} rect1;
void Rectangle::setHeight(int h)
{
height = h;
}
void Rectangle::setWidth(int w)
{
width = w;
}
int main()
{
Rectangle rect2(rect1); //default copy constructor
rect2.setWidth(2);
rect2.setHeight(3);
cout << "rect1 Area: " << rect1.getArea() << "\n";
cout << "rect2 Area: " << rect2.getArea() << "\n";
return 0;
}