Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c081435

Browse files
committed
Added new tasks
1 parent a2612ed commit c081435

File tree

4 files changed

+405
-215
lines changed

4 files changed

+405
-215
lines changed

‎OOP2_Lab5/Source.cpp‎

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@
22
#include <string>
33
using namespace std;
44

5-
// class 'Rectangle'
6-
class Rectangle {
5+
// class 'Rectangle'
6+
class Rectangle
7+
{
78
private:
8-
double length, breadth;
9+
double length, breadth;
10+
911
public:
10-
double getArea() {
12+
double getArea()
13+
{
1114
return length * breadth;
1215
}
13-
void setLength(double length) {
16+
void setLength(double length)
17+
{
1418
this->length = length;
15-
}
16-
void setBreadth(double breadth) {
19+
}
20+
void setBreadth(double breadth)
21+
{
1722
this->breadth = breadth;
18-
1923
}
20-
Rectangle operator+(Rectangle& r2) {
24+
Rectangle operator+(Rectangle &r2)
25+
{
2126
Rectangle temp;
2227
temp.setLength(length + r2.length);
2328
temp.setBreadth(breadth + r2.breadth);
2429
return temp;
2530
}
26-
2731
};
2832
// void function for the inputing data for class 'Rectangle' & uisng the overloading
29-
void RectangleFirst() {
33+
void RectangleFirst()
34+
{
3035
Rectangle r3, r1, r2;
3136
int temp;
3237
cout << "Rectangle 1" << endl;
@@ -36,7 +41,8 @@ void RectangleFirst() {
3641
cout << "Breadth: ";
3742
cin >> temp;
3843
r1.setBreadth(temp);
39-
cout << "Area: " << r1.getArea() << endl << endl;
44+
cout << "Area: " << r1.getArea() << endl
45+
<< endl;
4046

4147
cout << "Rectangle 2" << endl;
4248
cout << "Length: ";
@@ -45,63 +51,79 @@ void RectangleFirst() {
4551
cout << "Breadth: ";
4652
cin >> temp;
4753
r2.setBreadth(temp);
48-
cout << "Area: " << r2.getArea() << endl << endl;
54+
cout << "Area: " << r2.getArea() << endl
55+
<< endl;
4956

5057
r3 = r1 + r2; // overloading by the binary operator
5158
cout << "Rectangle 3 Area: " << r3.getArea() << endl;
52-
5359
}
5460

55-
class Distance {
61+
class Distance
62+
{
5663
private:
5764
float Km, M;
65+
5866
public:
59-
void setKm(int Km) {
67+
void setKm(int Km)
68+
{
6069
this->Km = Km;
6170
}
62-
void setM(int M) {
71+
void setM(int M)
72+
{
6373
this->M = M;
6474
}
65-
Distance operator==(Distance& d) {
66-
if ((Km == d.Km) && (M == d.M)) {
75+
Distance operator==(Distance &d)
76+
{
77+
if ((Km == d.Km) && (M == d.M))
78+
{
6779
cout << "They are EQUAL.\n";
6880
return *this;
6981
}
70-
else {
82+
else
83+
{
7184
cout << "NOT EQUAL.\n";
7285
return *this;
7386
}
7487
}
7588
};
76-
void DistanceSecond() {
89+
void DistanceSecond()
90+
{
7791
Distance d1, d2;
78-
float k1,m1,k2,m2;
92+
float k1,m1,k2,m2;
7993
cout << "First distance: \n";
8094
cout << "Kilometers: ";
8195
cin >> k1;
8296
cout << "Meters: ";
8397
cin >> m1;
84-
if (m1 > 1000) {
98+
if (m1 > 1000)
99+
{
85100
k1 = m1 / 1000;
86101
}
87-
cout << endl << endl;
102+
cout << endl
103+
<< endl;
88104

89105
cout << "Second distance: \n";
90106
cout << "Kilometers: ";
91107
cin >> k2;
92108
cout << "Meters: ";
93109
cin >> m2;
94-
if (m2 > 1000) {
110+
if (m2 > 1000)
111+
{
95112
k2 = m2 / 1000;
96113
}
97114
d1 == d2;
98115
}
99-
int main() {
116+
int main()
117+
{
100118
int choice;
101119

102-
do {
120+
do
121+
{
103122

104-
cout << "1. Rectangle" << endl << "2. Distance" << endl << "3. Exit" << endl << "Your choice: ";
123+
cout << "1. Rectangle" << endl
124+
<< "2. Distance" << endl
125+
<< "3. Exit" << endl
126+
<< "Your choice: ";
105127
cin >> choice;
106128
switch (choice)
107129
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /