am or pm. For example, 1:32pm.
We haven't taught you a way to combine an integer and a string.
Include the procedure digitToString before your
main():
#include <string>
string digitToString (int digit) {
assert (digit >= 0 && digit <= 9);
static string dummy = "X";
dummy[0] = '0' + digit;
return dummy;
}
You should now be able to type:
string five = digitToString (0) + digitToString(5); cout << five << endl;Hint: You'll want to use
n % 10 and n / 10
to extract individual digits.
gdb, since
gdb allows you to change the values of variables
while running a program, without changing the program! To do
this,
gdb
now, is declared.
gdb
now by using gdb's
set command.
set expressionFor expression, you can use any
C++ expression,
but you may need to be specific about adding the class name to a
method. For example, in some debuggers you must type,
print now.Time::get_hours()
In this case, a useful expression would add, say,
60 * 60 * 12 seconds to the time to make your program
think its 12 hours later. (If you have troubles doing this, ask!)
This technique is a good one for debugging code, since you don't have to actually change the code to test it. Were you to change the code to (temporarily) hardwire a time, you might forget to fix it again later.
set in
gdb to test the am/pm part of your code.
For this part, you need to learn how to use the inverse of the
tan in C++. There are two functions which
might come in handy, which I found by the man command in
Linux (or M-x man in emacs). I typed
man -k atanto get a list of all manual pages which mention the
atan
function. There are two that are relevant, atan and
atan2. Before embarking on the program, be sure to
figure out which of the two is more useful. Inspect the individual
manual pages by typing:
man atan man atan2