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.
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.
.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.
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
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.
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.
lab0 card_file.txt), and (2) returns a non-zero value.
vector<Card>), and pass that vector and the first program argument (after the program name) to the function that parses a file of card definition strings.
If that function returns a non-zero value the program should return that value, or otherwise the program should pass the vector to the function that will print it out, and then check the integer value returned from that function and if it's non-zero return it (note that the next step can be combined with this one by simply returning the result returned by the function).
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.
stdafx.cpp, or other Windows-generated files you did not modify), by:
stdafx.cpp) from Visual Studio into that folder; and then
Send the zip file containing your lab 0 solution as an e-mail attachment to the course e-mail account (email@example.com) 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).
shell.cec.wustl.eduserver. 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:
shell.cec.wustl.edufor the Host Name, enter your login id and press the
Connectbutton. 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 paste that command prompt string into your ReadMe.txt file as the answer for this part of the extra credit exercise.
mkdircommand to create a
cse332directory where you will store your programs during the course, i.e.,
Change to that directory, create a lab0 subdirectory in it, and change to that
Note that you can also issue multiple commands in sequence
by placing semicolons between them:
mkdir cse332 ; mkdir cse332/lab0 ; cd cse332/lab0
stdafx.cpp), and drag and drop them into the lab0 directory in your secure file transfer window. Also download the following
Makefileto your desktop, and drag and drop it into the lab0 directory window of the secure file transfer client as well.
Back in the secure shell client, if necessary use the
change the name of the file you just added from
Makefile (Windows sometimes "helpfully" adds the
extension even though the name
Makefile is what the
command you'll use expects the file's name to be).
stdafx.hfile (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
makecommand 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:
Copy the results of those trials into your ReadMe.txt file, in the extra credit section.