Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
// A little class that does some 2d Point arithmetic
2
#ifndef POINT_H
3
#define POINT_H
4
5
#include <iostream>
6
7
class Point {
8
public:
9
//overloaded constructors!
10
Point();
11
Point(double _x, double _y);
12
13
//overloaded methods for accessing x and y
14
double x();
15
void x(double val);
16
double y();
17
void y(double val);
18
19
//overloaded addition and subtraction operators
20
Point operator+(Point &rhs);
21
Point &operator+=(Point &rhs);
22
Point operator-(Point &rhs);
23
Point &operator-=(Point &rhs);
24
25
private:
26
//private attributes of the class
27
double _x;
28
double _y;
29
};
30
31
32
//insertion operator (NOTE: This is not a member.)
33
std::ostream& operator<<(std::ostream &os, Point &rhs);
34
#endif
35
36