Homework 4

1.  Complete the following table. The first three rows are already filled in.

Expression

Data Type of the result of the expression

Value of the expression

1 / 2

int

 0   (integer division,  / returns the number of 2s that can be taken out of 1)

1 % 2

int

  1   (% returns the remainder after taking as many 2s out of 1 as you can)

1.0 / 2

double

  0.5   (“normal” floating point division due to 1.0)

 5 + 7 / 2

 

 

"Beat" + ' ' + "Army"

 

 

6 + 13 / 5 - 35 % 3

 

 

3.5 * (5/4)

 

 

(3.5 * 5)/4

 

 

 

2. Write a RAPTOR flowchart that reads in two lengths in the format x' y" (i.e. x feet y inches) and returns the difference in length 
between the two in the same format. You may assume that the first is always larger than the second!
See hint 1 and hint 2 below. For example, if the user enters 32' 6" and 15' 11" the result should be 16' 7"
 
 

3. Write a C++ program for the problem in question 2.  See hint 3 and hint 4 below. A typical run of your program should look like this (user input shown in red):

     Enter two lengths in feet and inches (larger first!)
     32' 6"
     15' 11"

          Difference is 16' 7"

 

4. A reminder to complete the pre-lab homework for lab2.

Turn In (all stapled together with your name and alpha code on it):

1.      A copy of this homework assignment with Table 1 filled in.

2.      A screen capture of your flowchart from question 2.

3.      A printout of your source code from question 3.

4.      A screen capture of your program from question 3 running on the example input from question 3.