-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroute.cpp
67 lines (51 loc) · 1.25 KB
/
route.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
//
// Created by Aykut Ismailov on 29.4.2020 г..
//
#include "route.h"
object route::getStart() const
{
return start;
}
object route::getEnd() const
{
return end;
}
route_type route::getRoadType() const
{
return road_type;
}
double route::getDuration() const
{
return duration;
}
double route::getDistance() const
{
return distance(start, end);
}
std::string route::getDurationString() const
{
int hours = static_cast<int>(duration / 3600);
int minutes = static_cast<int>((duration - hours * 3600) / 60);
double seconds = duration - minutes * 60 - hours * 3600;
return std::to_string(hours) + ":" + std::to_string(minutes) + ":" + std::to_string(seconds);
}
std::ostream& operator<<(std::ostream& out, route o)
{
std::string str;
switch(o.getRoadType())
{
case route_type::Highway:
str = "Highway";
break;
case route_type::Inter_city:
str = "Inter-city";
break;
case route_type::Off_read:
str = "Off-road";
break;
default:
str = "";
}
out << "This " << str << " starts from " << o.start << " and ends in " << o.end << ". The duration is " << o.getDurationString() << ".";
return out;
}