In this assignment you are to implement two unrelated functions as
described below. Please submit each in a separate .cpp file as indicated.
For both parts of this assignment you should use one or more instances of
STL stack
.
Your are to implement the function mulitbaseOutput
, as
declared in assign1_a.h, to convert a positive
integer to a string representation in the given base. The following are
some test cases (note the result should not contain quote
characters, they're used in this table to make it clear that these are
strings):
num | b | result |
---|---|---|
12 | 10 | "12" |
12 | 2 | "1100" |
12 | 7 | "15" |
12 | 16 | "C" |
Note that the string representation returned should be only the number. No whitespace or extra characters should be included.
Submit an, appropriately commented, .cpp file called
assign1_a.cpp
containing only your
implementation of multibaseOutput
(i.e., not
main
).
Hints:
static const char *digits = "0123456789ABCDEF";
n
and b
, the
modulus operator, n % b
will give the
lowest-order digit in the base b
representation of
n
and n/b
will give the number to convert for the
higher order digits. For example, Write a function evaluate
as declared in
assign1_b.h to compute the value of a "fully
parenthesized numeric expression" using integer math.
A "fully parenthesized numeric expression" consists of only the following:
(((6 + 9)/3)*(6 - 4))
evaluate
for this expression should be
10.
Submit an, appropriately commented, .cpp file called
assign1_b.cpp
containing only your
implementation of evaluate
(i.e., not
main
).
Hint: Use two stacks: one to hold operands, and one to hold operators.
Be sure to include appropriate comments, including file and function header blocks (see Assignment Policies), and to use good style as outlined in Programming With Style. Submit your source code using Web Submit.
Last modified: Thu 2003.05.08 at 21:57 NDT by Dennis Peters