Skip to content

Commit fb46184

Browse files
committed
add: cpp-programming-questions 06_operator_over_friend 20
1 parent f2f9232 commit fb46184

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
10+
}

06_operator_overloading_and_friend_function/16_logical_not_for_integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Integer
1515
int value;
1616

1717
public:
18-
// // Constructor
18+
// // constructors
1919
Integer()
2020
{
2121
value = 0;

06_operator_overloading_and_friend_function/17_coordinate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Coordinate
1515
int x, y, z;
1616

1717
public:
18-
// // Constructor
18+
// // constructors
1919
Coordinate()
2020
{
2121
x = y = z = 0;

06_operator_overloading_and_friend_function/18_type_casting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Integer
1515
int value;
1616

1717
public:
18-
// // Constructor
18+
// // constructors
1919
Integer()
2020
{
2121
value = 0;

06_operator_overloading_and_friend_function/19_distance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Distance
1515
double feet, inches;
1616

1717
public:
18-
// // Constructor
18+
// // constructors
1919
Distance()
2020
{
2121
feet = inches = 0;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// // Create a class Marks that have one member variable marks and one member function that will print marks. We know that we can access member functions using (.) dot operator. Now you need to overload (->) arrow operator to access that function.
2+
3+
// // Header files
4+
#include <iostream>
5+
#include <conio.h>
6+
7+
// // use namespace
8+
using namespace std;
9+
10+
// // define class Marks
11+
class Marks
12+
{
13+
private:
14+
// // instance memeber variable
15+
int marks;
16+
17+
public:
18+
// // constructors
19+
Marks()
20+
{
21+
marks = 0;
22+
}
23+
24+
Marks(int marks)
25+
{
26+
this->marks = marks;
27+
}
28+
29+
// // instance member function to print marks
30+
void printMarks()
31+
{
32+
cout << "\nMarks => " << marks;
33+
}
34+
35+
// // overload member access operator (->)
36+
void operator->()
37+
{
38+
}
39+
};
40+
41+
int main()
42+
{
43+
44+
Marks m1(445); // create an object of Marks class
45+
46+
cout << endl; // Add new line
47+
getch();
48+
return 0;
49+
}

0 commit comments

Comments
 (0)