Lab #5 Assignment
Design Document Due Date: Nov. , 2012 at noon (12pm)
Lab Due Date: Dec. , 2012 at noon (12pm) Extra credit for early submission – See website
(see instructions on website for how to turn this in - “lab submission info”)
Grade value: 12% out of 100% for all grades
Objective: The goal for this lab is to provide an opportunity for practice of C program development and the C programming topics covered in Foster and Foster as covered in class. It is assumed that the student is familiar with the programming concepts but not the C syntax. This lab continues Dr. T’s approach to lab assignments and reinforces and refreshes previously learned material about C and programming.
Every lab assignment allows students to practice program development, debugging, and testing. All of these skills are crucial to success in Dr. T’s class. The format of this assignment is similar to the assignments that will be required for the rest of the semester so a student who is unsure of their skills can use this assignment to refresh them and to ask the instructor or TA about any concepts they are unsure of.
Linked lists Command line parameters Multiple program files
Testing and test plans Pointers Structs
Recursion Algorithms Searching
Sorting File input One-dimensional Array
Multi-dimensional Arrays Strings Control structures
Functions Arithmetic and relational operators Input and output,
Passing parameters Data types Global constants
Pre-processor directives Program design Modular programming structure
Error checking Programming style Compiling code,
Executing code, Debugging Testing.
Plan: Dr. T gives an overall problem that students work on all semester. Each lab assignment implements specific concepts. Succeeding assignments will modify and extend previous assignments.
Overview: For the rest of the semester you will be trying to determine what it would cost to start a small brick-and-mortar bookstore. You will be developing an estimate based on a number of factors including the size of the store, the kind of stock, the start up costs, staff costs, and other factors. (If you really own a business, you will quickly realize that this is not going to be a very realistic example, even later in the semester, but the idea is for you to practice your programming skills. ;) You will also make various other calculations as required.
You are going to get information from the user and store that information in a certain way. We’ll call this the data-entry phase of the program. Once all the input data is entered, your program will allow another user to perform various tasks on the data by choosing tasks from a menu. We’ll call this the menu-driven phase of the program. The user can continue to choose tasks from the menu as long as desired and one of the menu choices must be to end the program. The program ends correctly when the user chooses that option.
You are also required to design your program in advance before you begin writing code. You will document your design and turn in the design document at least a week before the lab assignment is due. The goal of the design document is to assist you in developing the actual program. In Lab #5 your design document must include some additional information to indicate the order in which you plan to work on and develop your various code modules.
This assignment has an overview section, a task description section, an implementation requirements section, a grading scale, and a deductions section. If there is additional info needed it will be in a miscellaneous section at the end of this lab assignment. Read ALL of the assignment before you start trying to develop the program.
Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties. You may NOT use global variables, the exit command, goto, break (except in a switch), or continue. You should do input and output using printf, scanf, fprintf, fscanf, and getline (you are allowed to use getchar and putchar if desired.)
Assumptions for the lab #5:
1) Strings may be single words or phrases with blanks and the maximum length will be 100 chars. Use constants to define the max value.
2) In general, if your instructions tell the user to enter numbers, then you do not have to check that the input might be a letter instead of a number. If the user does not follow your instructions to enter a number then any data type input error is the USER’s fault and you will not be penalized in this lab. There may be specific places where you ARE required to handle data checking but these are specified.
3) You will have a maximum number of 25 rooms (MAXROOMS) and 50 employees (also called staff) (MAXSTAFF) .
4) For date checking in Lab #5, you must use real calendar calculations.
5) There will be NO maximum of unique stock items in this lab. Each stock item will be of one of the existing stock types.
Problem: The data in your database will be the bookstore information needed to create the estimate such as rental space rates, stock information, and so on. As part of this assignment you will have to find real data about some items to use as test data for your program. When the user runs your program, they must first enter data. The data they entering will be the bookstore information that you have researched to use as your test data. After getting all the input data from the user (and storing it in a linked list), you will allow the user to do the following:
1) Using the data in the linked list,
A) Print all or part of the data in a table
i. Total estimated first year costs
ii. Total estimated square footage of bookstore
i. All the types of stock that will be sold with their actual prices and current amounts
ii. Items of stock with actual prices less than a given value
D) Determine revised scenarios:
i. Calculate total yearly expected profit on 100% sales (Scenario 1)including rent, staff, and startup costs
ii. Calculate total yearly expected profit on 80% sales (Scenario 2)
E) Search for
i. Employee with highest wage rate
ii. Most expensive stock item
i. Room names
ii. Room sizes
iii. Room number
iv. Stock items by name
v. Stock items by price
G) Sell items
H) Restock items
2) End the program
Data Description: For lab #5, you will be storing the input data in sorted singly linked list of structs. You will use the struct data types from Lab #4 – one for a stock item, one for a room, and one for information about a staff member – but you will add “links”, i.e. pointers to structs, inside each struct.
The data elements are the same as for Lab #4. No new data items have been added except the link to put in each struct.
The format for the struct types is the same as in Lab #4 with the addition of the links in each struct type.
Detailed descriptions of each data value. The data values as listed in Lab #4 must be stored as described. You may also store additional values into the structs if desired.
It is NOT necessary to have the user enter the data in exactly the order listed if you are doing individual data entry. When asking for data directly from the user, you may get data from the user in whatever order makes sense. However, you must implement the required data input methods described later in the document for "individual data method", "line of data method", and "file input method".
The stock item struct, the room data struct and the staff data struct will each have a new link pointer added to them. Simple names to use would be nextitem for the stock item struct pointer, nextroom, and nextstaff for the other two. The link pointers must be a pointer to the data type of the struct. Therefore, inside the roomdata struct type you will be adding a struct member of struct roomdata *nextroom; and similarly for the other two struct types.
Additionally, you will need to declare some external pointers in the functions to use in traversing the various lists. For example, you will probably want something like:
struct roomdata *startroom, *currroom, *prevroom, and *followroom for the external pointers for the rooms linked list.
Input Implementation: For Lab #5 the user must enter at least the minimum numbers of stock, staff, and rooms that were defined for Lab #4. Since the user has no maximum for stock, the program will NOT ask for the number of inputs. The program will simply start accepting inputs once the user chooses an input method. The program should let the user enter data for one room or stock item, etc., then ask the user if they have more data to enter or if they are done. The program must keep count of the entered data to make sure the minimum is entered. [Note for development: start with a smaller number of items then increase to the required minimum when program is working well.]
Your program must loop for each room to read and store input. You also have the choice to make two separate loops; one to enter all of the size data for all rooms and then one to enter all stock data for all rooms.
Make sure your program begins with a brief intro to the user so that they know what the program is for.
For Lab #5, you must implement line of data input and file input. The first method will allow the user to input all needed pieces of data about one item, room, or employee on one line, and the second method will read lines of data from an input file. The two forms of the input are described below. The program must ask the user how they want to input the data. Your program must give them all available choices of methods: File input method and line of data input method or both. Once the user has chosen the method of input, all the input will be done that way for the current run of the program.
For Lab #5 you must implement command line parameters to do the following. If the user has entered any command line parameters other than the executable name, i.e. a.out, then the program should assume that the first parameter after a.out is the name of an input file. The program should open this file and check to make sure the file pointer is valid. If it is, the program should read all input from the file. In this case, the program would NOT ask the user about what kind of data entry the user wants. The program SHOULD print out a message saying, “You entered file name “Lab5stuff.txt” (using the appropriate file name) on the command line. It will be used for input.” If the file name is not valid or if there was no command line parameter, then the program should let the user choose any of the implemented input methods listed below including file input.
For most pieces of data that are entered, you will do some error checking. It is recommended that your write small functions that you call to do the error checking. This would allow you to reuse these functions during the menu-driven phase of the program.
For Lab #5 you must validate any calendar dates to insure that they are "real". For dates that are supposed to be future dates, use the system time functions to validate that the input date is after the current date.
Line of data input method:
Your file or line of data input method is to have all the necessary data entered by the user on a few lines. The input would be all the pieces of data listed above. You must tell the user exactly how to enter the line of data. For Lab #5, use the file input and/or the line of data method with inputs in exactly the order specified in Lab #4. You must tell the user exactly how to enter the line of data.
Regardless of how the data is entered, your program will read the first number and store it in the current struct at the correct location, then read and store the character into the corresponding location in the struct then read the third number, and so on. Your program should read all the numbers, chars, and the string within a minimum number of input commands. Your program should read in as many lines of input as the user desires.
File input method :
This input method is to have all the necessary data entered by the user from a file. The input would be all the pieces of data listed above and would use the format specified in Lab #4. For Lab #5 your data file may have any name and may be in the same directory as your C program or a different directory where you include the path name. Be sure to tell the user the name for the data file so that they can run the program with their own data file if they did not enter a file name on the command line.
You should make two test files with different data to test with. Copy the test file to the specified file name and then test with it. Do this for both your test files.
File input method additional information::
If the user chooses file input, then your program must first get the name of the input data file to use or have the file name from the command line. You the user has chosen file input without giving a file name on the command line, then you must ask the user for the file name and you must let the user type in a string with the name of the file in it and then use the string as the file name to set up the file pointer. You would read in the name string using getline in the same way you read in the destination name.
Your program needs a FILE * pointer which is connected to the file with fopen. Ex:
int filenm = 100;
printf("Please enter the complete name of your data file: ");
getline(&filename, &filenm, stdin);
if (filename != NULL)
infile = fopen(filename, "r");
When the user has entered all the store data, print out all the input data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels. It is strongly suggested that this printing be written as a separate function that can be called at any time in the program to print the current contents of the arrays and variables. It is also suggested that a small function be written which will print the name of a sales room given the number as input. The function could have a switch or a bunch of if statements in it. You may wish to write small output functions for printing staff data, stock data, start up data and room data if desired. These could be combined to print the data required for input verification.
Task Description: (Menu-driven phase)
Once all the data is read into the linked list your program should give the user a main menu with the following choices: (use any number scheme you wish)
A) Print all the data about the store
B) Print all the data about business costs
C) Print all data for stock
D) Print all data for staff
E) Print all data for rooms (entered by user and calculated, if any)
F) Calculate estimated square footage of bookstore
G) Calculate total estimated first year costs
K) List all individual stock items with actual prices less than a given value
M) Determine profit scenario 1 (see description below). Revised to use each stock item as in Lab #4.
N) Determine profit scenario 2 (see description below). Revised to use each stock item.
S2) Search for employee with the highest wage rate
S3) Search for most expensive stock item
T) Sort the rooms array by name by bubble sort
V) Sort each room in the rooms array by total area from largest to smallest
W) Sort each room in the rooms array by room number
Z2) Sort stock items by name
Z4) Sort stock items by price charged, i.e. actual cost plus cost markup amount is price charged.
Z6) Sell items
Z7) Restock items
AA) End the program
All the menu functions in Lab #5 perform the same tasks as they did in Lab #4 except that now the functions are using the linked lists of data instead of the arrays of data. You must also make the changes described below for the linear searches and the bubble sorts.
Searches: All searches on the linked list will be linear searches. You should write ONE linear search function and then write separate test functions for each kind of search. These test functions should be passed into linear search as function parameters for each search.
Sorts: Sorting on the linked list will be either by bubble sort or selection sort. You should write ONE bubble sort function and then write separate test functions for each kind of sort. These test functions should be passed into bubble sort as function parameters for each sort. If you also choose to implement selection sort, you should create one sort function with multiple test functions.
When the user chooses "End the program" from the main menu, print a concluding message and then gracefully end the program.
You should design your program in advance before you begin writing code. In this lab and all other labs you will document your design and turn in the design document at least a week before the lab assignment is due. The goal of the design document is to assist you in developing the actual program. This lab has additional requirements for the design document so make sure you read them.
Read ALL of the assignment before you start trying to develop the program.
Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties. You may NOT use global variables, the exit command, goto, break (except in a switch), or continue.
Develop your program in small steps. Test and debug as you go.
For Lab #5 WRITE A DESIGN DOCUMENT FIRST. The design must include
a) all the functions you expect to write,
b) brief (one line) descriptions of each function, and
c) some indication of which function calls what other functions.
d) an indication of what order you plan to work on the functions in your design.
When you indicate the development order for the functions, explain why you chose to do that function in that order. You explanation should reference things like the point value of that task, the ease of making changes, the amount of work required, whether the function is similar to another so you will save it until later, whether a function does something completely new, whether you think you will even have time to work on the function, and other reasons.
The design document may be written as lines of text or as diagrams (such as a diagram that start with the main function at the top and all others below it, a tree, UML, etc.) or as some combination of those, but it must include the information listed for a), b), c) and d) above. Each function should accomplish one main purpose and each function at a lower level should have a more specific purpose than the function that calls it. Be sure to include all the functions that are described in this lab assignment. This design documentation will normally be turned in for the lab and a design will be required to be turned in for all labs after Lab 1. See the website or this assignment for the DESIGN DOCUMENT due date. It is usually ONE WEEK PRIOR to the lab due date.
A Lab #5 Design Document must be turned in in order for your Lab #5 assignment to be graded.
For Lab #5 you must also write and turn in a TESTING PLAN along with your design document. The testing plan should include at least five (5) sets of test data values that will test at least the following elements of your code:
Test the future date validation for day, month, year
Validate that the markup value is within the required limits
Demonstrate correct calculation of scenarios
Demonstrate correct sorting of the linked list
Demonstrate a search that does NOT find a matching value
Give your set of test values for each test element above and indicate what the correct result of the test should be and how to demonstrate that this result has occurred, i.e. will the user have to ask for the data to be printed out or will that happen automatically?
The program should use the following data structures:
Linked list of structs
Global CONSTANTS for specific and/or maximum values given in this assignment.
Constants can be done with #define or with the const declaration. Examples:
#define EVENTMAX 10
const int EVENTMAX = 10;
The program should use the following control structures:
Function calls to perform tasks
While, for, or do-while loops to read the input data
If, if-else, nested ifs, or switches to error check and implement the menu options
The program should NOT use:
break (except in a switch)
any topic not covered in class before the lab DUE date unless approved by the instructor
Comment your code! Use headers as described below, use line comments and use block comments. Line and block comments should explain the meaning of the code. As an example compare the following examples of code with comments:
/* Find A by multiplying L times W */
A = L * W; // A is the product
/* Find the area of the rectangle by multiplying length times width of the sides */
A = L * W; // A is area, L is length of one side, W is length of perpendicular side attached to L
While Example 1 has comments, the comments do not tell us anything extra about the code. The code itself tell us that A is the product of L*W. In Example 2, the comments are meaningful and explain the goal of the code and the meaning of the variables. Make your comments like Example 2 not Example 1.
The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple files are used, each file should contain a similar header.
Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook. This header should include at least the function name, the purpose of the function, and its inputs and outputs.
The program should be implemented as a set of functions with a main routine and at least one function for menu operations, two for getting input, one for printing, and all of the functions listed for the user choices. You may use many more functions than this but you must use at least this many. The purpose of functions is to divide the problem into small tasks, each one assigned to its own function and then to call the functions from main() or from another function when appropriate.
One good guideline for function size is to keep functions between 50 and 200 lines long unless the longer function content is truly obvious. If you find yourself writing virtually the same code in multiple places, then that code would probably make a good function which can be called in multiple places.
Do not code the entire program in main!
For Lab #5, you must split your program into at least three separate program files as follows:
All constants and type definitions in one file,
The main routine and the functions prototypes in one file, and
The remaining functions in one or more physical files.
Compile them all together with #include statements or with gcc to create the output a.out
The program should perform the following actions in the given order:
Declare and initialize the variables
Print a welcome screen for the user that introduces the system
Get the needed input values from the keyboard or file
Print the appropriate outputs
Let the user make additional choices until the user indicates that they are finished.
The program must be run and the output recorded in a script file from OMEGA using the gcc compiler.
No Exceptions! If you do not know how to create a script file, it is your responsibility to ask the TA, look for help on the class website, or OIT how to use this function.
You must come up with information to use as test data for 10 items of stock, 8 members of staff, and 5 rooms as a minimum. See the Miscellaneous section below for other useful info.
This program must be run with the different sets of test data a given in your test plan for the input data. This is what gets recorded in the script file.
You must create two different data sets and run your program with both of them. I have given you a small amount of sample data for you to use as a model. You may run your program two times within a single execution or you may execute the program two different times so that you have a total of two different data sets. The sample data sets that you create must meet the guidelines given in the problem definition. Your test runs should demonstrate all the choices that are available in your program.
NOTE ABOUT ERRORS:
Programs turned in for credit MUST compile and run WITHOUT any compilation errors or runtime errors using the gcc compiler on omega. No other compiler may be used for the compilation for credit. No other operating system may be used for the compilation and/or execution for credit.
Compilation errors occur while the program is being developed and they prevent the program from compiling correctly. Programs compile correctly when running
>gcc mymainprogram.c myheader.h myfunctions.c
gives no error or warning messages.
Programs may be turned in for credit when they are partially complete but all completed functions must run without any errors. A program completes without runtime errors if it ends only when the user selects for the program to end and it correctly prints the exit message. Partially complete programs that run correctly for all implemented menu choices will receive partial credit.
Any other type of ending is a runtime error or a "crash". A program has a runtime error if it compiles and runs but then crashes in any situation, i.e. if there is any set of legal choices the user can make that will make the program crash. It is your responsibility to test all possible choices in your program to make sure that none of them cause a runtime error. The goal of creating input test data and running your program with it should be to test all of the various choices in your program to make sure all of them terminate correctly. For Lab #5 you, the programmer, are not responsible for errors of data type committed by the user in the input data. You are responsible for errors of data value in the input data.
Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)
Program header and function headers for all functions, and
(line comments and block comments), and
Style (indentation, consistency, meaningful identifiers,
lateral separation of code from line comments, etc.) (6 points)
Modularity (division of the problem into small tasks, each one assigned to its own function
and called from main() or from another function when appropriate
--do not code the entire program in main!) (3 points)
definition of all struct types including struct pointes (3 pts)
Correct manipulation of struct data of all kinds of structs (5 pts)
Correct construction of sorted singly linked list (6 pts)
Correct use of command line parameters for filename input (4 pts)
Correct test condition functions written for search and/or sort (3 pts)
Correct modification/rewriting of menu functions to handle linked lists of structs (6 pts)
Correct use of pointers to functions for passing in test condition functions to search and/or sort (3 pts)
Correct use of multiple files as defined (4 pts)
Proper implementation of file input and input error checking (3 points)
Proper implementation of line of data input including error checking (3 points)
Correct implementation of bubble sort algorithm (4 points)
Correct implementation of selection sort algorithm (2 points extra if used)
Correct implementation of linear search algorithm (2 points)
Proper implementation of add and delete stock and error checking
Validate new values (1 pts)
Add values (2 pts)
Delete values (2 pts)
User clearly understands what is being requested for input (3 points)
Linked list correctly developed initially (3 pts)
Linear Search tasks perform correctly with test functions passed in (4 points)
List-all tasks perform correctly (2 points)
Calculate tasks perform correctly (3 points)
Bubble Sort tasks perform correctly with test functions passed in (4 points)
Selection Sort tasks perform correctly (2 points extra if implemeted)
Linked list correctly manipulated for sorting and updates (5 pts)
Additions - tasks perform correctly (2 points)
Deletions - tasks perform correctly (2 points)
Input verification shows valid values and list of inputs correctly saved and printed (2 points)
Output gives clear information to explain the values to the user (2 points)
Output follows test data plan (2 pts)
Output contains all test data set as defined (2 points)
At least two test data files turned in with assignment (4 points)
Design document development order is well thought out (2 pts XC on lab)
Use of global variables will result in an overall grade of 0 (zero) [-100 deduction]
Use of the exit, break (outside a switch), or continue command
will result in an overall grade of 0 (zero) [-100 deduction]
Labs which cannot be compiled or do compile with warnings
will receive an overall grade of 0 (zero) [-100 deduction]
Labs which have errors in them and do not terminate normally
will receive an overall grade of 0 (zero) [-100 deduction]
Missing or late submission of design document
will result in an overall grade of 0 (zero) UNLESS
student has obtained instructor approval by e-mail [-100 deduction]
Missing test plan document will result in 50 point deduction [-50]
Late submission of softcopy of code and/or script file
will result in an overall grade of 0 (zero) PERIOD for Lab #5
Use of C language elements not yet discussed in class by the lab due date
will result in potential deduction of points - discuss with instructor before using.
[This is a sample data set that can be put in a file as test data. Make sure the file is plain text only.]
500.00 250.00 50.00 15000.00 1 12 2012 3 N M A 10 4 3 2 M F 2 10 4 S T B O 2 1 2 1
124456 N 4.50 2.3 8 5 Harry Potter and the Philosopher's Stone
124457 N 4.50 2.3 4 3 Harry Potter and the Chamber of Secrets
124458 N 5.00 2.0 3 3 Harry Potter and the Prisoner of Azkaban
124459 N 5.00 2.2 3 3 Harry Potter and the Goblet of Fire
124460 N 5.50 2.2 1 3 Harry Potter and the Order of the Phoenix
124461 N 6.00 2.0 2 3 Harry Potter and the Half-Blood Prince
124462 N 6.50 2.0 2 3 Harry Potter and the Deathly Hallows
124531 N 2.25 2.5 2 2 Fantastic Beasts and Where to Find Them
124532 N 2.25 2.5 2 2 Quidditch through the Ages
124533 N 3.00 2.0 3 2 The Tales of Beadle the Bard
392554 M 5.55 2.75 4 2 Sargent Pepper's Lonely Hearts Club Band
392563 M 5.50 2.5 2 2 The White Album
392571 M 5.60 2.55 2 3 Rubber Soul
392588 M 5.40 2.6 2 2 Yellow Submarine
814456 A 6.0 1.5 2 1 Harry Potter and the Philosopher's Stone
814461 A 6.10 1.4 2 2 Harry Potter and the Half-Blood Prince
814462 A 6.0 1.7 2 3 Harry Potter and the Deathly Hallows
Kate Daniels F 6540 10 2 2010 H 10.00 160 7 5 1985 45 Trail Ave, Savannah, GA 31244 912-465-2020
Andrea Kane F 4734 9 9 2010 H 12.00 160 9 23 1984 342 White St, Atlanta, GA 30345 404-833-1889
Raphael Ware F 7344 4 5 2011 H 8.50 80 3 3 1980 224 Peachtree St, Atlanta, GA 30365 404-929-3444
Beatrice Ware M 2453 4 1 2008 S 3750.00 160 5 6 1960 65 Green St, Atlanta, GA 30365 470-908-3332
Jim Bent F 5545 7 2 2009 S 1654.75 160 8 3 1979 445 Suter Dr, Atlanta, GA 31136 470-598-2571
Dali Niesan F 7393 3 15 2012 H 7.35 80 8 23 1992 2022 6th Ave, Decater, GA 31876 678-223-3565
Brenna Loop F 6399 9 4 2010 H 9.95 120 12 15 1990 213 Forest St, Atlanta, GA 31154 404-929-7285
Julie White F 4392 11 1 2009 S 2200.00 160 2 9 1979 1600 8th St. Smyrna, GA 32566 470-713-6545
Derek Sims M 3327 3 8 2007 S 3405.50 160 4 14 1972 42 Ninth Ave, Roswell, GA 32245 678-432-4378
Rowena Gale F 4530 1 15 2010 H 11.10 160 5 13 1988 1600 8th St. Smyrna, GA 32566 470-843-3343
Peter Weiss F 6772 5 22 2011 H 8.00 80 11 29 1987 3498 Macon Dr, Atlanta, GA 31167 404-452-9345
Red Moore F 8128 9 1 2012 H 7.25 40 5 6 1994 892 Penn Ave, Marietta, GA 34276 770-334-8765
S 1 40 0 60 0 22.00 Main room
124456 4 124457 2 124458 2 124459 2 124460 1 124461 1 124462 2 124533 2 124532 2 124531 1
S 2 20 6 20 8 22.00 Media room
392554 3 392563 2 392571 2 392588 2 814456 1 814461 1 814462 2
T 1 20 0 20 0 18.00
124456 4 124457 2 124458 1 124459 1 124461 1 124533 1 124531 1 392554 1 814456 1 814461 1
B 1 10 6 10 0 25.00
B 2 9 6 10 0 25.00
O 1 15 3 10 4 18.00