/********************************************************************************************
compass.h
Jim Millard
Practical 10
********************************************************************************************/
#include "compass.h"
#include <iostream>
using namespace std;
//------- Enhanced Default Constructor -------
compass::compass(const int d, const int m, const int s) {
degree=0;
minute = 0;
second = 0;
addSecond(s);
addMinute(m);
addDegree(d);
}
//------- Print the object in "pretty" format -------
void compass::print(ostream& out) const {
if (degree < 100)
out << '0';
if (degree < 10)
out << '0';
out << degree << '\370';
if (minute < 10)
out << '0';
out << minute << '\'';
if (second < 10)
out << '0';
out << second << '\"';
};
//------- "managed" addition functions -------
void compass::addDegree(const int d) {
degree = (degree + d) % 360;
}
void compass::addMinute(const int m) {
addDegree((minute + m) / 60);
minute = (minute + m) % 60;
}
void compass::addSecond(const int s) {
addMinute((second + s)/60);
second = (second + s) % 60;
}
void compass::addSame(const compass& C) {
addDegree(C.degree);
addMinute(C.minute);
addSecond(C.second);
}