To do this, you will implement a simple C++ program that can (1) read in and parse command line arguments, (2) open a dictionary file and read in strings from it, and (3) open another file and parse it for the definitions of a set of "letter tiles" (like in the game Scrabble). Your program will print out what was read from each of the files so you can check easily that it worked correctly.
In subsequent lab assignments you will use these features to generate permutations of letter tiles, check each permutation against a dictionary, and generate a score for each matching permutation.
Note:the details of this assignment are intentionally somewhat under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your Readme.txt file.
Hint: it's a lot easier to construct C++ style strings from C style strings and then do comparisons, concatenation, etc. using their operators and methods, rather than trying to do that with the original C style strings.
char) for the letter itself, and an unsigned integer (type
unsigned int)
for a score to be associated with that letter.
vector<string> &)
and a C-style string (of type char *); This function should open
a file stream using the C-style string given in the second function parameter
as the name of the file to open, read one string at a time from that file, and
push back each string into the vector as it's read. If the file cannot be opened
or the function encounters any other problems during its execution it should
print out a helpful error message indicating the problem and return a non-zero
value; otherwise it should return 0 to indicate success.
Note: in keeping with the spirit of giving you freedom to innovate in designing your
programs, for this function and the next one you could pass a reference to a C++-style string (of type
string &) instead of passing a C-style string as the second parameter to the function.
If you do that, however, please note that C++ file streams expect a C-style string for a file name, which
you can get by calling the C++-style string's c_str method.
vector<LetterTile> & if you named your
struct type LetterTile)
and a C-style string (of type char *); This function should open
a file stream using the C-style string given in the second function parameter
as the name of the file to open (for example
tile_defs.txt), and read one line at a time from that file
(Hint: the C++ getline function can help with this, as can
using C++ STL string streams to read values out of strings). From each line
of the file, the function should (1) read in a character and then a score for
that character, and then a quantity indicating how many letter tiles to create
with that character and score; and (2) push back a letter tile with that character
score into the vector, as many times as the quantity indicates. If the file
cannot be opened or the function encounters any other problems during its execution
it should print out a helpful error message indicating the problem and return a
non-zero value; otherwise it should return 0 to indicate success.
Send the zip file containing your lab 1 solution as an e-mail attachment to the course e-mail account (cse332@cec.wustl.edu) by the submission deadline for this assignment. If you need to make changes to your lab solution you are welcome to send a new zip file, and we will grade the latest one received prior to the deadline (according to the time stamp the server puts on the e-mail).
grid.cec.wustl.edu or the Lopata 400 Linux lab machines.
For extra credit, please add a section marked "Extra Credit" at the end of the ReadMe.txt file
you submit with your solution, and copy the results of compiling and running your code on
Linux (as described below) from the secure shell window into that section.Please ask for help from your professor or teaching assistants if you are uncertain about how to do this extra credit part or if you run into any difficulty with it:
grid.cec.wustl.edu for the Host Name, enter your CEC
login id (without @cec.wustl.edu) and press the
Connect button. Type in your password and click OK, in
the window that appears. You should then see a Linux command prompt
(a string of characters including possibly some combination of your
id, the machine's name, and the current directory). Copy and past
that command prompt string into your ReadMe.txt file as the answer for
this exercise.
mkdir command to create a
cse332 directory where you will store your
programs during the course, i.e.,mkdir cse332
Change to that directory, create a lab1 subdirectory in it, and change to that
subdirectory:
cd cse332
mkdir lab1
cd lab1
Note that you can also issue multiple commands in sequence
by placing semicolons between them:
mkdir cse332 ; mkdir cse332/lab1 ; cd cse332/lab1
stdafx.h and stdafx.cpp), and drag and
drop them into the lab1 directory in your secure file transfer window.
Also download the following Makefile to your desktop, and drag and drop
it into the lab1 directory window of the secure file transfer client
as well.
Back in the secure shell client, use the mv command
change the name of the file you just added from Makefile.txt
to just Makefile (Windows "helpfully" adds the .txt
extension even though the name Makefile is what the make
command you'll use expects the file's name to be).
EXECUTABLE =
CMPL_SRCS =
HEADER_FILES =
stdafx.h file (or for that matter any
other windows-specific) in your source and/or
header files, comment out that line (but only on the Linux platform - uncomment
those lines on Windows).
Makefile, exit the editor
and run the make command to build your program. Please document any errors
or warnings you encountered on Linux, or if there were none please indicate that instead,
in the extra credit section of your ReadMe.txt file. Fix any errors or warnings you see
on Linux, and please ask for
help from your Professor or TAs if you have any difficulty with this.
Hint:Many terminal window shells in the Linux environment require you
to put a leading ./ (saying to find the program in the current directory)
before the name of the executable program when you run it, as in:
./lab1.exe -d dictionary.txt -t tiledefs.txt
Copy the results of those trials into your ReadMe.txt file, in the extra credit section.