-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.cpp
More file actions
39 lines (33 loc) · 679 Bytes
/
Copy pathclass.cpp
File metadata and controls
39 lines (33 loc) · 679 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
#include <iostream>
using namespace std;
class Rectangle
{
int width, height;
public:
Rectangle ();
Rectangle (int x, int y) : width(x), height(y){};
int area () {
return width * height;
};
};
Rectangle::Rectangle ()
{
width = 5;
height = 5;
}
int main ()
{
Rectangle obj(3, 4);
Rectangle *a, *b, *c;
a = &obj;
b = new Rectangle(5, 6);
c = new Rectangle[2] {{2, 5}, {3, 6}};
cout << "obj's area" << obj.area() << endl;
cout << "a's area" << a->area() << endl;
cout << "b's area" << b->area() << endl;
cout << "c[0]'s area" << c[0].area() << endl;
cout << "c[1]'s area" << c[1].area() << endl;
delete b;
delete[] c;
return 0;
}