AIVQ3 - return 0 time24:time24(int h int m hour=h minute=m...

Info icon This 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");
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern