Create
a
set<char>,
then open a file (whose name is provided on the command line) and read that
file in a
char
at a time, placing each
char
in the
set.
Print the results and observe the organization, and whether there are any
letters in the alphabet that are not used in that particular file.
Create
a kind of “hangman” game. Create a class that contains a
char
and
a
bool
to
indicate whether that
char
has been guessed yet. Randomly select a word from a file, and read it into a
vector
of your new type. Repeatedly ask the user for a character guess, and after each
guess display the characters in the word that have been guessed, and
underscores for the characters that haven’t. Allow a way for the user to
guess the whole word. Decrement a value for each guess, and if the user can get
the whole word before the value goes to zero, they win.
Modify
WordCount.cpp
so that it uses
insert( )
instead of
operator[ ]
to insert elements in the
map.
Modify
WordCount.cpp
so that it uses a
multimap
instead of a
map.
Create
a generator that produces random
int
values between 0 and 20. Use this to fill a
multiset<int>.
Count the occurrences of each value, following the example given in
MultiSetWordCount.cpp.
Change
StlShape.cpp
so that it uses a
deque
instead of a
vector.
Modify
Reversible.cpp
so it works with
deque
and
list
instead of
vector.
Modify
Progvals.h
and
ProgVals.cpp
so
that they expect leading hyphens to distinguish command-line arguments.
Create
a second version of
Progvals.h
and
ProgVals.cpp
that uses a
set
instead
of a
map
to
manage single-character flags on the command line (such as
-a
-b -c
etc)
and also allows the characters to be ganged up behind a single hyphen (such as
-abc).
Use
a
stack<int>
and build a Fibonacci sequence on the stack. The program’s command line
should take the number of Fibonacci elements desired, and you should have a
loop that looks at the last two elements on the stack and pushes a new one for
every pass through the loop.
Open
a text file whose name is provided on the command line. Read the file a word at
a time (hint: use
>>)
and use a
multiset<string>
to create a word count for each word.
Modify
BankTeller.cpp
so that the policy that decides when a teller is added or removed is
encapsulated inside a class.
Create
two classes
A
and
B
(feel free to choose more interesting names). Create a
multimap<A,
B>
and fill it with key-value pairs, ensuring that there are some duplicate keys.
Use
equal_range( )
to discover and print a range of objects with duplicate keys. Note you may have
to add some functions in
A
and/or
B
to make this program work.
Perform
the above exercise for a
multiset<A>.
Create
a class that has an
operator<
and an
ostream&operator<<.
The class should contain a priority number. Create a generator for your class
that makes a random priority number. Fill a
priority_queue
using your generator, then pull the elements out to show they are in the proper
order.
Rewrite
Ring.cpp
so it uses a deque instead of a list for its underlying implementation.
Modify
Ring.cpp
so that the underlying implementation can be chosen using a template argument
(let that template argument default to
list).
Open
a file and read it into a single
string.
Turn the
string
into a
stringstream.
Read tokens from the
stringstream
into a
list<string>
using a
TokenIterator.
Compare
the performance of
stack
based on whether it is implemented with
vector,
deque
or
list.
Create
an iterator class called
BitBucket
that just absorbs whatever you send to it without writing it anywhere.
Create
a template that implements a singly-linked list called
SList.
Provide a default constructor,
begin( )
and
end( )
functions (thus you must create the appropriate nested iterator),
insert( ),
erase( )
and a destructor.
(More
challenging) Create a little command language. Each command can simply print
its name and its arguments, but you may also want to make it perform other
activities like run programs. The commands will be read from a file that you
pass as an command-line argument, or from standard input if no file is given.
Each command is on a single line, and lines beginning with ‘
#’
are comments. A line begins with the one-word command itself, followed by any
number of arguments. Commands and arguments are separated by spaces. Use a
map
that maps
string
objects (the name of the command) to object pointers. The object pointers point
to objects of a base class
Command
that has a virtual
execute(string
args)
function, where
args
contains all the arguments for that command (
execute( )
will parse its own arguments from
args).
Each different type of command is represented by a class that is inherited from
Command.
Add
features to the above exercise so that you can have labels,
if-then
statements, and the ability to jump program execution to a label.