AIVQ3 - return 0; } time24::time24(int h, int m){ hour=h;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> using namespace std; class time24 { private: int hour; int minute; public: time24(int h=0, int m=0); time24 operator + (const time24& y); time24 operator - (const time24& y); friend istream& operator >> (istream& , time24& ); friend ostream& operator << (ostream& ,const time24& ); }; int main () { ofstream fout ("time24.out"); time24 x, y, z; int a; cout << "Enter two times in the form hour:minute\n"; cin >> x >> y; fout << "The time24 x is: " << x << endl; fout << "\nThe time24 y is: " << y << endl; z = x + y; fout << "\nThe time24 z now is: " << z << endl; z = x - y; fout << "\nThe time24 z now is: " << z << endl; system("notepad time24.out");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return 0; } time24::time24(int h, int m){ hour=h; minute=m; } istream& operator >> (istream& in, time24& a){ char t; in>>a.hour>>t>>a.minute; return in; } ostream& operator << (ostream& out,const time24& a){ out<<a.hour<<":"<<a.minute<<endl; return out; } time24 time24::operator +(const time24& y){ time24 z; int tm=minute+y.minute; z.minute=tm%60; z.hour=((hour+y.hour)+tm/60)%24; return z; } time24 time24::operator -(const time24& y){ time24 z; int tm=minute-y.minute; if(tm<0){ tm=tm+60; z.hour=-1; } z.minute=tm; z.hour=z.hour-y.hour+hour; if(hour<=y.hour) z.hour=z.hour+24; return z; }...
View Full Document

This note was uploaded on 02/21/2010 for the course ENGM 2282 taught by Professor Phillips during the Winter '10 term at Dalhousie.

Page1 / 2

AIVQ3 - return 0; } time24::time24(int h, int m){ hour=h;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online