forked from Rustam-Z/cpp-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
144 lines (134 loc) · 2.18 KB
/
Copy pathSource.cpp
File metadata and controls
144 lines (134 loc) · 2.18 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
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <string>
using namespace std;
// class 'Rectangle'
class Rectangle
{
private:
double length, breadth;
public:
double getArea()
{
return length * breadth;
}
void setLength(double length)
{
this->length = length;
}
void setBreadth(double breadth)
{
this->breadth = breadth;
}
Rectangle operator+(Rectangle &r2)
{
Rectangle temp;
temp.setLength(length + r2.length);
temp.setBreadth(breadth + r2.breadth);
return temp;
}
};
// void function for the inputing data for class 'Rectangle' & uisng the overloading
void RectangleFirst()
{
Rectangle r3, r1, r2;
int temp;
cout << "Rectangle 1" << endl;
cout << "Length: ";
cin >> temp;
r1.setLength(temp);
cout << "Breadth: ";
cin >> temp;
r1.setBreadth(temp);
cout << "Area: " << r1.getArea() << endl
<< endl;
cout << "Rectangle 2" << endl;
cout << "Length: ";
cin >> temp;
r2.setLength(temp);
cout << "Breadth: ";
cin >> temp;
r2.setBreadth(temp);
cout << "Area: " << r2.getArea() << endl
<< endl;
r3 = r1 + r2; // overloading by the binary operator
cout << "Rectangle 3 Area: " << r3.getArea() << endl;
}
class Distance
{
private:
float Km, M;
public:
void setKm(int Km)
{
this->Km = Km;
}
void setM(int M)
{
this->M = M;
}
Distance operator==(Distance &d)
{
if ((Km == d.Km) && (M == d.M))
{
cout << "They are EQUAL.\n";
return *this;
}
else
{
cout << "NOT EQUAL.\n";
return *this;
}
}
};
void DistanceSecond()
{
Distance d1, d2;
float k1, m1, k2, m2;
cout << "First distance: \n";
cout << "Kilometers: ";
cin >> k1;
cout << "Meters: ";
cin >> m1;
if (m1 > 1000)
{
k1 = m1 / 1000;
}
cout << endl
<< endl;
cout << "Second distance: \n";
cout << "Kilometers: ";
cin >> k2;
cout << "Meters: ";
cin >> m2;
if (m2 > 1000)
{
k2 = m2 / 1000;
}
d1 == d2;
}
int main()
{
int choice;
do
{
cout << "1. Rectangle" << endl
<< "2. Distance" << endl
<< "3. Exit" << endl
<< "Your choice: ";
cin >> choice;
switch (choice)
{
case 1:
system("cls");
RectangleFirst();
system("pause");
case 2:
system("cls");
DistanceSecond();
system("pause");
default:
break;
}
} while (choice != 3);
return 0;
}