TIME MACHINE NOTES Time Machine Enter start time

  • Slides: 10
Download presentation
TIME MACHINE NOTES

TIME MACHINE NOTES

Time Machine Enter start time, in the format 'HH: MM xm', where 'xm' is

Time Machine Enter start time, in the format 'HH: MM xm', where 'xm' is either am or pm. O 4: 30 am integer char am. Pm. Char; // am/pm character char extra; // extra character ‘: ’

Pre and Post conditions // Precondition // Postcondition void read. Time(int& hours, int& minutes,

Pre and Post conditions // Precondition // Postcondition void read. Time(int& hours, int& minutes, bool& ampm);

int start. Hours; int start. Minutes; bool start. Is. AM; int end. Hours; int

int start. Hours; int start. Minutes; bool start. Is. AM; int end. Hours; int end. Minutes; bool end. Is. AM; // // // Starting time hours Starting time minutes Starting time am/pm Ending time hours Ending time minutes Ending time am/pm // Call the read. Time function read. Time(start. Hours, start. Minutes, start. Is. AM); read. Time(end. Hours, end. Minutes, end. Is. AM);

// Function that computes the difference // between two times int compute_difference(int start. Hours,

// Function that computes the difference // between two times int compute_difference(int start. Hours, int start. Minutes, bool start. Is. AM, int end. Hours, int end. Minutes, bool end. Is. AM); Called like this diff = compute_difference(start. Hours, start. Minutes, start. Is. Am, end. Hours, end. Minutes, end. Is. Am);

Pre and Post conditions // Precondition // Postcondition int compute_difference(int start. Hours, int start.

Pre and Post conditions // Precondition // Postcondition int compute_difference(int start. Hours, int start. Minutes, bool start. Is. AM, int end. Hours, int end. Minutes, bool end. Is. AM);

// A helper function, to return the // number of minutes since midnight int

// A helper function, to return the // number of minutes since midnight int minutes_since_midnight(int hours, int minutes, bool is. AM);

Pre and Post conditions // Precondition // Postcondition int minutes_since_midnight(int hours, int minutes, bool

Pre and Post conditions // Precondition // Postcondition int minutes_since_midnight(int hours, int minutes, bool is. AM);

Project Hints start = minutes_since_midnight (start. Hours, start. Minutes, start. Is. AM); end =

Project Hints start = minutes_since_midnight (start. Hours, start. Minutes, start. Is. AM); end = minutes_since_midnight (end. Hours, end. Minutes, end. Is. AM); diff = end - start; // // If start and end were on opposite sides of midnight, then the difference will be negative. In this case we have to add back a day.

// Total number of minutes in an hour and day const int MINUTES_IN_HOUR =

// Total number of minutes in an hour and day const int MINUTES_IN_HOUR = 60; const int MINUTES_IN_DAY = 24 * MINUTES_IN_HOUR; int diff; int hours; int minutes; // difference // hours // minutes