CS1210 – C++ Programming

Homework #3

Due: As Indicated on Course Web Site

Points: 30

Objective: Develop three C++ programs practice with C++ I/O, selection and iteration.

Discussion: In this assignment you’ll develop three separate programs with each one building upon the one that precedes it. The first program is to prompt the user for two integer numbers and then display the sum and product of those numbers. The second program extends the first by asking the user whether he/she wants to display the sum (s) or product (p). The third program extends the second to allow the user to repeat calculations as often as they would like.

Example: You can run examples of each of the programs online from the directory /home/shomperk/CS1210/public. In that directory you’ll find the three programs. Their names are hw3.1, hw3.2 and hw3.3. Samples of their output appear below (the bold text is assumed to be typed by the user of the program:

hw3.1:

Please enter an integer: 3

Please enter another integer: 4

The sum of 3 and 4 is 7

The product of 3 and 4 is 12

hw3.2:

Please enter an integer: 4

Please enter another integer: 5

Do you want to compute the sum (s) or the product (p)

of the numbers you entered? p

The product of 4 and 5 is 20

hw3.3:

Please enter an integer: 4

Please enter another integer: 5

Do you want to compute the sum (s) or the product (p)

of the numbers you entered? s

The sum of 4 and 5 is 9

Would you like to compute another sum or product (y/n)? y

Please enter an integer: 7

Please enter another integer: 8

Do you want to compute the sum (s) or the product (p)

of the numbers you entered? p

The product of 7 and 8 is 56

Would you like to compute another sum or product (y/n)? n


Additional Details:

a.  Submit the source code of all three programs to your instructor using the “submit” command by the beginning of class on the due date indicated on the course web.

b.  Turn in a hardcopy listing of your program on the same day.

c.  Please be sure to properly comment your program and use appropriate white space.

d.  All work (including typing the program with Chameleon or gedit) should be done on james or john to increase your familiarity with that environment.

e.  If you would like to submit only one file, you can combine the files using the linux “cat” command. For example, the command

cat hw3.1.cpp hw3.2.cpp hw3.3.cpp > hw3.cpp

will combine all three source files into a single file called hw3.cpp which you can then submit.