CSE 332 Lab 1: Letters, Tiles, and Dictionaries

Lab dates: Wednesday September 2 and Wednesday September 9, 2009
Due by Tuesday September 15 at 11:59 pm
(deadline for e-mailing a zip file with your solution)
Final grade percentage: 5 percent

Objective:

This lab is intended to familiarize you with basic program structure, data movement and execution control concepts, including:

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.

Assignment:

    Part I - Readings:

  1. The following readings in the optional text books may be useful as reference material while working on this lab assignment, and though we'll touch on most of the issues in the next few studio sessions, selectively looking up topics and/or reading ahead (on demand as you encounter issues while working on the lab) is encouraged:

  2. The output stream, C++ string class, and input and output stringstream examples in the C++ Data and I/O lecture slides also may be helpful when implementing parts this lab.

  3. Please read the following CSE 332 Programming Guidelines which are relevant to this lab, and please follow them as you implement your solution: A.1-A.6, A.9-A.11, A.17, B.7, B.9, B.13, B.15, B.16, B.20-B.23, B.25, B.30, B.33, B.34, C.1-C.4 and C.6-C.9.

    Part II - Program Design and Implementation:

  4. Open up Visual Studio, and create a new Win32 Console Application Visual C++ project for lab 1.

  5. In the header file and a source files that were created in your project (and if you'd like to add additional header and source files feel free to do so), you will declare and define (respectively) the functions, structs, and other features of your program as you implement this assignment. As you develop your code, please use good modularity: for example, if a function's logic has several separable parts (or is long enough to fill the editor's window) you may want to break it up into other smaller functions.

    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.

  6. Declare and define a helpful "usage message" function that (1) prints out (to the program's standard output stream) the program's name followed by a helpful usage message telling the user how to run the program correctly with a "-D" or "-d" followed by the name of a dictionary file (for example dictionary_example.txt) and a "-T" or "-t" followed by the name of a tile definition file (for example tile_defs.txt), and (2) returns a non-zero value.

    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.

  7. Declare and define a struct to represent a "letter tile" that has a character (type char) for the letter itself, and an unsigned integer (type unsigned int) for a score to be associated with that letter.
  8. Declare and define a function for reading in a dictionary file (for example dictionary_example.txt), that takes a reference to a vector of C++-style strings (of type 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.

  9. Declare and define a function for reading in letter tile definitions, that takes a reference to a vector of letter tiles (for example of type 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.
  10. For your project's main function:

  11. Build your project, and fix any errors or warnings that occur. Please be sure to note all of the different kinds of errors or warnings you ran into (though you don't have to list every instance of each kind) in your ReadMe.txt file. If you were fortunate enough not to run into any errors or warnings, please note that instead, where you would have listed errors or warnings in your ReadMe.txt file.

  12. Open up a Windows console (terminal) window and change to the directory where your program's executable file was created by Visual Studio (see the first studio exercises document for more details on this, if you don't remember them).

  13. Run the executable program through a series of trials that test it with good coverage of cases involving both well formed and badly formed inputs. For this lab one especially useful test is to check whether the output printed by your program consistently represents the contents of valid dictionary and tile definition files it was given. In your ReadMe.txt file please document which cases you ran (i.e., what the command lines were) and summarize what your program did and whether that is correct behavior, in each case.

  14. In your ReadMe.txt file, make sure that your name and the lab number (lab 1) are at the top of the file, and that you've documented whether you ran into any errors or warnings while developing your solution (and if so what they were) and what the executable program did for each of the trials you ran. Be sure to save your changes to your ReadMe.txt file, as well as those to your source (and header) file(s) before preparing your solution zip file.

  15. Prepare a zip file that contains your project's source, header, and ReadMe.txt files (except for stdafx.h, stdafx.cpp or other Windows-generated files you did not modify), by:

    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).

    Part III - Linux Programming Environment: (optional, worth up to 5% extra credit)

    The goal of this optional part of the assignment is to practice using the Linux environment to compile and run your program on 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:


Updated 9:00am Tuesday September 15 2009 by
Chris Gill

Changes since original posting: