You are on page 1of 4

# Project 2 – Time Calculator

Objective

To gain experience and practice using pass-by-value and pass-by-reference functions.

Problem

You have been hired by a local mechanical watch company. They are interested in expanding to
digital watches to grow their business. The would like you to write a program which can set the
current time, calculate time deltas, and display times.

Specifications

For your program, you will need to implement the following functions:

 void calcDeltaFutr(int h, int m, int deltaH, int deltaM,
int& hNew, int& mNew);
h and m are the current times. deltaH and deltaM are the amount of time into the
future you are trying to calculate. hNew and mNew will store the future time once all
the necessary calculations are done.
 void calcDeltaPast(int h, int m, int deltaH, int deltaM,
int& hNew, int& mNew);
h and m are the current times. deltaH and deltaM are the amount of time into the
past you are trying to calculate. hNew and mNew will store the past time once all the
necessary calculations are done.
 void getTime(int &h, int &m, bool mode);
h and m store the time that the user enters. mode is used to decide if you allow the
user to enter the time in 12h mode or 24h mode.
 void rollTimeForward(int& h, int& m);
h and m are the hours and minutes for a time. This function will take values of h and m
that are larger than 24 and 60, respectively, and roll them around until they are on the
intervals [0,23] and [0,59], respectively. Note than you can use the % operator to take
the remainder when dividing by a number. For instance, if m = 70, then this should be
converted to m = 10 and h = h + 1. To achieve this, you could do h = h + m %
60 and then m = m % 60. This function should be called right at the end of the
calcDeltaFutr function.
 void rollTimeBack(int& h, int& m);
Similar to rollTimeForward, this function deals with values of h and m that are
negative and rolls them around so that they are on the intervals [0,23] and [0,59],
respectively. This function should be called right at the end of the calcDeltaPast
function. Make sure you work though all the edge cases that this function might
encounter. This function can get messy if not all situations are taken into account.
 void printTime(int h, int m, bool mode);

Exit > 2 Enter an increment of hours and minutes (separated by a space): 2 20 . Display current time 5 .Add delta to time 3 . (2) add a forward delta to the “current time”.Toggle 24-hour mode 6 . the “current time” should be stored in 24-hour format.Add delta to time 3 . In this project. mode specifies if the time should be printed in 12-hour or 24-hour format. only allow hours between 0 and 23 and minutes between 0 and 59.Display current time 5 . Sample Output: Normal Operation (user input in italics) 1 . When entering the current time. only allow positive values or 0 (this is true for both forward and backwards time deltas). (4) display the current time. The program should identify invalid input for the main menu.Subtract delta from time 4 . Enter a time 2 .Toggle 24-hour mode 6 .Subtract delta from time 4 . Exit > 4 The current time is 05:50 1 . (3) add a backwards delta to the “current time”. h and m are the hours and minutes component of the time to be printed. Add delta to time 3 . Accept only ‘a’ and ‘p’ when entering the time in 12-hour mode. Only when the user actually interacts with the program will the output and input be sometimes in 12-hour format.Enter a time 2 .Add delta to time 3 .Exit > 2 Enter an increment of hours and minutes (separated by a space): 0 120 The new time would be 07:50 1 .Display current time 5 . Toggle 24-hour mode 6 . (5) toggle the interface mode between 24-hour and 12-hour (should impact both getTime and printTime).Enter a time 2 . When entering time deltas.Toggle 24-hour mode 6 . Implement a main menu that will allow the user to (1) enter the current time.Subtract delta from time 4 .Enter a time 2 .Display current time 5 . Subtract delta from time 4 .Exit > 1 Enter the time with whitespace separating the hours and minutes: 5 50 1 .

Enter a time 2 .Toggle 24-hour mode 6 .Exit > 6 Exiting.Display current time 5 .Exit > 5 12-hour mode turned on 1 ..Toggle 24-hour mode 6 . Enter a time 2 . Toggle 24-hour mode 6 .Add delta to time 3 .Toggle 24-hour mode 6 .Add delta to time 3 . .Enter a time 2 . Add delta to time 3 ..Display current time 5 . Subtract delta from time 4 . Display current time 5 .Subtract delta from time 4 .Exit > 3 Enter a decrement of hours and minutes (separated by a space): 0 90 The new time would be 10:45 pm 1 .Subtract delta from time 4 .Display current time 5 .Enter a time 2 .Exit > 1 Enter the time with whitespace separating the hours.Exit > 3 Enter a decrement of hours and minutes (separated by a space): 1 15 The new time would be 11:00 pm 1 . Tips  Make sure to write your other functions before you write your int main.Toggle 24-hour mode 6 .Subtract delta from time 4 . and either 'a' for am or 'p' for pm: 0 15 a 1 .Subtract delta from time 4 .Enter a time 2 .Display current time 5 . Exit > 4 The current time is 12:15 am 1 .Enter a time 2 .Add delta to time 3 .Add delta to time 3 .Toggle 24-hour mode 6 .Subtract delta from time 4 . minutes.Display current time 5 .Add delta to time 3 . The new time would be 08:10 1 .

Deliverables  (15 points) A project report discussing what your program does. and why you designed it the way you did. Shoot for something in the 1-2 page range. PDF format. how it does it. . make sure to test all edge cases.cpp. Reflect on how the project would be different if you had not used loops and functions methods. Make sure to name it project2_yourlastname.  When implementing each function.  (85 points) Your c++ source code (the .cpp file). This is especially important for the rollForward and rollback functions as they have perhaps the most complicated functionality of any of the functions used in this project.