-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAnt.cpp
More file actions
42 lines (36 loc) · 771 Bytes
/
Ant.cpp
File metadata and controls
42 lines (36 loc) · 771 Bytes
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
#include"Ant.h"
double Ant::GetLength() const
{
return length;
}
void Ant::AddLength(const double &distance)
{
length += distance;
distances.push_back(distance);
}
void Ant::AddWay(const string &c_name)
{
way.push_back(c_name);
}
void Ant::pop_back()
{
way.pop_back();
length -= distances.back();
distances.pop_back();
}
bool Ant::IsWay(const string &c_name1,const string &c_name2)
{
bool res = false;
for(int i = 0;i < way.size()-1;i++)
if(way[i] == c_name1 && way[i+1] == c_name2)
res = true;
return res;
}
std::ostream& operator<<(std::ostream& out, const Ant &ant)
{
for(string temp:ant.way)
out << temp << " ";
out << ant.length << "km\n";
// out << std::endl;
return out;
}