Homework One

The objective of this homework assignment is to become familiar with the tools you will use for the rest of the course. Find a convenient place to do your C++ homework. Become familiar with the C++ compiler by doing Programming Projects 1, 2, 3 and 4 from Chapter 1 of Savitch. Hand in a printout of your code for parts 2 and 4.

Here is the text of the Programming Projects for people who don't have the textbook yet:

  1. Using your text editor, enter (i.e., type in) the C++ program shown in Display 1.8 [there is a copy of the program in the Samples section of this website.] Be certain to type the first line exactly as shown. In particular, be sure that the first line begins at the left-hand end of the line with no space before or after the # symbol. Compile and run the program. If the compiler gives you an error emessage, correct the program and recompile the program. Do this until the compiler gives no error messages. Then run your program.

  2. Modify the C++ program you entered [above]. Change the program so that it first writes the word Hello to the screen and then goes on to do the same things that the program in Display 1.8 does. You will only have to add one line to the program to make this happen. recompile the changed program and run the changed program. Then, change the program even more. Add one more line that will make the program write the word Good-bye to the screen at the end of the program. Be certain to add the symbols \n to the last output statement so that it reads as follows:

    cout << "Good-bye\n";
    (Some systems require that final \n and your system may be one of the systems that requires a final \n.) Recompile and run the changed program.

  3. Modify the C++ program that you entered in Programming Project 1 or 2 [above]. Change the multiplication sign * in your C++ program to the addition sign +. Recompile and run the changed program. Notice that the program compiles and runs perfectly fine, but the output is incorrect. That is because this modification is a logic error.

  4. Write a C++ program that reads in two integers and then outputs both their sum and their product. One way to proceed is to start with the program in Display 1.8 and then modify that program to produce the program for this project. [See the first project for hints.]