-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassOperations.cpp
More file actions
132 lines (97 loc) · 2.21 KB
/
Copy pathClassOperations.cpp
File metadata and controls
132 lines (97 loc) · 2.21 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
using namespace std;
class Student
{
protected:
int rollNo;
public:
Student()
{
rollNo = 0;
cout << "Student Default Constructor Called" << endl;
}
Student(int r)
{
rollNo = r;
cout << "Student Parameterized Constructor Called" << endl;
}
Student(const Student &s)
{
rollNo = s.rollNo;
cout << "Student Copy Constructor Called" << endl;
}
~Student()
{
cout << "Student Destructor Called" << endl;
}
};
class Sports
{
protected:
int sportsMarks;
public:
Sports()
{
sportsMarks = 0;
cout << "Sports Default Constructor Called" << endl;
}
Sports(int m)
{
sportsMarks = m;
cout << "Sports Parameterized Constructor Called" << endl;
}
Sports(const Sports &s)
{
sportsMarks = s.sportsMarks;
cout << "Sports Copy Constructor Called" << endl;
}
~Sports()
{
cout << "Sports Destructor Called" << endl;
}
};
class Result : public Student, public Sports
{
private:
int totalMarks;
public:
Result() : Student(), Sports()
{
totalMarks = 0;
cout << "Result Default Constructor Called" << endl;
}
Result(int r, int s, int t) : Student(r), Sports(s)
{
totalMarks = t;
cout << "Result Parameterized Constructor Called" << endl;
}
Result(const Result &obj) : Student(obj), Sports(obj)
{
totalMarks = obj.totalMarks;
cout << "Result Copy Constructor Called" << endl;
}
void display()
{
cout << "\nRoll No : " << rollNo;
cout << "\nSports Marks : " << sportsMarks;
cout << "\nTotal Marks : " << totalMarks << endl;
}
~Result()
{
cout << "Result Destructor Called" << endl;
}
};
int main()
{
cout << "\n===== Default Constructor =====\n";
Result r1;
r1.display();
cout << "\n===== Parameterized Constructor =====\n";
Result r2(101, 25, 450);
r2.display();
cout << "\n===== Copy Constructor =====\n";
Result r3(r2);
r3.display();
cout << "\nProgram Ends..." << endl;
return 0;
}