-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.cpp
79 lines (73 loc) · 1.24 KB
/
Point.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
/**
* Point.cpp
* Project UID 8b3bcc444eb500121e420f7e2e359014
*
* EECS 183, Fall 2019
* Project 4: CoolPics
*
* Tin Long Rex Fung, Isaac Lok-Tin Li
* rexfung, isaliac
*
* This file contains the class "Point"
*/
#include "Point.h"
// for the declaration of DIMENSION
#include "utility.h"
Point::Point() {
x = 0;
y = 0;
}
Point::Point(int xVal, int yVal) {
x = checkRange(xVal);
y = checkRange(yVal);
}
void Point::setX(int xVal) {
x = checkRange(xVal);
return;
}
int Point::getX() {
return x;
}
void Point::setY(int yVal) {
y = checkRange(yVal);
return;
}
int Point::getY() {
return y;
}
void Point::read(istream& ins) {
char temp;
int xVal;
int yVal;
ins >> temp >> xVal >> temp >> yVal >> temp;
x = checkRange(xVal);
y = checkRange(yVal);
return;
}
void Point::write(ostream& outs) {
outs << '(' << x << ',' << y << ')';
return;
}
int Point::checkRange(int val) {
if (val < 0) {
return 0;
}
else if (val > DIMENSION - 1) {
return DIMENSION - 1;
}
else {
return val;
}
}
// Your code goes above this line.
// Don't change the implementations below!
istream& operator >> (istream& ins, Point& pt)
{
pt.read(ins);
return ins;
}
ostream& operator<< (ostream& outs, Point pt)
{
pt.write(outs);
return outs;
}