Lab #1 Assignment , CSE 1320 Spring 2010
Due Date: See class website for due date
(see instructions on website for how to turn this in - "lab submission info")
Grade value; 10% (out of 100% for all grades) added to total of lab grades.
Topic objectives: Operators
Control structures
Multi-dimensional Arrays
Strings
Sorting
Program design
Modular programming structure
Error checking
Programming style
The goal for this lab is to provide an opportunity for practice of C program development and the C programming topics covered in Chapters 1-6 and parts of later chapters in Foster and Foster. It is assumed that the student is familiar with and can use all the concepts in those chapters for this assignment. This assignment is designed to practice those concepts by creating a C program.
This assignment also gives students a chance to practice or refresh their skills in using a Unix operating system, in debugging programs, and in testing programs. 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. The class instructor and the TAs will have office hours each week when students can come ask for help. See the website for this info.
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. You will be required to turn in a DESIGN DOCUMENT before the lab assignment is due. The goal of the design document is to assist you in developing the actual 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), continue, structs, passing by reference (except arrays), or linked lists.
* -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
As a student as a large university you have many activities and events that you can choose to attend. These events give you an opportunity to expand your worldview and learn things outside the classroom. However, there are so many of these events that it can be difficult to keep track of all of them. Your goal for this program will be to develop a computer program that helps students learn about events that are occurring on campus that they may wish to attend. This system will be a searchable calendar and database of upcoming events with categories of event types, event purpose and other info. Your system will have two main activities - first, a knowledgeable user, such as someone who arranges campus events, will input the event data to your system. Once this is done, the system will then become an information provider that a participant user would access to try to find interesting events to participate in.
Throughout the course of this semester you will work on your event database. Each lab assignment will build on the previous assignments and will also implement changes to make the system more efficient and so on. For this lab you will be creating components of the event database. You will implement a program that can hold data about events such as event name, purpose, event time, and so on. You will write functions that can retrieve data that matches certain criteria, that can modify the data, that can sort the data, that can output the data, and other tasks.
The tasks for this lab assignment will be:
¨ Introduce the event database to a new user.
¨ Create multi-dimensional arrays to store each type of event data in and then populate the arrays with data. (This is the knowledgeable user activity.)
¨ Create and display a screen menu of the following choices for the user. (This is the participant user activity.)
1) Using the data in the arrays,
A) Search for events by
i. Event type
ii. Event purpose
iii. Date
iv. Event name
v. Cost
B) Count how many events
i. Have a user-specified purpose
ii. Cost more than a given amount
C) List all the events that meet a certain criteria
i. Size
ii. Occur on the same day
iii. Less than a given cost
D) Calculate cost to attend all events
E) Calculate the average cost of an event
F) Sort the events according to
i. Event type
ii. Date
iii. Event name
iv. Cost
2) Update the data in the arrays-this will take the user to a submenu for doing updates
3) End the program
Each of these tasks is described in more detail below. There are also a number of simplifying assumptions for this lab. Many of these simplifications will be eliminated in later labs.
Simplifying assumptions for the lab:
a) Various constants will be given for use in the lab. These constants should be declared in your program using "const" or "DEFINE"
b) All events take place on the UTA campus. Later labs may not use this assumption
c) All events will have a unique number and a unique name. Names are one word strings with no spaces or blanks in the name.
Task Descriptions:
¨ Introduce the event database to a new user.
For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key.
¨ Create one-dimensional arrays to store each type of event data in and then populate the arrays with data.
For the lab, the following data will be used:
1. Number representing the event
2. Name of the event
3. Event type. Specifies the form of the event to occur. The following are the valid event types
C Concert
S Spectator
P Participatory - Competitive
N Participatory - Non-Competitive
D Dinner
L Lunch
B Breakfast
O Other
4. Purpose of the event. The purpose must be one of the following as denoted by the letter preceding it:
F - fun and social event
M - fine arts event; music, dance, art, theatre, comedy, and other types of arts activities
C - cultural; offers support and education related to a specific culture or group of cultures
S - sports; opportunities to play or support teams
V - volunteer event that does service activities of any type
L - leadership; opportunities for leadership on campus or learning skills for leadership
E - educational; offers some discipline-related content for student
A - academic; offers some sort of academic focused purpose such as tutoring, mentoring, study group, etc.
P - professional; focused on providing support to student for future professions
O - other
5. Event time consisting of
a. time of day given as hour and minute in military time (24 hour time)
b. day of the month given as a number
c. month given as a number
6. Size. Gives maximum number of event participants
7. Cost. Gives cost to participate/ attend event
For the lab, the data above will be stored in a set of multi-dimensional arrays. Each array will have 10 rows in it for a maximum of ten events being described. There should be four multi-dimensional arrays declared - one for all integer data, one for all float data, one for all char data and one for the name strings. (Use constants for these maximum values.) The data and arrays are described below:
Integer multi-dimensional array - the array will have 10 rows and four columns. Each column will represent one of the pieces of data below.
o Event number - the numeric code associated with a specific event. For this lab we will have a fixed set of events that are coded by number (ex. One Mike Stand = 842, Wheelchair Basketball Game = 110, FLOC Movie Night = 500, etc.) and that list would be displayed in the output as described below. For all the other pieces of data, the row index [n] for some event code will refer to the same event for all other info as well. (See the event code list at the end of this assignment and you can add to it if desired. If data is added, make a comment in your code describing the added data.) HINT: for the column index create a constant like EVNTNUM and set it to 0 then use arraynam[n][EVNTNUM] to store the event number for the nth event.
o Event month - the month info for the event. The event month [n] corresponds to event code [n]. Make sure that the event month that is entered is valid, e.g. how many months are there in a year? HINT: for the column index create a constant like EVNTMO and set it to 1 then use arraynam[n][EVNTMO] to store the month for the nth event.
o Event day - the date of the day of the of the associated event. Make sure that the number that is entered is valid, i.e. that it is a meaningful date for that month.
o Event maximum size - the maximum number of people that can attend or be involved in the associated event.
Character multi-dimensional array - the array will have 10 rows and two columns. Each column will represent one of the pieces of data below.
o Event type - the code of the event type. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters. HINT: for the column index create a constant like EVNTTYP and set it to 0 then use arraynam[n][EVNTTYP] to store the event type for the nth event.
o Event purpose - the code of the purpose of the associated event. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.
Floating point multi-dimensional array - the array will have 10 rows and two columns. Each column will represent one of the pieces of data below.
o Event hour and minute - the hour and minute info for the associated event. The hour and minute value will be entered as a single floating point number with the hour value to the left of the decimal and the minute value to the right of the decimal HH.MM . The value should be entered as military time, i.e. 24-hour clock instead of 12-hour clock. Make sure that the event hour and event minute that is entered are valid. The hour and minute [n] corresponds to event code [n].
o Event cost - the amount it costs to participate in the associated event. Make sure this amount is not negative but it can be free to participate.
Character multi-dimensional array for name strings - the array will have 10 rows and 20 columns. Each row will have a character string in it that is the name of the nth event. The names will be single words with no blanks and no spaces and the names will be no more than 19 characters in length.
For the lab, you must implement at least two of the following three methods of input. The first method will prompt the user for each piece of data about an event individually, the second method will allow the user to input all needed pieces of data about one event on one line, and the third method is to read lines of event data from a data file. The three forms of the input and the input data file are described below. (Just FYI, it is expected that most people will do the first two, but if you already know how to use files, than you are welcome to do that. We will talk about files later in the semester.)
For this lab the user must enter at least 7 events and no more than 10 events. Since the user has a choice, then the first piece of data that the program needs from the user is a count of how many events they are entering. The program should check to make sure this count is between 7 and 10. [Note for development: start with a smaller number of events then increase to 7 when program is working well ] If the user's number exceeds 10, the program should inform the user that 10 is the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (index= 0, 1, …count-1) to read and store input in one of the three following ways: Individual data method, line of data input method, or file of lines input method.
Individual data method:
a. Ask the user for the event code (don't forget to supply a list of names and codes for them.) Read in their number, make sure it is a valid code and then store it in the integer array at [index][EVNTNUM]
b. Ask the user for the month that the event meets. Make sure it is a valid number and then store it in integer array at [index][EVNTMO]
c. Do the same for the event day and event size. Be sure to check for validity of the data. [Note: checking validity where appropriate means to check the value IF there is something to check against. For meeting hours there is a clock to check against. For group size, there isn't anything to check against for this lab except to make sure the size isn't negative.]
d. For the data values that are letter codes (Event purpose, Event type), ask the user for the data using the single character descriptions (don't forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the character array at [index][EVNTTYP] or in the purpose location
e. Ask the user for the hour and minute that the event occurs. Make sure that the hour and minute values are valid and then store it in the floating point array at the appropriate row and column indices.
f. Ask the user for the cost of participating in that event. Make sure it is a valid value and then store it in the floating point array at the appropriate row and column indices.
g. Ask the user for the name of the event. Read it as a string into a temporary array and check the length. If the length is OK, copy it into the correct row of the name array.
Line of data input method:
Your program may ask the user to enter all the information for one event on the same line. This data would be an integer for event code, ints for event month and day and size, chars for purpose and type, a float for hour and minute, a float for cost and a string for the name. You must tell the user exactly how to enter the line of data. The data for a single event will be entered by the user as values on one line as follows {there must be one space only between the values}:
> 842 2 15 250 M C 20.00 10.00 One_Mike_Stand
which represents event 842 (One Mike Stand) on Feb. 15, with a maximum of 250 attendees. It is a fine arts concert starting at 8:00pm and it costs $10.00.
Your program will read the first number and store it in the integer array at some row index and column EVNTNUM, then read and store the month int into the corresponding row index and column EVNTMO in the integer array, then read and store the third number into row index and correct column in the integer array, and so on. Your program should read all the numbers and chars within a single input command. You may read the string in the same scanf command or in a separate command using either scanf or getline ONLY. Your program should read in as many lines of input for events as were originally specified by the count up to the maximum of ten lines of input (events).
File of lines input method
You may create a file that contains between 7 and 10 lines of event data and you may read the data from this file. To do this will requires creating file variables, opening the file and linking it to the file variable, and then reading the data from the file variable in the same way that a line of data would be read from the screen. The first line of data in the file should have only one integer on it which is the count of the number of lines of event data which follow in the file. (File input may or may not be covered in class prior to this lab's due date so you might have to learn this on your own if you wish to use it in the lab. It will be covered and required for later labs in the class.)
Input verification:
When the user has entered count number of events, print out all the input event 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. It is also suggested that a small function be written which will print the name of an event given the event code as input. The function could have a switch or a bunch of if statements in it.
¨ Create and display a screen menu of the following choices for the user.
Once all the data is read into the arrays your program should give the user a screen menu with the following choices: (use any number scheme you wish)
i. Search for an event by type
ii. Search for an event by date
iii. Search for an event by purpose
iv. Search for an event by name
v. Count how many events have a specific purpose as chosen by the user
vi. Count how many events have a cost more than some given amount
vii. List all the events that have a maximum size that is smaller than or equal to some number
viii. List all the events that occur on the same day
ix. List all the events that cost less than or equal to a given amount
x. Calculate cost to attend all events
xi. Calculate average cost to attend any event
xii. Sort the events by type
xiii. Sort the events by date
xiv. Sort the events by name
xv. Sort the events by cost
xvi. List all the events
xvii. Update the data in the arrays
xviii. End the program
The search functions should let the user choose the event type or event date or purpose code or name and then look through the list to find the first event that matches that type, then print a sentence stating that matching type/date/purpose/name was or was not found and if found, it should also print the code, the name, the month, and the day of the event.
The count function should let the user choose a purpose code or a cost and then go through the data and count (#) how many events have that purpose or are greater than that cost. The output should be a sentence stating that the number of events with that purpose or number of events more than that cost is #.
The size list functions should let the user choose a size value and then should print all the events that have a maximum of that size or smaller. Make sure to print a message at the top of the list explaining what is being printed.
The list events on the same day function should let the user choose a date (month and day) and then should print all the events that occur on that day. This one is a little tricky in that both month and day have to be checked. Make sure to print a message at the top of the list explaining what is being printed.
The list events that cost less is similar to the size list function.
The calculate function simply goes through and sums up all the costs for all the events. Print this sum with a message.
The average cost function should use the sum function and the total number of events to get its result. Print this average with a message.
The sort events functions should use the selection sort algorithm to put the list in order by the appropriate thing, either by type, by name, or by cost.
The sort events by date functions should use the bubble sort algorithm to put the list in order by date. The sort by date is the most challenging sort because it requires looking at the month and the day to sort.
The list events function is the same as the print function described for input verification.
The update option should take the user to a second screen to allow them to update information in the arrays. This screen should ask for a event code from the user and search for that event. Once the correct event is determined save its [rowindex] and give the user a menu of the following options:
o Change month, day, or size in the integer array at [rowindex]
o Change purpose or type in the character array at [rowindex]
o Change the hour/minute or cost in the floating point array at [rowindex]
o Return to main menu
For any change the user wishes to make, do the same error checking as in the original data entry section. After each change is made, print all of the event info for the event at [rowindex]. [Hint: If you write your data entry section with little functions for each input check then you can reuse them all here.]
When the user chooses "End the program" from the main menu, print a concluding message and then gracefully end the program.
Implementation requirements:
WRITE A DESIGN DOCUMENT FIRST. The design should 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.
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) or as some combination of those, but it must include the information listed for a), b), and c) 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. This design documentation will be turned in for the lab and a design will be required to be turned in for Lab 1 and all later labs. See the website for the DESIGN DOCUMENT due date.
The program should use the following data structures:
Multi-dimensional integer, character, and floating point arrays
Global CONSTANTS for specific values like array indices 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 - function calls should pass in actual parameter values and return values as appropriate
A while or for loop 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:
structs
any topic not covered in class before the lab DUE date unless approved by the instructor
The program should be implemented as a set of functions with a main routine and at least one function for the menu of operations, two for getting input, one for printing, one for each search function, one for each sort function, and one for each calculating function. You may use many more functions than this but you must use at least this many.
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
Print the appropriate outputs
Let the user enter additional values until the user indicates that they are finished.
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. See your instructor's website for SPECIFIC instructions about the program 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.
This program must be run with two different sets of test data for the input data. You must create one data set in addition to the one that I will give you and run your program with both of them. You may run it 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 set that you create must meet the guidelines given in the problem definition. It is recommended that you try to fill in your data with real information. In cases where you cannot find real data you may create the missing data.
The program must be run and the output recorded in a script file from OMEGA using the gcc compiler. 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.
NOTE ABOUT ERRORS:
Programs turned in for credit must compile and run without any compilation errors or runtime errors.
Compilation errors occur while the program is being developed and they prevent the program from compiling correctly. Programs compile correctly when running
>gcc myprogram.c
gives no error messages.
Programs may be 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.
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 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.
Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)
Grading scale:
Code: (57%)
Program header and function headers for all functions (4 points)
Comments (line comments and block comments) (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!) (6 points)
Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.) (6 points)
Correct manipulation of the multi-dimensional arrays and strings (9 points)
Correct use of required control structures (6 points)
Correct function structure as required (8 points)
Correct sort functions implemented (4 points)
Proper implementation of data input and input error checking (8 points)
Output: (43%)
User clearly understands what is being requested for input (5 points)
Search (find) tasks perform correctly (5 points)
List tasks perform correctly (4 points)
Calculate tasks perform correctly (4 points)
Selection sort tasks perform correctly (5 points)
Bubble sort tasks perform correctly (6 points)
Update tasks perform correctly (4 points)
Input verification shows valid values and list of inputs correctly saved and printed (4 points)
Output gives clear information to explain the values to the user (6 points)
Output contains all the given test data and one additional data set (5 points)
Grading Deductions:
Use of global variables will result in an overall grade of 0 (zero)
Use of the exit, break (except in a switch), or continue command will result in an overall grade of 0 (zero)
Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)
Use of structs or linked lists will result in 50 (fifty) point deduction per use
Late submission of softcopy of code and/or script file to appropriate TA will result in an overall grade of 0 (zero) without prior instructor approval
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.
Miscellaneous:
Event code list:
One_Mike_Stand = 842
Wheelchair_Bball = 110
Baseball_Game = 120
Bball_Game_Mens = 130
Bball_Game_Womens = 140
FLOC_Movie_Night = 500
Jazz_Ensemble = 803
Choir_Concert = 810
Solo_Recital = 874
Maverick_Speaker = 990
Engineering_Speaker = 318
EE_Speaker = 337
Engineers_Week = 301
Global_Grounds = 554
Art_Glass_Sale = 868
Library_Friends = 935
The_Big_Event = 4
Oozeball = 8
Bed_Races = 10
Sample data:
842 2 15 250 M C 20.30 10.00 One_Mike_Stand
990 2 19 1250 E C 20.00 10.00 Maverick_Speaker
554 1 30 35 C N 16.45 0.00 Global_Grounds