Chapter 2 Projects: 1. (After 2.7) Annual Bonus Flowchart
Chapter 2 Projects: 1. (After 2.7) Annual Bonus Flowchart
Sound Velocity
5950 meters/sec
2350 meters/sec
1531 meters/sec
331.5 + 0.6 x T meters/sec, where T is the temperature in degrees Celsius
Draw a flowchart that uses this table to calculate the speed of sound in various materials. More
specifically, read in a material value and output the speed of sound in that material. For air
calculations, youll need to read in a second value temperature in degrees Celsius.
Sound Velocity
5950 meters/sec
2350 meters/sec
1531 meters/sec
331.5 + 0.6 x T meters/sec, where T is the temperature in degrees Celsius
Write pseudocode that uses this table to calculate the speed of sound in various materials. More
specifically, read in a material value and output the speed of sound in that material. For air
calculations, youll need to read in a second value temperature in degrees Celsius.
8. [after 2.7] Stock Market Return Flowchart **:
Stock market analysts sometimes characterize stock market growth using the terms bear, stagnant,
bull, and boom. A bear market refers to a market with significant negative growth. A stagnant market
refers to a market with little negative or positive growth. A bull market refers to a market with
significant positive growth. A boom market refers to a market with very high growth.
Stock market growth varies widely from year to year, and the following table presents evidence of
that phenomenon. The table documents annual rate of return statistics for the S&P 500 stock market
index during the 40-year period, 19511990. The tables first row shows that an annual return rate of
less than -10% occurred 10% of the time. The volatility of stock market growth is evidenced by the
fact that stagnant markets (annual return rates between -10% and +10%) only occurred 30% of the
time.
Probability That Annual Return on
Market
Range of Return
Investment Falls within The Range
bear
less than -10%
10%
stagnant
between -10% and +10%
30%
bull
between +10% and +30%
43%
boom
greater than +30%
17%
Draw a flowchart for an algorithm that uses this table to print the type of market that exists for a
given annual return on a stock market index. More specifically, read in an annual return value and
print this message:
The rate of return is indicative of a ____ market (which occurs ____ of the time).
Replace the first blank with one of the four market categories. Replace the second blank with the
appropriate value from the tables third column.
9. [after 2.7] Stock Market Return Pseudocode **:
Stock market analysts sometimes characterize stock market growth using the terms bear, stagnant,
bull, and boom. A bear market refers to a market with significant negative growth. A stagnant market
refers to a market with little negative or positive growth. A bull market refers to a market with
significant positive growth. A boom market refers to a market with very high growth.
Stock market growth varies widely from year to year, and the following table presents evidence of
that phenomenon. The table documents annual rate of return statistics for the S&P 500 stock market
index during the 40-year period, 19511990. The tables first row shows that an annual return rate of
less than -10% occurred 10% of the time. The volatility of stock market growth is evidenced by the
fact that stagnant markets (annual return rates between -10% and +10%) only occurred 30% of the
time.
Probability That Annual Return on
Market
Range of Return
Investment Falls within The Range
bear
less than -10%
10%
stagnant
between -10% and +10%
30%
bull
between +10% and +30%
43%
boom
greater than +30%
17%
Write pseudocode for an algorithm that uses this table to print the type of market that exists for a
given annual return on a stock market index. More specifically, read in an annual return value and
print this message:
The rate of return is indicative of a ____ market (which occurs ____ of the time).
Replace the first blank with one of the four market categories. Replace the second blank with the
appropriate value from the tables third column.
10. [after 2.8] Bank Balance Pseudocode **:
The First National Bank of Parkville recently opened up a new So You Want to Be a Millionaire
savings account. The new account works as follows:
The bank doubles the customers balance every year until the customers balance reaches one
million.
The customer isnt allowed to touch the money (no deposits or withdrawals) until the customers
balance reaches one million.
If the customer dies before becoming a millionaire, the bank keeps the customers balance.
(Note: Customers close to $1,000,000 tend to get run over in the banks parking lot.)
Write an algorithm (using pseudocode) that prompts the user for a starting balance and then prints the
number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
(Hint: You can use and to form a compound condition.)
Sample session:
Enter starting balance: 10000
It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000.
Sample session:
Enter miles (-999 to quit): 40
Enter gallons: 2
Enter miles (-999 to quit): -999
Overall MPG = 20
Provide a graceful response if the total gallons equals zero.
14. [after 2.9] Loop Termination by Counter Pseudocode *:
Write a pseudocode algorithm that calculates and prints the overall MPG (miles per gallon) for a series of
miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons
value. Within the loop, accumulate miles and gallons separately. Use a counter loop to ensure that the
loop repeats three times. The algorithm should generate a display of prompts, inputs, and final output that
looks like this (italicized values are user inputs):
Sample session:
Enter miles: 10
Enter gallons: 1
Enter miles: 20
Enter gallons: 2
Enter miles: 10
Enter gallons: 2
Overall MPG = 8
Provide a graceful response if the total gallons equals zero.
15. [after 2.10] Average Weight Pseudocode **:
A program often checks data before using it. A good prompt frequently includes a limit specification, and
if the data is not reasonable, the program can indicate that by simply repeating the prompt, thereby asking
for the same data again.
Suppose you want to compute the average weight of a group of items. To do this, initialize
cumulativeWeight to 0, count to 0, and more to y. Then enter a loop that repeats
while more equals y. Just before the end of this loop include a prompt asking more? (y/n): and input
the users answer. Inside this (outer) loop, increment count and print it out to tell the user the number of
the next item. Then preset the input variable to some unacceptable value. For example, set weight to
-1, and enter a second (inner) loop that repeats while weight is less than or equal to 0. In the inner
loop, print Enter kg weight greater than zero: and then input a value for the weight. This inner loop
should automatically repeat until the input is valid. After this inner loop terminates, add the (valid) input
to cumulativeWeight. After an n input for more terminates the outer loop, compute the average
by setting weight to cumulativeWeight / count, and print it out. Here is a typical interactive
display:
Sample session:
Item number 1:
Enter kg weight (greater than zero): 1.23
more? (y/n): y
Item number 2:
Enter kg weight (greater than zero): 2.78
more? (y/n): y
Item number 3:
Enter kg weight (greater than zero): -0.95
Enter kg weight (greater than zero): 0.95
more? (y/n): n
Average weight = 1.6533333333333333 kg
Use pseudocode to write the algorithm for a program that is able to generate the above display.