Assignment (II)
Assignment (II)
7. Write a program that repeatedly asks the user to enter two money
amounts expressed in old-style British currency: pounds, shillings,
and pence. (See Exercises 10 and 12 in Chapter 2, “C++
Programming Basics.”) The program should then add the two
amounts and display the answer, again in pounds, shillings, and
pence. Use a do loop that asks the user whether the program should
be terminated. Typical interaction might be
To add the two amounts, you’ll need to carry 1 shilling when the
pence value is greater than 11, and carry 1 pound when there are
more than 19 shillings.
8. Suppose you give a dinner party for six guests, but your table seats
only four. In how many ways can four of the six guests arrange
themselves at the table? Any of the six guests can sit in the first
chair. Any of the remaining five can sit in the second chair. Any of
the remaining four can sit in the third chair, and any of the
remaining three can sit in the fourth chair. (The last two will have
to stand.) So the number of possible arrangements of six guests in
four chairs is 6*5*4*3, which is 360. Write a program that
calculates the number of possible arrangements for any number of
guests and any number of chairs. (Assume there will never be
fewer guests than chairs.) Don’t let this get too complicated. A
simple for loop should do it.
9. Create a three-function calculator for old-style English currency,
where money amounts are specified in pounds, shillings, and
pence. (See Exercises 10 and 12 in Chapter 2.) The calculator
should allow the user to add or subtract two money amounts, or to
multiply a money amount by a floating-point number. (It doesn’t
make sense to multiply two money amounts; there is no such thing
as square money. We’ll ignore division. Use the general style of
the ordinary four-function calculator in Exercise 4 in this chapter.)
The user should type the first fraction, an operator, and a second
fraction. The program should then display the result and ask
whether the user wants to continue.