CS 1320 (Principles of Algorithm Design I):
Homework #2
- Assigned:
- September 15, 1999
- Due:
- September 22, 1999, at start of class.
(New due date: September 24, 1999.)
- Credit:
- 30 points.
Programming problems
- Credit:
- 10 points each.
- Instructions:
- Write a C++ program to solve each of the problems below.
See the
guidelines for
programming assignments for what to turn in.
Your code should begin with comments that describe
what the program is supposed to do (not how
it does it, but what it does -- i.e., its
input and output).
See the
sample programs
for examples.
Problem: Largest and smallest numbers
Write a program to compute and print the following:
- The largest number that can be represented by the C++ integer
type (int).
- The smallest number that can be represented by the C++ integer
type (i.e., the negative number with the largest absolute
value).
- The largest number that can be represented by the C++ unsigned
integer type (unsigned). (This is a type that
represents non-negative numbers only).
Seconds to years, etc. conversion
Write a program that prompts the user for a number of seconds S
(S should be a non-negative integer) and prints S in a more normal
notation -- years, days, hours, minutes, and seconds. You may
ignore leap years and seconds. For example, 100 seconds is 1 minute
and 40 seconds. (You may be interested to run this program using
successive powers of 10 as input and see how long it takes before
seconds start to add up to years.)
Temperature conversion, revisited
Modify the program you wrote in Homework #1 to convert Fahrenheit to
Celsius as follows:
- Have it accept and print floating-point numbers (i.e., numbers
with a decimal point). Print the results with one decimal
place.
- Have it accept and convert a sequence of temperatures rather than
a single temperature. That is, rather than prompting the
user for a single number and calculating and printing the
result, it should prompt for a sequence of numbers, one
at a time, calculating and printing results as it goes.
You can decide how the user should signal "no more" (we
have discussed, or will discuss, two methods in class).
Document your choice in the program's header.
- Have it also compute and print, after the
user has signalled "no more":
- The smallest temperature entered by the user.
- The largest temperature entered by the user.
- The average temperature entered by the user.