Due Tuesday, 14 Sep 1999, at the beginning of class.
Read Chapter 2 of the textbook.
When submitting a program, please submit the program's code prepended
with comments briefly describing its input and output. Please indent
your code to make it readable. See Section 2.5 of the textbook for
style hints. If you desire, you can also submit examples
demonstrating your program's correctness.
- 1.
- A sequence begins 0, 1, 1, 2, 3, 5, 8, 13. Write a program
producing the first thirty entries in this sequence. What are they?
- 2.
- Write a program showing how to add all possible pairs of
hexadecimal digits. Print the sums one per line. The first and
second lines could be
0 + 0 = 0
0 + 1 = 1.
Be sure to print the answer using hexadecimal numbers.
- 3.
- Write a program to convert a Fahrenheit temperature to Celsius.
The Celsius temperature is
(5/9)(F - 32), where F is the
Fahrenheit temperature. The program should ask the user for the
Fahrenheit temperature and should print the temperature in Celsius.
- 4.
- Write a program to determine the largest and smallest possible
values that an int variable can attain on the computers we use
for class. What are the values? Another type is unsigned int,
which means that it only holds nonnegative values. What is the
largest value an unsigned int variable can hold?
- 5.
- In Norton Juster's children's story The Phantom
Tollbooth, the Mathemagician gives Milo the following problem to
solve:
4 + 9 - 2*16 + 1 / 3*6 - 67 + 8*2 - 3 + 26 - 1 / 34 + 3 / 7 + 2 - 5.
According to Milo's calculations, which are corroborated by the
Mathemagician, this expression ``all works out to zero.'' If you do
the calculation, however, the expression comes out to zero only if you
start at the beginning and apply all the operators in strict
left-to-right order. What would the answer be if the Mathemagician's
expression were evaluated using C++'s precedence rules?
In your answer, show the order the operations are performed. An easy
way to do this is to copy the entire expression and then replace the
performed operation by its value. Copy the resulting expression to
the next line and continue. (Using a text editor to copy the
expression may be useful.)
1999-09-06