Homework assignment #2

Due Friday, October 29 by the beginning of class

  1. In the last assignment, we typed in a program to convert celsius to fahrenheit. The program used integers, but of course, temperatures are not always integers. Write a new version of the program so that it uses doubles, not ints. Specifically:
    1. the two variables fahrenheit and celsius should be declared as double
    2. the program should compile without errors or warnings
    3. the printed results should be accurate

    You may make any other changes necessary to achieve these three goals. Name the code file "dblftoc.cpp".

In order to print out double values, you will need to change the printf statement to this:

      printf ("%3.0f\t%6.1f\n", fahrenheit, celsius);

If you are using Visual C++, you may use this VC++ project, which is already set up with an empty file for your code, named dblftoc.cpp.
DoubleFtoC.zip

  1. In an early lecture, we saw the following program:
	/*
	 * This program prints a list of
	 * integers, from 0 to 9.
	 */

	#include <stdio.h>

	int main (void)
	{
	    int i;
	    for (i = 0; i < 10; i = i + 1)
	        printf (“i is %d\n”,    i);
	    return 0;
	} 

Type this program in and run it, to make sure it compiles without errors or warnings, and that it works correctly. Once you have done that, change the statement:

     for (i = 0; i < 10; i = i + 1)

to use either of the increment operators (preincrement or postincrement) or the += operator (you can choose which you'd like to use).

You may use this Visual C++ project for this question; it has been set up for you with a file named list.cpp.
List.zip


What I want you to turn in, and how:

The files I want to receive from you are dblftoc.cpp and list.cpp.

Turnin options are:

  1. As before, you may leave the files in a folder named Homework\HW2 in your cs5a account's home directory. This is the preferred method of turning in your homework.
  2. You may also email the two files (in a single e-mail message, please!) to cs5a@ieng9.ucsd.edu
  3. If you can't do either of those, you may bring me a PC-format floppy disk in class.