Programming Homework 1

This assignment is due by the start of class on Friday, February 7. You are encouraged to do this homework with your partner, and you are welcome to get help on it during the lab time Tuesday. The purpose of this assignment is to get practice writing your own programs. You will need to be able to write out a program like this on paper for the first exam, so you might want to approach this homework by writing out your solution on paper before going to the lab to type it in and test it.

Submit a printout of your solution to the problem below. Make sure that your name and account name are in comments at the top; for example,

/* Description: Programming Homework 1
   Filename:    program1.cpp
   Account:     CSC121xx
   Author:      Your Name
   Date:        Today
*/
If you work with your partner, you only need to submit one copy of the program; be sure that both of your names are listed in the comments (the account name should be the one in which the solution is stored).

You should start by copying the folder called Program1 from my public directory, I:\CSC121\public\Howard\, into your own folder, I:\CSC121\CSC121xx\. When you open your copy of the project, by following the same instructions as for the labs, you should see the comments shown above; modify them as needed and continue writing your program.

This first program will be graded on two criteria: the program should produce the correct output for any reasonable input, and the program should be structured with at least two functions besides main, as described below.

The assignment is to produce a temperature conversion program. When the program starts, there should be a function to greet the user and explain what the program is going to do. Then there should be a second function which asks the user for a temperature, f, in degrees Fahrenheit, calculates the equivalent temperature in degrees Celsius using the formula c = (f - 32) * 5 / 9, and displays the result.

You may follow the grade average program discussed in class as a model. If you want to look at that program, it is stored in I:\CSC121\public\Howard\Jan31\.

For extra practice (though not for extra credit), modify the program to also ask for a temperature in Celsius and convert it back to Fahrenheit. The formula you will need is f = 32 + c * 9 / 5. For the more adventurous, use the material from this week on loops to add a graphical display of the temperature. For example, with an input of 59o F, the output might be

The equivalent temperature is 15 degrees Celsius:
-20       -10       0         10        20        30        40
************************************
(Hint: with the scale shown here, there are 21 + c stars to represent the temperature c.) Don't worry about fractional temperatures, or about temperatures that would go off the scale (either too low or too high); we will talk about mechanisms to handle such cases in a few weeks.