forked from tridibsamanta/CPP_Beginner_to_Expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP031_Classes.cpp
57 lines (43 loc) · 1023 Bytes
/
CPP031_Classes.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Author: Tridib Samanta
* Created: 02.02.2020
**/
#include<iostream>
using namespace std;
class MyDetails {
private:
short age;
int *p;
public:
MyDetails() //Constructor
{
static int i=0;
cout<<"This constructor has been just invoked "<<++i<<" time"<<endl;
age=50;
p=new int[10];
}
~MyDetails() //Destructor
{
static int j=0;
cout<<"This Destructor has been just invoked "<<++j<<" time"<<endl;
delete [] p;
}
void setAge(int value) {
if(value<0)
age=0;
else
age=value;
}
short getAge() {
return age;
}
};
int main() {
MyDetails p1;
MyDetails p2;
p1.setAge(-55);
p2.setAge(20);
cout<<p1.getAge()<<endl;
cout<<p2.getAge()<<endl;
return 0;
}