CSC 221: Computer Programming I
Fall 2001

HW2: Programs with Computation


For this assignment, you are two write two small programs that prompt the user for numeric values, perform computations on those values, and display the (formatted) results.

Part 1: Growing old

Write a C++ program called ages.cpp that asks for a person's age (an integer) and prints out that age using different units of time. In particular, the program should print out the person's age in months, in days, in hours, in minutes, and in seconds. To simplify matters, you may ignore leap years and assume that every year is 365 days long. For example, if the user enters 20 for their age, the output of the program should appear as:

How many years old are you? 20 20 years is equivalent to: 240 months or 7300 days or 175200 hours or 10512000 minutes or 630720000 seconds

Hint: use separate variables for each of the intermediate numbers. For example, once you have computed the number of days, it is fairly simple to compute the number of hours (24 * days); then minutes (60 * hours) and seconds (60 * minutes).


Part 2: Making the grade

Write a C++ program called grades.cpp that can be used to compute your average for this course. The program should prompt the user for their quiz average, homework average, test1 score, test 2 score, and final exam score. Using the weightings posted in the class syllabus, the program should compute and display the overall average for the course (with 1 digit to the right of the decimal place). For example,

Quiz average: 84.5 HW average: 87.0 Test 1: 81 Test 2: 90 Final exam: 94 Your overall average is 87.7

You should use constants for the various weightings so that changing any of the weights would be simple.