Skip to content

Commit 49843c6

Browse files
committed
initial commit
1 parent 01ef88d commit 49843c6

9 files changed

+98
-0
lines changed

Lab_6/Q1/output.PNG

8.54 KB
Loading

Lab_6/Q1/unary_opp_overloading.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Distance {
6+
public:
7+
int feet, inch;
8+
Distance(int f, int i)
9+
{
10+
this->feet = f;
11+
this->inch = i;
12+
}
13+
void operator-()
14+
{
15+
feet--;
16+
inch--;
17+
cout << "\nFeet & Inches(Decrement): " << feet << "'" << inch;
18+
}
19+
};
20+
int main()
21+
{
22+
Distance d1(8, 9);
23+
-d1;
24+
return 0;
25+
}

Lab_6/Q1/unary_opp_overloading.exe

56 KB
Binary file not shown.

Lab_6/Q2/binary_opp_overloading.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Distance {
6+
public:
7+
int feet, inch;
8+
Distance()
9+
{
10+
this->feet = 0;
11+
this->inch = 0;
12+
}
13+
Distance(int f, int i)
14+
{
15+
this->feet = f;
16+
this->inch = i;
17+
}
18+
Distance operator+(Distance& d2)
19+
{
20+
Distance d3;
21+
d3.feet = this->feet + d2.feet;
22+
d3.inch = this->inch + d2.inch;
23+
return d3;
24+
}
25+
};
26+
27+
int main()
28+
{
29+
Distance d1(8, 9);
30+
Distance d2(10, 2);
31+
Distance d3;
32+
d3 = d1 + d2;
33+
cout << "\nTotal Feet & Inches: " << d3.feet << "'" << d3.inch;
34+
return 0;
35+
}

Lab_6/Q2/binary_opp_overloading.exe

56.3 KB
Binary file not shown.

Lab_6/Q2/output.PNG

8.48 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Distance {
6+
public:
7+
int feet, inch;
8+
Distance()
9+
{
10+
this->feet = 0;
11+
this->inch = 0;
12+
}
13+
Distance(int f, int i)
14+
{
15+
this->feet = f;
16+
this->inch = i;
17+
}
18+
19+
friend Distance operator+(Distance&, Distance&);
20+
};
21+
Distance operator+(Distance& d1, Distance& d2)
22+
{
23+
Distance d3;
24+
d3.feet = d1.feet + d2.feet;
25+
d3.inch = d1.inch + d2.inch;
26+
return d3;
27+
}
28+
29+
// Driver Code
30+
int main()
31+
{
32+
Distance d1(8, 9);
33+
Distance d2(10, 2);
34+
Distance d3;
35+
d3 = d1 + d2;
36+
cout << "\nTotal Feet & Inches: " << d3.feet << "'" << d3.inch;
37+
return 0;
38+
}
56.1 KB
Binary file not shown.

Lab_6/Q3/output.PNG

9.63 KB
Loading

0 commit comments

Comments
 (0)