-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition.cpp
More file actions
55 lines (47 loc) · 1.34 KB
/
position.cpp
File metadata and controls
55 lines (47 loc) · 1.34 KB
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
/***********************************************************************
* Source File:
* Point : The representation of a position on the screen
* Author:
* Br. Helfrich
* Summary:
* Everything we need to know about a location on the screen.
************************************************************************/
#include "position.h"
#include <cassert>
Position::Position(double x, double y) : x(0.0), y(0.0)
{
setMetersX(x);
setMetersY(y);
}
/******************************************
* POINT : ASSIGNMENT
* Assign a point
*****************************************/
Position& Position::operator = (const Position& pt)
{
x = pt.x;
y = pt.y;
return *this;
}
/******************************************
* POSITION insertion
* Display coordinates on the screen
*****************************************/
std::ostream& operator << (std::ostream& out, const Position& pt)
{
out << "(" << pt.getMetersX() << "m , " << pt.getMetersY() << "m)";
return out;
}
/*******************************************
* POSITION extraction
* Prompt for coordinates
******************************************/
std::istream& operator >> (std::istream& in, Position& pt)
{
double x;
double y;
in >> x >> y;
pt.setMetersX(x);
pt.setMetersY(y);
return in;
}