CSE 332 Lab 0: Ranks, Suits, Cards and Files

Due by Tuesday January 27, 2015, at 11:59 pm
(deadline for receipt of an e-mail with an attached zip file with your solution)
Final grade percentage: 5 percent


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 file and read in strings from it, and (3) parse those strings as the definitions of cards in a standard playing deck for bridge, cribbage, poker, etc. Your program will print out what was read and parsed from the file so you can check easily that it worked correctly.

In subsequent lab assignments you will use these features to generate sets of cards, generate different combinations of the cards in a set, and order the different combinations according to various scoring functions.


    Part I - Readings:

  1. The following readings in the required text book 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) in the text book, lecture slides, and studio exercises is encouraged:

  2. Please review the CSE 332 Programming Guidelines, and follow them as you develop your solution to this assignment. Guidelines on which we will focus in grading your solution for this lab are: A.1-A.11, A.15-A.17, B.1, B.13, B.15, B.16, B.20-B.24, B.29, B.32, and C.1-C.8.

    Part II - Program Design and Implementation:

  3. Open up Visual Studio 2013, and create a new Visual C++ Win32 Console Application Visual C++ project for lab 0.

  4. 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:even at this early stage the details of this assignment are intentionally slightly 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.

  5. Add a new C++ header (.h) file and a new C++ source (.cpp) file to your program and in them declare and define (respectively) a struct to represent a "playing card" (of type Card) that declares an enumeration for the different suits a card can have (clubs, diamonds, hearts, spades), another enumeration for the different ranks a card can have (two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace), a member variable of the suit enumeration type, and a member variable of the rank enumeration type. Don't forget to include the header file for this struct in any source file that uses the struct type or the enumeration types it contains.
  6. Declare and define a function for parsing a file (for example card_file.txt) containing text (character) strings that define different playing cards (we'll call these "card definition strings").

    The card definition strings in such a file are separated by spaces, tabs, line breaks, or other forms of whitespace. Valid card definition strings in a file must be either two or three characters long. The last character of a valid card definition string encodes a card's suit (and must be C or c for clubs, D or d for diamonds, H or h for hearts, or S or s for spades). The first character encodes (or for a rank of 10, the first two characters encode) the rank of the card (and are 2, 3, 4, 5, 6, 7, 8, 9, 10, J or j for jack, Q or q for queen, K or k for king, and A or a for ace).

    The file parsing function should take two parameters: a reference to a Standard Template library (STL) vector of card structs (of type vector<Card> &), and a C-style string (of type char *). This function should use the C-style string given in the second function parameter as the name of a file, open the file, and then read one card definition string at a time from that file until there are no more strings to read.

    Each time a valid card definition string is read (invalid strings simply should be ignored), the function should push back a card struct instance with the rank and suit encoded in the string, into the vector that was passed as the first parameter. If the file cannot be opened or the function encounters any other problems (other than badly formed card strings, which it should skip over and keep processing good ones) during its execution it should print out a helpful error message indicating the problem and return a non-zero integer value; otherwise it should return 0 to indicate success.

  7. Declare and define a function for printing out a vector of card structs to the standard output stream. The function should take a reference to a const vector of card structs (of type const vector<Card> &) as its only parameter and should print out valid card definition strings (with each string on its own line) for each of the card struct instances contained in the passed vector (hint: first construct each string and then use cout to print it). If the function encounters any problems during its execution it should print out a helpful error message indicating the problem and return a non-zero integer value; otherwise it should return 0 to indicate success.

  8. 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 the name of the program and the name of a file to read, e.g., lab0 card_file.txt), and (2) returns a non-zero value.

  9. For your project's main function:

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

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

  12. 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, an especially useful test is to check whether the output printed by your program consistently represents the contents of valid card strings from the file whose name it was given. Another one is to check the return code produced by the program, which you can get by running the program in the terminal window and then just after it finishes running issuing the command echo %errorlevel% which prints out the value of the %errorlevel% environment variable where the result returned by the most recently run program is always kept.

    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.

  13. In your ReadMe.txt file, make sure that your name and the lab number (lab 0) 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.

  14. 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 0 solution as an e-mail attachment to the course e-mail account (cse332@seas.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 the shell.cec.wustl.edu server. 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 terminal output that results from setting up, compiling, and running your code on Linux (as described below) from the secure shell window into the "Extra Credit" section of your ReadMe.txt file.

    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:

Posted 3pm Monday January 12 2015 by
Chris Gill