This assignment involves developing a program that edits a file of NCAA football teams. The program provides the user with a menu of options for maniuplating the file. The menu allows the user to
You will develop the program as a menu driven program, and you are strongly encouraged to develop it in seven stages. (In fact, when I wrote the program, I wrote it in exactly the stages that I am recommending to you. It took me 3.5 hours to write it from start to finish, so I strongly encourage you not to wait until the day before to start, but rather, to start now, and try to do one stage per day until you are finished. If you keep pace with me, you can do each stage in about 30 minutes; more likely, it may take you a couple of hours for each stage.
So that you can get an idea of what the program is supposed to do, I have put an example script file for each stage in the following directory on strauss:
~pconrad/public_html/cisc181/04S/proj/proj2which can be found on the following web link:
http://copland.udel.edu/~pconrad/cisc181/04S/proj/proj2You should also consult those files for ideas about what and how to test. You are encouraged to test each stage of the program as you develop, rather than trying to develop the whole thing at once.
At each stage, you should have a working complete program that you could script and turn in for partial credit. However, in the end you should only turn in one program.
It is best to read over the entire assignment before starting to code part 1, so you have some idea of where we are going. But don't let the size or complexity overwhelm you; working step by step, one step per day, you'll have no trouble finishing on time if you start NOW. So, with that advice, let's begin:
Main Menu:
a: add team to list
l: list teams
q: quit program
s: summarize list
The main is therefore very short, and mainly consists of a loop that
reads options from the user until the user selects the 'q' option. You
can use a switch statement. The default case should print an error message
indicating that the option is not supported. Print the menu of options
each time through the loop.
Each of these options will call a function that will perform some task. (Even the 'q' option might perform some task before finally quitting.) For example, the 'a' option will call a function called:
void addTeamToList(Team **teamListHeadPtr, Team **teamListTailPtr);This function will
The file will have the same format as the files in the directory proj2, which contains several files teams1.txt, teams2.txt, etc., all of which contain fields separated by ":". Use the example code from lecture (which reads a file containing fields separated by commas) as an example.
The linked list will consist of struct Team nodes, which
each node contains the following fields.
domainName (domain name from main website for this college or university) schoolName (name of the college or university) city state foundingYear userid (userid of the user that has the data file for this school) next (pointer to the next field)You should declare variables in your main program to point to the head and tail of a list of teams, such as the following:
Team *teamListHead; Team *teamListTail;These variables should be local variables to your main program not global variables (a serious deduction (at least 10%) will be made if you use global variables instead.)
You will pass these variables (the ones for head and tail of the team list) into the function readTeamFile. You should pass these variables by reference; that is, you will pass the address of these variables,
as follows:
...
switch (menuOption)
{
case 'a':
addTeamToList(&teamListHead, &teamListTail);
break;
...
NOTE: Previously, there was a typo on this page, and instead of the code above,
the following
code was in this position. This code is not wrong, it is just misplaced;
it should appear in step 5 when you do the 'r' option...
...
switch (menuOption)
{
case 'r':
readTeamFile(&teamListHead, &teamListTail);
break;
...
Inside the function, you should dereference these pointers when
assigning values to them. For example, when assigning a value to
teamListHead, you should use code such as the following. Note that the
name of the variables has "ptr" on the end of it to remind you that
inside the function, these variables are not the head and tail of the list,
but rather, they point to the head and tail of the list.
void addTeamToList (Team **teamListHeadPtr, Team **teamListTailPtr)
{
...
Team *p;
p = new Team; // allocate a new node
// set fields inside p based on values read from user, then do...
if ((*teamListHeadPtr) == NULL) // if first node in list
(*teamListHeadPtr) = p; // set the head of the list
else
(*teamListTailPtr)->next = p; // link new node to end of the list
(*teamListTailPtr) = p; // update the tail pointer
...
}
The other options should do the following:
Partial Credit: If this step is as far as you get, it is worth up to 40% partial credit (you start with a grade of 40%, and additional deductions may be taken from there). If you stop here, script this program. Be sure you test all the options that are present at this stage (see the script file p2s1.txt for ideas.
Your script file should also be called p2s1.txt if you stop at this stage. You MUST use your individual school (the one assigned to you at the start of the semeseter) as at least one of the schools you enter into your test run.
If you are continuing on with the remaining parts, you do NOT need to submit a script or C++ program for this step.
Add one additional option to the program.
The "f" option "finds" a team in the list. Prompt the user for a domain name, then search the list for all teams that match that domain name. Note that it is possible for the list to contain duplicate entries. See the script file p2s2.txt for example output.
Start by making a copy of your p2s1.cpp or p2s1.cc program with, for example:
cp
p2s1.cpp p2s2.cpp
Then add the necessary code to implement the new option.
Partial Credit: If this step is as far as you get, it is worth up to 50% partial credit (you start with a grade of 50%, and additional deductions may be taken from there). If you stop here, script this program. Be sure you test all the options that are present at this stage (see the script file p2s2.txt for ideas.
Your script file should also be called p2s2.txt if you stop at this stage. You MUST use your individual school (the one assigned to you at the start of the semeseter) as at least one of the schools you enter into your test run.
If you are continuing on with the remaining parts, you do NOT need to submit a script or C++ program for this step.
Add one additional option to the program:
The "d" option deletes a team from the list. It will prompt the user to enter a domainmame. It will then search the list for the first node that matches that domain name, and delete that node from the list.
From here on out the drill is the same for each additional step (except the last one)... for each step, you add one additional option to the program, and get a bit more credit. At each step, copy your file with a command such as:
cp p2s2.cpp p2s3.cpp
Then add the necessary code to implement the new options. (This is the last step where I'll spell out these specific instructions
Partial Credit: If this step is as far as you get, it is worth up to 60% partial credit (you start with a grade of 60%, and additional deductions may be taken from there). If you stop here, script this program. Be sure you test all the options that are present at this stage (see the script file p2s3.txt for ideas.)
(From here on out, you'll be expected to just follow the pattern; I'll just say "this step is worth x% partial credit, and the script file should be called p2sn.txt, where n is the step number. And as always, you must use your "assigned school" as one of the schools you test with.
If you are continuing on with the remaining parts, you do NOT need to submit a script or C++ program for this step. Only submit the script for the step at which you finish.
Suggestion: You should read the values into a character array (using cin.getline()) and before assigning the new value, check if the string entered is blank (using strcmp()). Use a character array even for the integer foundingYear, and then use atoi() to do the conversion.
This stage is worth 70%. See previous stages 1-3 for guidance on how to name your program, script file, etc. and what to turn in if you stop at this step.
It then opens that file as an ifstream; if the file can't be opened, just print an error message and return from the function to the main menu (don't exit the program.)
If the file is opened successfully, read all records from the file (which contains colon separated values, similar to the files teams.txt, and udel.txt; these can be found in the proj/proj2 directory cited above). For each line you read from the file, allocate a new Team node. Read each line from the file into a single character array, then use strtok() to break up the fields and store each one in its proper place in the new node. Then, add that new node into the linked list.
This stage is worth 80%. See previous stages 1-3 for guidance on how to name your program, script file, etc. and what to turn in if you stop at this step.
It then opens that file as an ofstream; if the file can't be opened, just print an error message and return from the function to the main menu (don't exit the program.)
If the file is opened successfully, write all the records from the linked list into an output file, separated by colons, in the same format as the input files teams.txt, and udel.txt; these can be found in the proj/proj2 directory cited above).
The idea is that the output file you create should be able to be read back into the program as an input file with the r option on the same run, or a later run. You should test this in your script.
This stage is worth 90%. See previous stages 1-3 for guidance on how to name your program, script file, etc. and what to turn in if you stop at this step.
When the user types quit, print a message warning the user if there are any unsaved changes. If there are NOT unsaved changes, the message should not be printed. If there are unsaved changes, ask the user if they really want to quit without saving. If the answer is yes, go ahead and quit. If the answer is no, return to the main menu.
Hint: Add a variable in your main program that keeps track of whether or not the list has been modified since the last time it was written to a file. Start the variable as false. Every time the user invokes an option that modifies the list, set the variable to true. Every time the user writes the file out to the disk, set the variable to false. Then pass this variable into the quit option.
This stage is worth 100%. For this stage, be sure your script tests all the options involved in the program. Also, if you reach this stage, name your program and your script file proj2.cpp and proj2.txt.
(end of project 2)