Program Set 4
Program Set 4
Program Set #4
Total Points: 30
Choose 3 of the 6 problems below for full credit. See 1437 Grading Program Sheet for
grading/submission information. Partial credit will be given. (10 points each)
1. Implement Programming Exercise #12-Chapter 17 (Gaddis), p.1062. Use the driver program
provided by your instructor. Output should be user friendly.
2. Write a C++ program that uses recursion to determine a valid C++ identifier. The recursive definition
is as follows:
A C++-Identifier is a: Letter
or a: Letter followed by a C++-Identifier-Substring
A C++-Identifier-Substring is a: Letter
or a: Digit
or a: Letter followed by a C++-Identifier-Substring
or a: Digit followed by a C++-Identifier-Substring
Input the identifier from the keyboard and output if it is or is not a valid identifier. Must use a recursive
function for full credit. Use the C++ string class. Output should look similar to below.
3. Given a dollar amount between $0.01 and $9.99 write a C++ program to compute the fewest
number of standard American coins needed to produce that sum. The standard coins are:
dollar ($1.00)
half-dollar ($0.50)
quarter ($0.25)
dime ($0.10)
1
nickel ($0.05)
penny ($0.01)
Input the amount from the keyboard (double). Output the number of coins in descending order of value,
using plurals when a specific coin is represented more than once. Include a recursive function to
compute the change. Must use a recursive function for full credit. Error check the input. Output should
look similar to below:
Sample Run:
Change returned:
1 dollar
1 quarter
2 dimes
2 pennies
4. Given an integer from 1 to 999,999,999 you are asked to write a recursive C++ program to state that
value using English words. For example:
Separate words using commas in the same way that you would when writing out in digit form. Thus
900,009 becomes "NINE HUNDRED THOUSAND, NINE" and uses one comma. Note how each value
contains only CAPITAL letters, spaces, hyphens and commas. Hyphens only occur between values such
as TWENTY-ONE and NINETY-EIGHT, that is, for values from 2199 with the exception of values evenly
divisible by ten. Recall that the numbers from 11-19 in English are represented by ELEVEN, TWELVE,
THIRTEEN, FOURTEEN, FIFTEEN, SIXTEEN, SEVENTEEN, EIGHTEEN and NINETEEN. Note that there is
a single space after each comma. Input from the keyboard consists of a single line of no more than 9
digits. The lead character will never be a zero ("0"). The output consists of a single line containing only
CAPITAL letters, spaces, hyphens and commas. Make sure that there are no leading or trailing spaces in
the output. Finally, ask the user if he/she wishes to run the program again. Must use recursive
function(s) for full credit. Output should look similar to below.
2
Sample Run:
5. A geography class is currently studying Europe, and the next test covers the capital cities. The
test will be fill-in-the-blank questions. Each question will be in one of the following two formats:
Where placeholders <country> and <city> are provided, and you must fill in the blanks. Here is a
copy of your study sheet:
3
Estonia Tallinn Russia Moscow
Finland Helsinki San Marino San Marino
France Paris Serbia Belgrade
Georgia Tbilisi Slovakia Bratislava
Germany Berlin Slovenia Ljubljana
Greece Athens Spain Madrid
Hungary Budapest Sweden Stockholm
Iceland Reykjavik Switzerland Bern
Ireland Dublin Turkey Ankara
Italy Rome Ukraine Kiev
Kazakhstan Astana United Kingdom London
Kosovo Pristina Vatican City Vatican City
Latvia Riga
You have little interest in geography and are an accomplished programmer. To skirt the opportunity of
genuine learning, you decide to take advantage of your existing abilities and write a C++ program to fill
in the blanks. Input will be from a data file each in the format given in the description above. Blanks will
consist of 5 consecutive underscore characters ('_'). Output will exactly mirror the input except that
the blanks will be replaced with the correct country or capital names from the study sheet. All of the
countries/capitals may or may not be used. Use the C++ string class and any appropriate STL classes. Let
the user input the file name from the keyboard. Output should look similar to below.
Sample File:
Sample Run:
4
6. A popular word game involves finding words from a grid of randomly generated letters. Words must
be at least three letters long and formed from adjoining letters. Letters may not be reused and it is valid
to move across diagonals. As an example, consider the 4x4 grid of letters below.
A B C D
E F G H
I J K L
M N O P
The word "FAB" is valid (letters in the upper left corner) and the word "KNIFE" is valid. The word
"BABE" is not valid because the "B" may not be reused. The word "MINE" is not valid because the "E" is
not adjacent to the "N".
Write a C++ program that uses a 4x4 two-dimensional array to represent the game board. The
program should randomly select letters for the board. Either place a "U" next to a "Q" or to treat "QU"
as a single letter. The program should read the words from a data file and then use an algorithm to
determine if the word may be formed from the letters on the game board. The program should output
the total number of words found and all valid words (10 per line) from the file that are on the game
board. Let the user input the file name from the keyboard. Use any appropriate STL classes and the C++
string class. Output should look similar to below.
Sample Run:
Generated Board:
H A H I
V W O S
E E S E
T I P W
awe awes epee eve eves ewe ewes hah have haves
haw haws his hiss hoe hoes hos hose hoses how
hows ohs owe owes pee peso pesos pet pew pews
pie pies pis pit psi see set sew sews shah
shave shaves shoe shoes show shows sieve sip sit site
sos sow sows spew spit spite ssh sweep sweet tee
tees tie ties tip tips tis veep veeps vet wave
waves wee weep weeps wet who whoa whose woe woes