-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairport.cpp
80 lines (68 loc) · 1.94 KB
/
airport.cpp
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
#include <iostream>
#include <cstring>
#include <memory>
#include "airport.hpp"
//Constructors
Airport::Airport()
{
airport_name = nullptr;
x_coordinate = nullptr;
y_coordinate = nullptr;
}
Airport::Airport (std::string name, double x, double y)
{
airport_name = std::make_unique<std::string>(name);
x_coordinate = std::make_unique<double>(x);
y_coordinate = std::make_unique<double>(y);
}
//Copy Constructor
Airport::Airport(const Airport& airport)
{
airport_name = std::make_unique<std::string>(*airport.airport_name);
x_coordinate = std::make_unique<double>(*airport.x_coordinate);
y_coordinate = std::make_unique<double>(*airport.y_coordinate);
}
//Getters and Setters
void Airport::Set_Data(double x, double y)
{
x_coordinate = std::make_unique<double>(x);
y_coordinate = std::make_unique<double>(y);
}
void Airport::Set_Data(std::string name)
{
airport_name = std::make_unique<std::string>(name);
}
double Airport::Get_x() const
{
return *x_coordinate;
}
double Airport::Get_y() const
{
return *y_coordinate;
}
//Overloading the >>, << and = operators
std::istream& operator>>(std::istream& on, Airport& airport)
{
std::string copy;
double x, y;
on >> copy >> x >> y;
airport.airport_name = std::make_unique<std::string>(copy);
airport.x_coordinate = std::make_unique<double>(x);
airport.y_coordinate = std::make_unique<double>(y);
return on;
}
std::ostream& operator<<(std::ostream& of, const Airport& airport)
{
of << "Name: " << *airport.airport_name << " [" << *airport.x_coordinate << ", " << *airport.y_coordinate << "]";
return of;
}
Airport& Airport::operator=(const Airport& airport)
{
if (this != &airport)
{
airport_name = std::make_unique<std::string>(*airport.airport_name);
x_coordinate = std::make_unique<double>(*airport.x_coordinate);
y_coordinate = std::make_unique<double>(*airport.y_coordinate);
}
return *this;
}