-
Notifications
You must be signed in to change notification settings - Fork 1
/
NumberWithUnits.hpp
58 lines (48 loc) · 2.86 KB
/
NumberWithUnits.hpp
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
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
namespace ariel{
class NumberWithUnits{
private:
double num;
string the_unit;
public:
NumberWithUnits(const double& value, const string& unit);
NumberWithUnits(){}
~NumberWithUnits(){}
static double convert(const std::string &from, const std::string &to, double fromVal);
static void read_units(ifstream& file);
friend int comparison(const NumberWithUnits& n1, const NumberWithUnits& n2);
// in/out
friend ostream& operator<<(ostream& os, const NumberWithUnits& unit);
friend istream& operator>>(istream& in, NumberWithUnits& unit);
// plus/minus
friend NumberWithUnits operator+(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend NumberWithUnits operator+(const NumberWithUnits& unit, double num);
NumberWithUnits& operator+=(const NumberWithUnits& unit2);
friend NumberWithUnits operator-(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend NumberWithUnits operator-(const NumberWithUnits& unit1, double num);
NumberWithUnits& operator-=(const NumberWithUnits& unit2);
const NumberWithUnits operator+() const{
return NumberWithUnits(+num, the_unit);
}
const NumberWithUnits operator-() const{
return NumberWithUnits(-num, the_unit);
}
// bool operators
friend bool operator>(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend bool operator<(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend bool operator>=(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend bool operator<=(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend bool operator==(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
friend bool operator!=(const NumberWithUnits& unit1, const NumberWithUnits& unit2);
// increment/decrement
friend NumberWithUnits& operator++( NumberWithUnits& number);
friend NumberWithUnits operator++( NumberWithUnits& number, int);
friend NumberWithUnits& operator--( NumberWithUnits& number);
friend NumberWithUnits operator--( NumberWithUnits& number, int);
friend NumberWithUnits operator*(const NumberWithUnits& unit, double n);
friend NumberWithUnits operator*(double n, const NumberWithUnits& unit);
};
}