Homework assignment #1

Due Monday, October 18 by the beginning of class


All answers (files) should be stored in a folder named H:\Homework\HW1

  1. Get a copy of the file id.txt (by clicking on the link to the left, and saving the file). The file should be saved as:

H:\Homework\HW1\id.txt

Edit the file to add your name, computer account name (cs5a??), and preferred e-mail address. The e-mail address can be your cs5a computer account (cs5a??@ieng9.ucsd.edu) or it could be your own e-mail address. This will be the address we will send homework scores to.

  1. Compile and run the following program (which is very similar to the Fahrenheit-to-Celsius conversion program from page 9 (section 1.2) of your text). Store the program file as ftoc.cpp, and also create a file named ftoc.txt, containing the output you get when you run this program.
    /*
     * FtoC1 – print a Fahrenheit-to-Celsius
     * conversion table
     */
    
    #include <stdio.h>
    
    int main (void)
    {
        int fahr;
        int celsius;
        int lower = 10;
        int upper = 300;
        int step = 27;
    
        fahr = lower;
        while (fahr <= upper) {
            celsius = 5 * (fahr - 32) / 9;
            printf ("%d\t%d\n", fahr, celsius);
            fahr = fahr + step;
        }
        return 0;
    } 

    Once you have this program working, modify the line

celsius = 5 * (fahr - 32) / 9;

so that it reads:

    celsius = (5/9) * (fahr - 32);     

and run the program now. What does the output look like this time? Write a sentence or two in ftoc.txt that describes the output.

For extra credit, try changing the program so that a heading gets printed above the table. It could look something like this:

 F    C
--- --- ... and then the temperature table.