-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_object.cpp
64 lines (54 loc) · 1.09 KB
/
dynamic_object.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
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
class Student
{
public:
int roll;
int cls;
double gpa;
Student(int cls, int roll, double gpa)
{
this->cls = cls;
this->roll = roll;
this->gpa = gpa;
}
};
Student *fun()
{
Student *rahim = new Student(10, 46, 3.86);
return rahim;
}
main()
{
Student *rahim = fun();
cout << rahim->cls << " " << rahim->roll << " " << fixed << setprecision(2) << rahim->gpa << endl;
delete rahim;
cout << rahim->cls << " " << rahim->roll << " " << fixed << setprecision(2) << rahim->gpa << endl;
return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;
class Student
{
public:
int roll;
int cls;
double gpa;
Student(int cls, int roll, double gpa)
{
this->cls = cls;
this->roll = roll;
this->gpa = gpa;
}
};
main()
{
// Regular Object
// Student rahim(10, 45, 3.65);
// Dynamic Object
Student *karim = new Student(9, 44, 2.30);
cout << karim->cls << " " << karim->roll << " " << fixed << setprecision(2) << karim->gpa;
return 0;
}
*/