AIIIQ3 - z.write(fout); fout.close();...

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; u class time24 { private: int hour; int minute; public: time24(int h = 0 , int m = 0); void write(ostream& out); time24 add(const time24& y); time24 minus(const time24& y); }; int main () { ofstream fout ("time24.out"); time24 x(18, 34), y(10,56), z; fout << "The time24 x is: "; x.write(fout); fout << "\nThe time24 y is: "; y.write(fout); z = 12; fout << "\nThe time24 z is: "; z.write(fout); z = x.add(y); fout << "\nThe time24 z now is: "; z.write(fout); z = x.minus(y); fout << "\nThe time24 z now is: ";
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: z.write(fout); fout.close(); system(&quot;notepad time24.out&quot;); return 0; } time24::time24(int h, int m){ hour=h; minute=m; } void time24::write(ostream&amp; out){ out&lt;&lt;hour&lt;&lt;&quot;:&quot;&lt;&lt;minute&lt;&lt;endl; } time24 time24::add(const time24&amp; y){ time24 z; int tm=minute+y.minute; z.minute=tm%60; z.hour=((hour+y.hour)+tm/60)%24; return z; } time24 time24::minus(const time24&amp; y){ time24 z; int tm=minute-y.minute; if(tm&lt;0){ tm=tm+60; z.hour=-1; } z.minute=tm; z.hour=z.hour-y.hour+hour; if(hour&lt;=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

AIIIQ3 - z.write(fout); fout.close();...

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