Assignment 2
Assignment 2
To be discussed in Tutorials:
Exercise 2-1 Errors
Beside each code fragment in the table below, write what is printed when the code fragment is
executed. If the code would cause an error, write ERROR and give a brief explanation.
Example:
diameter = 13
height = 50
output: Your stove needs: 13.2665 minutes to bring the water to boil.
a = m2 − n2
b = 2×m×n
p
c = a 2 + b2
Write an algorithm that reads in values for m and n and prints the values of the Pythagorean
Triple generated by the formulae above.
Extra Exercises:
• Step 1: Calculate How Much has the Consumer Price Index Increased?
By looking at the above example, common sense would tell us that the index increased (it
went from 100 to 198). The question is how much has it increased? To calculate the change
we would take the second number (198) and subtract the first number (100). The result
would be 98. So we know that from 1984 until 2014 prices increased (Inflated) by 98 points
• Step 2: Comparing the CPI Change to the Original CPI
Since we know the increase in the Consumer Price Index we still need to compare it to
something, so we compare it to the price it started at (100).We do that by dividing the
increase by the first price or 98/100. the result is (.98).
• Step 3: Convert it to a Percentage
This number is still not very useful so we convert it into a percentage. To do that we multiply
by 100. So the result is a 98 increase in prices since 1984.
Write an algorithm that given two prices of the same item in two different years computes the CPI.
The algorithm should display the following for the example above