-
Notifications
You must be signed in to change notification settings - Fork 0
/
Location.cpp
50 lines (38 loc) · 881 Bytes
/
Location.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
/*
* Roni Fultheim, ID: 313465965
* Location.cpp
*/
#include "Location.h"
using namespace std;
Location::Location (int row, int col): row_(row), col_(col) {}
void Location::set(int row, int col) {
row_ = row;
col_ = col;
}
void Location::set(Location& loc) {
set(loc.row(), loc.column());
}
void Location::increment(int incR, int incC) {
row_ += incR;
col_ += incC;
}
int Location::column() const {
return col_;
}
int Location::row() const {
return row_;
}
bool Location::operator ==(const Location &loc) const {
//compare rows and columns
return (loc.row() == row_ && loc.column() == col_);
}
bool Location::operator !=(const Location &loc) const {
//use == operator for
return !(*this==loc);
}
ostream &operator <<(ostream &out, const Location &loc)
{
//translate from c++ indexing
out << "(" << loc.row_+1 << "," << loc.col_+1 << ")";
return out;
}