Skip to content

Commit c5eeea3

Browse files
committed
add: cpp-programming-questions 06_operator_over_friend 17
1 parent d0a5b2e commit c5eeea3

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files.associations": {
3+
"system_error": "cpp",
4+
"array": "cpp",
5+
"functional": "cpp",
6+
"tuple": "cpp",
7+
"type_traits": "cpp",
8+
"utility": "cpp",
9+
"ostream": "cpp",
10+
"iostream": "cpp"
11+
}
12+
}

06_operator_overloading_and_friend_function/16_logical_not_for_integer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// // Create an Integer class and overload logical not operator for that class.
2+
13
// // Header files
24
#include <iostream>
35
#include <conio.h>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// // Create a Coordinate class for 3 variables x,y and z and overload comma operator such that when you write c3 = (c1 , c2 ) then c2 is assigned to c3. Where c1,c2 and c3 are objects of 3D coordinate class.
2+
3+
// // Header files
4+
#include <iostream>
5+
#include <conio.h>
6+
7+
// // use namespace
8+
using namespace std;
9+
10+
// // define class Coordinate
11+
class Coordinate
12+
{
13+
private:
14+
// // instance memeber variable
15+
int x, y, z;
16+
17+
public:
18+
// // Constructor
19+
Coordinate()
20+
{
21+
x = y = z = 0;
22+
}
23+
24+
Coordinate(int x, int y, int z)
25+
{
26+
this->x = x;
27+
this->y = y;
28+
this->z = z;
29+
}
30+
31+
// // instance memebr function to get value
32+
void setValues(int x, int y, int z)
33+
{
34+
this->x = x;
35+
this->y = y;
36+
this->z = z;
37+
}
38+
39+
// // instance memebr function to get value
40+
int showValues()
41+
{
42+
cout << "\nx => " << x;
43+
cout << "\ny => " << y;
44+
cout << "\nz => " << z;
45+
}
46+
47+
// overload logical comma (,) operator
48+
Coordinate operator,(Coordinate p)
49+
{
50+
return p;
51+
}
52+
};
53+
54+
int main()
55+
{
56+
57+
Coordinate c1(2, 4, 6), c2(4, 2, 135), c3; // create objects of Coordinate class
58+
59+
c3 = (c1, c2);
60+
61+
cout << "\n\n>>>>>>>>>>> Coordinates of c1 <<<<<<<<<<<";
62+
c1.showValues();
63+
cout << "\n\n>>>>>>>>>>> Coordinates of c2 <<<<<<<<<<<";
64+
c2.showValues();
65+
cout << "\n\n>>>>>>>>>>> Coordinates of c3 <<<<<<<<<<<";
66+
c3.showValues();
67+
68+
cout << endl; // Add new line
69+
getch();
70+
return 0;
71+
}
45.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)