Lab #3 Assignment
CSE 1320-001
Summer 2011
Due Date: See class website for due date
(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 Chapters 1-6 and parts of later chapters in Foster and Foster as covered in class. It is assumed that the student is familiar with and can use all the concepts in those chapters. This assignment is designed to practice those concepts by creating a C program. This lab will introduce students to Dr. T's approach to lab assignments and to reinforce and refresh 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.
Topics:
Structs
Recursion
Algorithms
One-dimensional Array
Strings
Control structures
Functions
Arithmetic and relational operators
Input and output,
Passing parameters
Data types
Global constants
Pre-processor directives
Searching
Sorting
Program design
Modular programming structure
Error checking
Programming style
Compiling code,
Executing code,
Debugging and 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: This semester our theme will be working on a support system to manage information for a theater company. You are going to put together a small database of information to help make show reservations and to handle other aspects of the theater production. 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 phaseof 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.
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), continue, structs, passing by reference (except arrays), or linked lists.
Assumptions for the lab #3:
1) A maximum of 15 shows per week are allowed. Use constants to define the max value.
2) Strings will have a maximum length that will be given.
3) The maximum number of shows for Lab #3 is 12. Use constants to define the max value.
Problem: The data in your database will be information about plays, musicals, dramas, comedies, and other live shows in local theaters, information about the shows and tickets for them, and other data needed regarding the shows. As part of this assignment you will have to find real data about local theater shows to use as test data for your program.
Your program will really be two related parts. First in the data-entry phase the user is entering all the data needed to find and manipulate the show data. You can imagine that this user is someone who works for the theaters and is entering all this data. This will be the first task that happens when someone starts running your program.
The data they entering will be the theater information that you have researched to use as your test data. Getting all the input data for the shows from the user and storing it in arrays, will all happen in the data-entry phase of the program. After getting all the input data for the shows from the user, your program will then go into menu-driven phase. This will allow the user to do the following tasks. These tasks are actions that a theater patron might want to perform:
1) Using the data in the arrays,
A) Search for a show by
i. Type of show
ii. Theater location
iii. Date of show
iv.Tickets sold
B) Calculate
i. Purchase of tickets for the show and find total cost
ii. Number of times the show will be performed
C) List all the shows that meet certain criteria
i. Less than given cost
ii. Before or after a given date
iii. In the same city
D) Sort the data by
i. Show code
ii. Show date
iii.Show name
iv.Number of times the show will be performed
2) Update the data in the arrays-this will take the user to a submenu for doing updates
3) End the program
Data Description: For lab #3, you will be storing the input data in a struct type for a show stored in a single array. The show struct will have two date structs and an array of weekly performance structs in it.
The data members of the show struct type and descriptions are given below. Following this first list, the data elements are described by type.
1) Show code - a four (4) digit integer where the 1000s place represents a city, the100s digit represents a theater company and the other two digits indicate a specific show. The guidelines for the city codes and theater company codes are given at the end of the assignment.
2) Show name - a string less than 120 characters long that gives the show name. In lab #3 we are using strings and reading them in with the getline command in order to allow blanks in the string. i.e. Jeeves in the Morning is a show name string
3) Genre letter code - a letter representing the kind of show. Choices are:
D Drama
C Comedy
S Suspense
F Fantasy
M Musical
V Variety
R Revue
I One man show
O Any other type of show - such as a special performance
4) Show start date as day, month, and year - three separate numbers read into a date struct which is part of the show struct type
5) Show end date as day, month, and year - three separate numbers read into a date struct which is part of the show struct type
6) Number of shows per week
Data for each show per week should be stored in a weekly performance struct that is in an array stored as part of the show struct.
6a) Day of show as a letter (for each show in a week)
S Sunday
M Monday
T Tuesday
W Wednesday
R Thursday
F Friday
A Saturday
6b) Start time of show (in hours and minutes) - save as a floating point value HH:MM
6c) Show designation as a letter
R Regular
M Matinee
L Late showing
6d) Cost per adult ticket for this show in dollars and cents - save as a floating point value
6e) Current Tickets sold for this show – kept as a running total
6f) Number of adults attending (age 18 or older) – kept as a running total
6g) Number of children ages 2 through 17 – kept as a running total
6h) Number of infants less than age 2 – kept as a running total
7) Total number of available seats for the show
8) Length of show from start to end in minutes
9) Show run – number of performances calculated from previous data
The format for each piece of data is listed below.
You will declare a struct show type. This data type will have all the info listed above as data members of the struct. You will also declare a struct type to hold a date and a struct type to hold the data for one weekly performance. The show struct will have two date structs in it – one for start date and one for end date. The show struct will also contain an array of the weekly performance structs. To store your data for all the different shows, you will declare an array of show structs called myshows.
As an example, let's say the user is going to enter data for two shows. The first show will be to see “Alice Wonder” (code 1310) and the second show will be “The Hobbit” (2108). For each show you will be asking the user for all the pieces of data listed above and storing this data into the current show struct in the array. The different shows, in this case the first show and second show, will be stored in the first and second struct in the array. The number of elements in the myshows array is the same as the maximum number of shows that can be stored. (12 for this lab)
To store data in the struct show array, you select the appropriate member of the struct and assign the data to that member. Therefore the show code for Alice Wonder would be stored in myshows[0].showcode and the start day of the show would be myshows[0].start.day. Likewise, to store the cost of the 5th weekly showing of the 3rd show in the array, you would use myshows[2].weekly[4].cost.
As you read in the shows, you will be numbering them from 0 up to the max number of shows. This is the shownumvalue used below.
------
Show code - a four (4) digit integer where the 1000s place represents a city, the 100s digit represents a theater company and the other two digits indicate a specific show. The guidelines for the city codes and theater company codes are given at the end of the assignment. You will have to validate the 100s place and 1000s place of any code entered by the user. For the first show, the show code would be read in and error checked. If the value is valid, i.e. it passes error checking, then it is stored in myshows[shownum].showcode
Show name - a string with blanks of up to 64 chars in length. The show name will be read in with getline into a temporary string of length 128. The length of the string should be checked using the strlen command. If the string is less that 64 chars in length then it should be copied to myshows[shownum].shownamein the array. showname should be declared as a character pointer in the struct and space should be dynamically allocated for exactly the length of the show name when it is read in.
Genre letter code - a single character representing the kind of show. It must match one of the valid codes. If it is valid, it should be stored in the array myshows[shownum].genre
Show start day is an integer value. It should be error checked and then a valid day value stored in the date struct atmyshows[shownum].start.day.
Show start month is an integer value. It should be error checked and then a valid month value stored in myshows[shownum].start.month.
Show start year is an integer value greater than 2000 and less than 2050. It should be error checked and then a valid year value stored in myshows[shownum].start.year.
Show end day is an integer value. It should be error checked and then a valid day value stored as appropriate.
Show end month is an integer value. It should be error checked and then a valid month value stored as appropriate.
Show end year is an integer value greater than 2000 and less than 2050. It should be error checked and then a valid year value stored as appropriate..
Number of shows per week is an integer value. It should be error checked and then a valid value stored atmyshows[shownum].perweek
For each show in a week, the following for data items must be requested and stored:
Day of show is one letter per weekly show. It should be error checked and then a valid type code stored at
myshows[shownum].weekly[weekshow].doshow where weekshow indicates which show during the week this is.
Show designation is one letter per weekly show. It should be error checked and then a valid type code stored at
myshows[shownum].weekly[weekshow].desig where weekshow indicates which show during the week this is.
Start time for a show is a floating point value in the form HH.MM where HH is the hours in military time and MM is the minute value. It should be error checked and then a valid start time stored atmyshows[shownum].weekly[weekshow].starttime
Cost per adult ticket is a floating point value. It must represent valid dollars and cents. The cost of a ticket can be free. A valid ticket price should be stored in the float array at myshows[shownum].weekly[weekshow].cost
Tickets sold is an integer value. It should be calculated from the number of adult, child and infant tickets selected and kept as a running total as more tickets are purchased. It should be updated whenever the user chooses to calculate and purchase tickets. It should also be checked against the available seats number to guarantee tickets are still available. This value should be calculated automatically by your program after a ticket purchase for a show is entered and as the user acts on the data and then stored atmyshows[shownum].weekly[weekshow].sold
Adult is an integer value. This should be initialized to 0. It will not be entered until the user reaches the menu functions. It should be error checked and then a valid number of adults stored atmyshows[shownum].weekly[weekshow].adult
Child is an integer value. This should be initialized to 0. It should be error checked and then a valid number stored atmyshows[shownum].weekly[weekshow].child
Infant is an integer value. This should be initialized to 0. It should be error checked and then a valid number stored atmyshows[shownum].weekly[weekshow].infant
Available seats is an integer value. It will be entered by the user and error checked for a reasonable value. This should be stored in myshows[shownum].seats
Show length is an integer value. It will be entered by the user as a number of minutes. It must be greater than 15 and less than 1440. This is the length of the entire show and should be stored in myshows[shownum].showlen
Show run is an integer value. It should be calculated from the number of days from the beginning to the end of the show, divided to get the number of weeks and then multiplied by the number of shows per week. If the number of weeks is a fraction, round up to the next whole number of weeks before multiplying. This value should be calculated automatically by your program after the data for a show is entered and stored atmyshows[shownum].run
Input Implementation: For Lab #3 the user must enter at least 5 shows and no more than 12. 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 shows they are entering. The program should check to make sure this count is between 5 and 12. [Note for development: start with a smaller number of shows then increase when program is working well.] If the user's number exceeds the max, the program should inform the user of the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (shownum= 0, 1, …count-1) to read and store input.
For Lab #3, you must implement TWO of the following three methods of input and you are REQUIRED to implement file input. In addition to file input you may implement either the individual data method or the line of data method or both. The three forms of the input are described below. The first question the program must ask the user is how they want to input the data. Your program must give them at least two choices of methods: File input (REQUIRED choice), Individual data method, or line of data input method. Once the user has chosen the method of input, all the input will be done that way for the current run of the program.
Individual data method:
a. Ask the user for the show code (don't forget explain codes for them.) Read in their number, make sure it is a valid code and then store it in the struct show array at the correct location. As an example of an explanation, you might tell the user "Please enter a show code. Codes should be four digits with the first digit representing the city, the second digit indicating the theater company and the last two digits just being a unique code…" and then you can list the cities and theater companies for them to use. See the Miscellaneous section at the bottom for the show code info.