The goal for this week is to do even more structured programming in C, using strings, pointers, functions and header files to organize processing. You will really need pointers to update data (function parameters) this time.
[25 points] We have written a header file "CardOps.h" for a set of operations to manipulate playing cards. You must implement these functions by writing a corresponding definition file "CardOps.c". You must not change the way any of these functions are declared!
[20 points] In order to know if your functions are working properly, you need a test program. Write a main program (CardOpsTest.c) that thoroughly tests the operation of all the functions in CardOps.c. Check both good and invalid values for suits and faces. There should not be any user input for your test program. Use gcov to insure that every statement in your implementation of CardOps is executed at least once. Include the gcov output log in your submitted zip file.
[20 points] Write a second main program (pg3a.c) to read a file containing card strings, one per line. Use a command-line argument when you run the program to get the name of the input file. Store only valid and unique cards in a dynamically allocated array that starts with size 5, and is doubled in size as necessary. Then sort them according to their rank and print them out. Hopefully you all know how to implement at least one type of sorting algorithm. You can use other people's existing code for the basis of your sorting as long as you cite the original source. You should check for memory leaks with valgrind and eliminate them all.
Think about how you want to store the card information and try to find a way to do this efficiently, so that you don't have to keep parsing card strings over and over again. (Hint: make a Card struct and use that as your array base type.) You are encouraged to add other functions to help with the processing. You should (and we will) use gprof to check for inefficient coding decisions.
[5 points] You must also write a makefile called "MakeCards" that can be used to compile the CardOps files along with your test program and your main driver program. It must have at least two executable targets, CardOpsTest and pg3a.
Grading: 5 points style, submission, reflection & warnings, 25 points CardOps.c, 20 points CardOpsTest.c, 20 points pg3a.c, 5 points makefile.
In preparation for our working session on version control in class on Tuesday 6/11, you all need to have the following steps completed and ready to use. There is nothing to submit for this part of the assignment.
General assignment requirements, style and submission details:
gcc -std=c99 -pedantic -Wall -Wextra -O g++ -std=c++98 -pedantic -Wall -Wextra -ORemember: you will receive NO credit for programs that do not compile. Use incremental coding to insure that you always have a working program, even though it might be incomplete.