Lab #4 Assignment

CSE 1320-002

Spring 2012

 

Design Document Due Date:  April 12, 2012 at noon (12pm)

Lab Due Date:                        April 19, 2012 at noon (12pm)

(see instructions on website for how to turn this in - Òlab submission infoÓ)

Grade value:    11% 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Ð7 and parts of later chapters 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 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

            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 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:  For the rest of the semester you will be trying to determine a price to charge for an event and other data based on the venue size (number of seats), the fixed event costs, the amount of tickets you expect to sell, some profit margin, and other criteria.  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 typically 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, passing by reference (except arrays), or linked lists. You should do input and output using printf and scanf (you are allowed to use getchar and putchar if desired.)  You must use getline for string input.

 

Assumptions for the lab #4:

 

1) Strings will have a maximum length of 40 chars.  There are no restrictions on the contents of the string.  ÒBass HallÓ is a valid string input for this lab.  Use constants to define the max value.

2) The maximum number of different kinds of seating in a venue for Lab #4 is 5.  Use constants to define the max value.

3a) You will have a maximum of 15 venues for Lab #4 and a minimum of 8 venues.  These values will change in later labs.

3b) You will have a maximum of 20 events for Lab #4 and a minimum of 6 events.  These values will change in later labs.

4) For date checking in Lab #4, you may NOT make the simplifying assumption that all months have 30 days.  You must check dates accurately.

5) In Lab #4 you should use the built-in time functions to get the current date as the date to check against for a ÒfutureÓ date.

 

Problem:  The data in your database will be venues for events, event information, profit goals, and more.  As part of this assignment you will have to find real data about some venues and events 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 venue and event information that you have researched to use as your test data.  After getting all the input data from the user (and storing it in arrays), you will allow the user to do the following: (Many of these functions must be revised with new algorithms for Lab #4.)

 

1)   Using the data in the arrays,

      A)  Print all of part of the data in a table

      B)  Calculate

            i.    Best venue for an event

            ii.   Cost to set for ticket prices

      C)  List all the venues that meet certain criteria

            i.    Less than given usage cost per hour

            ii.   Larger than a given size

            iii.  In a given city as determined by the venue code

      D)  Search for a venue by

            i.    Type of venue

            ii.   Type of seating available

      E)  Search for an event by

            i.    Size of the event

            ii.   Type of event

            iii.  Cost of ticket price

      F)   Sort the venues by

            i.    Venue code

            ii.   Total seating

      G)  Sort the events by

            i.    Date

            ii.   Length of event

2) Update the data in the arraysÐthis will take the user to a submenu for doing updates, additions and deletions

3) End the program

 

 

 

Data Description:  For lab #4, you will be storing the input data in arrays of structs.  You will define at least three new struct data types Ð one for an event, one for a venue, and one for information about a single type of seating.  The seating struct will be used inside the venue struct as was demonstrated in class.

 

The data elements and descriptions are given below.  Following this first list, the data elements are described by type and by which struct they will belong to.

 

1) Venue code  - a four digit integer where the digits represent a venue location using the guidelines given at the end of the assignment. 

 

2) Venue name Ð a string less than 40 characters long that gives the venue name.  In lab #3 we are using strings for the name without simplification which means that the names can have spaces, e.g. College Park Center is a valid name.

 

3) Venue type Ð a letter representing the type of venue.  Choices are:

B Basketball arena

T Theater

A Auditorium

F Football stadium

C Concert hall

L Large room (seats > 150)

S Small room (seats <= 150)

O Outdoor performance area

M other miscellaneous type of venue

 

4) Venue kinds of seating (festival, selected, special, box, VIP) Р  an integer of value 1- 5 followed by that many letters of either F, S, P, B, or V. Must offer either festival or selected seating at a minimum.  The number represents how many types of seating are available and the letter code(s) indicate which kinds of seating they are.  Festival seating is seats that are not specifically assigned, selected means the seats are assigned in some way, box seats are unique seating areas that are partially enclosed in some way, VIP seats are any seats that are used for VIP guests, and special is any other type of seating which could include lousy seats like in the high balcony, seats in the stage wings, seats in the choir loft, etc. 

Ex: 3 F P B

 

5) Venue amount of seating of each kind Ð same number of values as previous info giving a list of number representing seats of the available types. Ex: for example above, 400 100 24

 

6) Venue cost per hour Ð a floating point money amount that is the amount that the venue charges per hour.  Ex: 500.00 to represent $500.00 per hour

 

7) Event date Ð Event date as day, month, and year - three separate numbers

 

8) Event type Ð a letter representing the type of event.  Choices are:

S Sports

A Arts and entertainment

C Community

P Public welfare

G Group participation

O Other

 

9) Event setting (intimate, average, large, mass) Ð they are ranges of performance preferences for audience size.  This will help select among venues if needed.  This is a letter representing one of the four setting sizes: I intimate (less than 300 people), A average (300 Ð 999 people), L large (1000 Ð 3999), M mass (4000+)

 

10) Fixed event cost Ð A floating point money amount that is the fixed amount charged for the performance/event

 

11) Event length in hours Ð An integer (must be > 0)

 

12) Desired profit percentage for event Ð A floating point number representing how much profit margin is desired.  33% is 0.33 (can be 0)

 

13) Desired profit fixed amount for event Ð A floating point number (can be 0)  that indicates a specific dollar amount of profit desired.

  

14) Percentage of kinds of seating in the venue expected to sell Р  Ticket types within any one kind of seating  are discounted and regular.  The values for this input are two floating point numbers representing how much of each kind of seating you expect to sell. Ex: 1.00 0.75 would indicate 100% of discounted seating is expected to be sold and 75% of regular seating.

 

15) Chosen venue for event Ð this will be the venue code of the venue where the event will be held. 

 

16) Recommended ticket prices Ð (up to 10 different values) Ð this value will be calculated and should be stored as floating point numbers.  The possible combinations are discounted Festival seating, regular Festival, disc. Selected, reg. Selected, disc. sPecial, reg. sPecial, disc. Box, re. Box, disc. VIP, and/or reg. VIP.

 

17) Count of venue entered Ð integer that is the number of venues the user entered data for.  Max is 15 and min is 8.  This number is determined by user input.

 

18) Count of events entered Ð integer that is the number of events the user entered data for.  Max is 20 and min is 6.  This number is determined by user input.

 

19) Percentage of seating that will discounted Ð floating point value.  In previous labs, this was a fixed amount of 15%.  Now you will allow the user to input this amount.

 

20) Percentage of seating that will be regular price Ð floating point value.  This must be calculated as 100% - discount percentage.

 

21) Event name

 

 

The format for each piece of data is listed below. 

 

You will create three struct types for the input data to be stored in.  The first struct type will be the event struct which will hold all the data items for the event.  The second struct type will hold all the data items for one venue including an array for the seating data.  The seating data will be another struct type and you will have an array of size 5 of the struct seating type as one member of the struct venue type.  Declare the struct types globally and then declare the arrays inside main.  You will have an array of VENUEMAX elements of type struct venue to store up to VENUEMAX venues, ex. you could name your array venues.   You will also have an array of EVENTMAX elements of type struct event to store up to EVENTMAX events, ex. you could name this array events.  

 

 

As an example, letÕs say the user is going to enter two venues and one event.  The first venue will be UT Arlington College Park Center (code 101 or 0101) and the second venue will be Bass Hall (code 221 or 0221).  The event will be a concert.  For each venue you will be asking the user for all the data about the venue and then  storing this data into the struct venue array.  The concert data will be stored in the struct event array  Each member of the struct will indicate a different piece of data about the event or venue.

 

For Lab #4 you will have maximum and minimum amounts of events and venues.  This information then dictates the sizes of the various arrays you will need.   

 

Make sure to declare all your constants (such as VENUEMAX or max string length) before you try to use.

 

 

Detailed descriptions of each data value.  The data values below must be stored as described.  You may also store additional values into these structs if desired.  In the descriptions below count represents the either the venue count or the  event count depending on which kind of data is being entered:

 

 

Venue data:  Other than the count of venues, all the other data should be defined as members of the struct

 

Count of venues entered Ð integer that is the number of venues the user will enter data for.  This number is determined by user input.  This should be error checked and then stored as an integer variable in the main function, e.g. totvenues.

 

Venue code  - a four digit integer where the digits represent a venue location using the guidelines given at the end of the assignment.  You will have to validate the digits of any code entered by the user.  For the first venue, the venue code would be read in and error checked.  If the value is valid, i.e. it passes error checking, then it is stored in the integer vcode member of the current venue struct in the array, i.e. venues[count].vcode where count represents the count +1 venue being entered.

 

Venue name Ð a string less than 40 characters long that gives the venue name.  The string will be read in  with a getline command into a temporary string.  The length of the string should be checked using the strlen command.  If the string is less that 40 chars in length then it should be copied to venues[count].venname.

 

Venue type Ð a single character representing the kind of venue.  It must match one of the valid venue type codes.  If it is valid, it should be stored in the array venues[count].vtype.

 

How many kinds of venue seating Ð an integer of value 1 - 5.  If it is valid, it should be stored in the array venues[count].vkindsstg.

 

Venue cost per hour Ð a floating point money amount that is the amount that the venue charges per hour.  This value is stored in the array at the vcost member for this venue, i.e. venues[count].vcost where count represents the count +1 venue being entered.

 

Venue seating info Ð an array of type struct seating with 5 values.  The array members must include either F or S at minimum to be valid.  The number of array members with letters stored is determined by the How many value just described.  The venseating array can hold 5 seating structs.  The seating struct is described below.

 

 

Seating data: The seating data struct will contain

 

Venue kind of seating  Р One letter of either F, S, P, B, or V.  The letter that is read is stored in the venkind member of the seating struct in the venue array, i.e. venues[count].venseating[k].venkind  where k is a counter from 0 to venues[count].howmanykindsofseating -1.  The letter should be error checked to make sure it is valid and to make sure that the same letter is not already stored in the array.

 

Venue amount of seating of each kind Ð a number representing seats of the current type. The value that is read is stored in venues[count].venseating[k].venamount .

 

Percentage of seating that will discounted Ð floating point value representing the portion of the seats of the current kind and amount will be sold at a discount.  In previous labs, this was a fixed amount of 15%.  Now you will allow the user to input this amount.  The amount should be between 0.0 and 1.0 where .5 would represent 50%, .15 would be 15% and 1.0 is 100%.  Error check the amount and store it in the discperc member of the seating struct, i.e.venues[count].venseating[k].discperc .

 

Percentage of seating that will be regular price Ð floating point value.  This must be calculated as 100% - discount percentage and stored at venues[count].venseating[k].regperc .

 

Percentage of kind of discount seating expected to sell Р  floating point value representing how much discounted seating you expect to sell within the current kind of seating for a venue.  Ex.  For kind of seating of P, then there will be a percentage value ex. 0.9 which would represent 90% of discounted seats. This data is stored in the venseating array.  Ex. venues[count].venseating[k].discoccupied

 

Percentage of kind of regular seating expected to sell Р  floating point value representing how much regular seating you expect to sell within the current kind of seating for a venue.  Ex.  For kind of seating of P, then there will be a percentage value ex. 0.75 which would represent 75% of regular seats. This data is stored in the venseating array.  Ex. venues[count].venseating[k].regoccupied

 

Regular recommended ticket price Ð floating point value representing how much you will sell regular seating for within the current kind of seating for a venue.   This value will be calculated and should be stored as a floating point numbers This data is stored in the venseating array.  Ex. the regular price would be stored in venues[count].venseating[k].regprice

 

Discoun recommended ticket price Ð floating point value representing how much you will sell discount seating for within the current kind of seating for a venue.   This value will be calculated and should be stored as a floating point numbers This data is stored in the venseating array.  Ex. the regular price would be stored in venues[count].venseating[k].discprice

 

 

Event data:

 

Count of events entered Ð integer that is the number of events the user will enter data for.  Max is 20, min is 6.  This number is determined by user input.  This should be error checked and then stored as an integer variable in the main function, e.g. totevents.

 

Event date Ð Three integers representing the event date as day, month, and year - three separate numbers.  These values are stored in event[evcount].evday and then in event[evcount].evmo  and event[evcount].evyear.  The dates should be error checked.    You must check that the date is in the future compared to the current date.  We will talk about the build-in time functions to use to check this.

 

Event type Ð a letter representing the type of event.  It must match one of the valid event type codes.  If it is valid, it should be stored in the array event[evcount].etype.

 

Event setting  Ð a letter representing one of the four setting sizes. It must match one of the valid event setting codes.  If it is valid, it should be stored in the array event[evcount].esetting.

 

Event length in hours Ð An integer (must be > 0). This value is stored in event[evcount].evlen.

 

Fixed event cost Ð a floating point amount (must be >= 0).  This value is stored in event[evcount].ecost.

 

Desired profit percentage Ð a floating point number between 0 and 1 inclusive.  This limits the profit to 100% of the cost, i.e. if the cost is $5000 then the whole event should raise $10,000 to pay the cost and make 100% profit. This value is stored in event[evcount].profitp.

 

Desired profit fixed amount Ð A floating point number of dollars (must be >= 0).  This indicates that the user cannot plan to lose money on the event.  This value is stored in event[evcount].profita.

  

Chosen venue for event Ð integer venue code of the venue where the event will be held. Store in the array at event[evcount].evenue.  This is determined by the program and stored.

 

Event name Ð a string less than 40 characters long that gives the event name.  The string will be read in  with a getline command into a temporary string.  The length of the string should be checked using the strlen command.  If the string is less that 40 chars in length then it should be copied to event[evcount].eventname.

 

 

 

Data entry phase

 

Input Implementation:  For Lab #4 the user must enter at least 8 venues and no more than 15 and at least 6 events and no more than 20.  Since the user has a choice, then the first piece of data that the program needs from the user are counts of how many venues and events they are entering.  The program should check to make sure this counts are appropriate. [Note for development: start with a smaller number of events then increase to the required minimum 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 the maximum of venue or event number of times (num= 0, 1, Émaxnumber-1 where maxnumber is venue count or event count whichever is greater) to read and store input.  You also have the choice to make two separate loops; one to enter all of the venue data for all venues and then one to enter all event data for all events.

 

For Lab #4, you must implement at least two of the following three methods of input and file input is REQUIRED.  The first method will prompt the user for each piece of data 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 will read lines of data from an input file.  File input is required. The three forms of the input are described below. After getting the count of events from the user, 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 either individual data method or 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 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 when you are updating data in the arrays during the menu-driven phase of the program.

 

Individual data method:

 

Within a loop that uses num and the loop counter and will run for the number of venue (totvenues) times:

 

a.         Ask the user for the venue 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 array at the current struct  [num] at member vcode e.g. venues[num].vcode.  As an example of an explanation, you might tell the user "Please enter a venue code.  Codes should be four digits with the first two digits representing the city and the last two digits representing a specific locationÉ" and then you can list the cities and venues for them to use. See the Miscellaneous section at the bottom for the venue code info.

b.         Ask the user for the venue type letter and give them the choices. Check to make sure it is a valid type.  Store this valid character in the array.

 

c.         Ask the user how many kinds of venue seating there are  and check that they enter only 1 - 5.  Store the number of kinds of seating in the array.

 

d.         For each kind of seating, loop and do the following (the loop counter should be less than the how many kinds of seating):

1.         Ask the user for a letter representing a kind of seating at the venue and give them the choices.  Check that they entered a valid code letter and also check that they have not already entered this kind of seating for this venue.  If valid, then store it at venues[num].venseating[loopcounter].venkind  . 

2.         Ask the user for the amount of that kind of seating available at the venue.  Check that they entered 0 or a positive number and then store it in the array .

3.         Ask the user what percentage of this kind of seating will be discounted.  Error check the amount and store it in the discperc member of the seating struct, i.e.venues[num].venseating[loopcounter].discperc

4.         Ask the user what percentage of discounted seating you expect to be occupied, i.e. sold.  Check that this is a floating point value between 0 and 1.00 and store in venues[num].venseating[loopcounter].discoccupied.

5.         Ask the user what percentage of regular seating you expect to be occupied, i.e. sold..  Check that this is a floating point value between 0 and 1.00 and store in venues[num].venseating[loopcounter].regoccupied.

 

e.         Ask the user for the venue cost per hour.  Check for validity and save this value in venues[count].vcost

 

f.          Ask the user for the name of the venue with a maximum length.  Read it into a temporary string and check the length.  If it is OK, store it into the array.

 

 

Within a loop that will run for the number of event times (totevents): (This can be the same loop as above or it can be after all the venue data is entered.)

 

g.         Ask the user for the month, day, and year for the event.   Make sure it is a valid date, i.e. it is a real date and it is in the future, and then store it in event[evcount].evday and then in event[evcount].evmo  and event[evcount].evyear.  The dates should be error checked.    You must check that the date is in the future compared to the current date.

h.         Ask the user for the event type letter and give them the choices. Check to make sure it is a valid type.  Store this valid character in the array at event[evcount].etype.

i.          Ask the user for the event setting letter and give them the choices. Check to make sure it is a valid type.  Store this valid character in the array.

j.          Ask the user the length in hours of the event.  Check that the data is valid and store in array.

k.         Ask the user for the fixed cost of the event.  Check for valid data and store in array.

l.          Ask the user for the desired percentage of profit to make from the event.  Check for valid data and store in array.

m.        Ask the user for the desired fixed amount of profit to make from the event.  Check for valid data and store in array.

n.         Ask the user for the name of the event.  Check the length and store in the array.

 

 

Line of data input method:

 

Your program may ask the user to enter all the information for one venue and/or one event per line.  Both may be on the same line or you may ask about venues first one per line then events one per line.  The venue and event info would be all the pieces of data listed above.  You must tell the user exactly how to enter the line of data. 

 

The data for a single venue and event will be entered by the user as values on one line (or two lines) as follows {there must be one space only between the values}.  Here's an example:

 

prompt> 0104 L 1 F 400 0.45 1.00 0.75 500 Bluebonnet Ballroom UTA 24 2 2012 G A 7 9600.00 0.1 1000 ACM Annual Dinner

 

which represents the UTA Bluebonnet Ballroom (code 0104, name ÒBluebonnet Ballroom UTA", Large room) with one kind of seating (Festival) and 400 total seats.  45% of the seats will be discounted and 100% of discounted tickets are expected to be sold and 75% of regular price tickets.  The hourly rental is $500.  The event is on Feb. 24, 2012 and it is an Average sized, Group participation event called the ACM Annual Dinner.  The event timeline is 7 hours, the fixed costs are $9600.00, the desired profit is 10% and $1000.

 

And a second example:  [NOTE: this example is longer because the venue has two kinds of seating instead of one]

 

> 0221 T 2 S P 850 150 0.1 0.02 0.90 0.75 0.7 0.65 1200  Bass Hall 5 3 2012 A L 12 47000.00 0.4 100000 Lyle Lovett and his Large Band

 

which represents Bass Hall (code 0221, name ÒBass HallÓ, Theater) with two kinds of seating (Selected and sPecial) and with 850 and 150 seats respectively.  10% of Selected seats will be discounted and 2% of sPecial seats will be discounted.  90% of discounted Selected tickets are expected to be sold and 75% of regular price Selected tickets.  70% of discounted sPecial tickets are expected to be sold and 65% of regular price sPecial tickets. The hourly rental is $1200.  The event is on March 5, 2012 and it is a Large, Arts and entertainment event, a concert by Lyle Lovett and his Large Band.  The event timeline is 12 hours, the fixed costs are $47000.00, the desired profit is 40% and $100,000.

 

Alternately, you could have the user enter all the venue data first, one venue per line, then all the event data, one event per line.  Ex.

 

> 0104 L 1 F 400 0.45 1.00 0.75 500 Bluebonnet Ballroom UTA                 Alternate order of seating items is OK.  Ex. below

> 0221 T 2 S P 850 150 0.1 0.02 0.90 0.75 0.7 0.65 1200 Bass Hall             > 0221 T 2 S 850 0.1 0.90 0.75 P 150 0.02 0.7 0.65 1200 Bass Hall

 

> 24 2 2012 G A 7 9600.00 0.1 1000 ACM Annual Dinner

> 5 3 2012 A L 12 47000.00 0.4 100000 Lyle Lovett and his Large Band

 

Regardless of how the data is entered, your program will read the first number and store it in the array at the correct location, then read and store the character into the corresponding location in the array, 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 for venues and events as were originally specified by the count up to the maximum for venues and/or events. 

 

 

File input method:

Your program may ask the user to enter all the information for all the venues and events from a file.  The file would have one venue and/or event per line.  The data for one venue or event in the file would be exactly the same data you would use for line of data input in exactly the same format. 

 

You must create a data file that contains at least 14 lines of data and you must read the data from the file.  To do this requires creating file variables, opening the file and linking it to the file variable, and then reading the data from the file variable using fscanf and getline in the same way that a line of data would be read from the screen.  

 

The first line of the file must have two integers on it.  The first integer represents the number of venues and the second integer represents the number of events.  The format of the data in the file should match the format of the data you use for the line of data method.  This means that if you have the user enter venue and event data on the same line in line-of-data method that your file should be the same.  Else, if you have the user enter only venue data on a line then only event data on separate lines, your file should do the same.

 

If the user chooses file input, then your program must first get the name of the input data file to use.  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;        

char *filename;           

FILE *infile;

 

printf("Please enter the complete name of your data file:  ");

getline(&filename, &filenm, stdin);                                       

if (filename != NULL)                                                           

            infile = fopen(filename, "r");                                      

 

 

Input verification:

When the user has entered their specified number of venues and events, 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.  It is also suggested that a small function be written which will print the name of a venue given the venue code as input.  The function could have a switch or a bunch of if statements in it.

 

Task Description: (Menu-driven phase)

 

Once all the data is read into the arrays your program should give the user a main menu with the following choices:  (use any number scheme you wish)

 

 

A)  Print all the data for all venues

B)  Print all the data for all events

C)  Print all data for a single venue

D)  Print all data for a single event

 

E)  Determine the best venue for an event

F)   Calculate price to charge for tickets

 

G)  List all the venues that cost less than a given amount per hour

H)  List all the venues that are larger than a given size

I)   List all the venues that are in a given city as determined by the venue code

 

J)   Search for a venue by venue type

K)  Search for a venue by the type of seating that is available

 

L)  Search for an event by the size of the event

M) Search for an event by the type of the event

N)  Search for an event by the cost of tickets

 

O)  Sort the venues by venue code

P)   Sort the venues by total seating

 

Q)  Sort the events by date

R)  Sort the events by length

 

S)   Update the data in the arraysÐthis will take the user to a submenu for doing updates

T)   End the program

 

 

The print functions let the user select to print one venue or event or all of them.  These functions should call the function that is discussed in the input verification section above.

 

The determine-best venue function will look at features of the venue and the event to determine the best match.  The best matching venue shall be stored with the event as the chosen venue.  The decision procedure is:

            Look at event setting, add up all the seating in the venue and compare:

            If venue seating is less than minimum size of event setting,

                        then do not choose the venue

            If venue seating is more than 50% larger than maximum event setting size,

                        then do not choose the venue

            For venues that fit,

                        Choose the venue that is closest in size to the maximum event setting size and meets the following requirements:

                                    If event is Sports,

                                                then venue must be B, F, O, or M type

                                    If event setting is Intimate,

                                                then venue must be T, A, C, L, or S type

                                    If event type is Group Participation,

                                                then do NOT choose A type

                                    Else choose the venue closest in size that doesnÕt violate any rules.

 

The calculate-price function has the following steps:

For each combination of regular and discounted tickets with a seating type, determine the expected number of tickets as:

 the number of seats times the percentage of seats they expect to fill of that ticket type divided by 100 and save this value. 

Ex: if there are 850 Selected seats, and if the user input 10% discounted seats then the number of discounted seats is 850 * .10 = 85.  Out of those seats we expect to sell 90% of the tickets so 85 * .9 = 77.  So we expect to sell 77 discount Selected seat tickets.  All remaining calculations would be similar (850 Ð 85 = 765 regular seats, 765 * .75 = 573 which would be 75% of the regular Selected tickets)  We will call these values:

numRS for number of Regular Selected tickets,

numRF for Regular Festival tickets,

numRP for Regular sPecial tickets,

numRB for Regular Box tickets,

numRV for Regular VIP tickets,

numDS for Discount Selected,

numDF for Discount Festival,

numDP for Discount sPecial.

numDB for Discount Box, and

numDV for Discount VIP.

 

You might want to create two members in the seating struct to hold regular numR and discounted numD ticket amounts so you can store these once they are calculated.

 

Once the ticket amounts are available, the ticket price is calculated as follows:

      Add the fixed event costs plus (event length hours * venue cost per hour) to get total cost

      Multiply desired percentage profit times total cost to get desired percentage amount

      Add the total cost, the desired percentage amount and the desired fixed profit amount to get

                  profit plus expenses (P&E)

There will be a fixed ratio of ticket pricing as follows:

      The basic ticket cost is considered to be the Regular Selected ticket cost (call this RS).

      The price of a Regular Festival (RF) will be 50% of the RS price.

      The price of a Regular sPecial (RP) ticket will be 300% of the RS price

      The price of a Regular Box (RB) ticket will be 500% of the RS price

      The price of a Regular VIP (RV) ticket will be 80% of the RS price.

      Ticket discounts are: Selected (DS) 15%, Festival (DF) 30%, sPecial (DP) 5%, Box (DB) 2%, VIP (DV) 50%

 

The total amount of money that is estimated to be brought in is the result of ticket sales.  The equation is:

      RS*numRS + RF*numRF + RP*numRP + DS*numDS + DF*numDF + DP*numDP + RB*numRB + RV*numRV + DB*numDB + DV*numDV

The num values will all be known or calculated from known values.  The ticket prices are what we need to calculate.  All the ticket prices are based on RS.  So if we rewrite the equation in terms of RS we get:

      RS*numRS + (RS*.5)*numRF + (RS*3)*numRP + (RS*5)*numRB + (RS*.8)*numRV +

      (RS*.85)*numDS + ((RS*.5)*.7)*numDF + ((RS*3)*.95)*numDP + ((RS*5)*.98)*numDB + ((RS*.8)*.5)*numDV = ticket sales

The goal then is to find a value for RS such that ticket sales >= P&E while keeping the tickets within purchasing range.

 

If we collect terms in the ticket sales equation we get to:

      RS*(numRS + (.5)*numRF + (3)*numRP + (5)*numRB + (.8)*numRV + (.85)*numDS + (.35)*numDF + (2.85)*numDP + (4.9)*numDB + (.4)*numDV) = ticket sales

Now we set this equation equal to P&E which is known and we can try to find a value of RS to make the equation work:

      RS =    (P&E) /

                  (numRS + (.5)*numRF + (3)*numRP + (5)*numRB + (.8)*numRV + (.85)*numDS + (.35)*numDF + (2.85)*numDP + (4.9)*numDB + (.4)*numDV)

If we can find RS, we now have the Regular Selected ticket price and all other prices can be calculated from that.

Once these values are calculated, they should be stored in the array.

 

The list-all-less-than-cost function should ask the user to enter an hourly venue cost maximum then go through every venue and print the complete information for all venues that have an hourly cost equal to or less than the userÕs entered cost.

 

The list-all-larger-than function should ask the user to enter a size, i.e. a total amount of seating the venue must exceed.  The function then goes through the venues, calculates total seating of each venue, and prints the complete information for all venues that have more than the requested amount.

 

The list-all-in-city function should ask the user to select a city and then go through every venue and print the complete information for all venues that have are in the selected city.

 

The search-by-type function should ask the user for a selected venue type and then use linear search to look through the venues to find the first venue that matches that type.  The function should print the complete info for that venue or print a message that no venue was found.

 

The search-by-seating function should ask the user for a selected seating type and then use binary search to look through the venues to find the first venue that has that type of seating.  The function should print the complete info for that venue or print a message that no venue was found.

 

The search-by-event-size should ask the user for a selected event size and then use linear search to look through the events to find the first event of that size.  The function should print the complete info for that event or print a message that no event was found.

 

The search-by-event-type should ask the user for a selected event type and then use binary search to look through the events to find the first event of that type.  The function should print the complete info for that event or print a message that no event was found.

 

The search-by-event-ticket-cost should ask the user for a maximum ticket price and then use binary search to look through the events to find the first event with tickets less than or equal to that price.  The function should print the complete info for that event or print a message that no event was found.  Note that the cost of the tickets has to be calculated for this to work.  This function should call the calculate price function for each event in order to make sure that all events have ticket prices.

 

The sort-by-venue-code should sort the venues in ascending order by venue code using the bubble sort algorithm.  The function should print the sorted arrays when this is done.  Remember that ALL the arrays, not just the code array, have to be sorted together for this to work properly.

 

The sort-by-total-seating function should sort the venues in descending order by total amount of seats using the selection sort algorithm.  The function should print the sorted arrays when this is done.  Remember that ALL the arrays, not just the code array, have to be sorted together for this to work properly.

 

The sort-by-date function should sort the events in date order from earliest to latest using the insertion sort algorithm.  The function should print the sorted arrays when this is done.  Remember that ALL the arrays, not just the integer array, have to be sorted together for this to work properly.  Sorting dates is a little tricky because it takes more than one comparison between each date but it is easier done in steps like the following:

      For any two events being compared,

            If the year of event A is greater than the year of event B

                        Then A is later than B,

            Else if the year of event A is less than the year of event B

                        Then B is later than A

            Else if the month of event A is greater than the month of event B (years are same)

                        Then A is later than B,

            Else if the month of event A is less than the month of event B

                        Then B is later than A

            Else if the day of event A is greater than the day of event B (months are same)

                        Then A is later than B,

            Else if the day of event A is less than the day of event B

                        Then B is later than A

            Else

                        A and B are on the same date (and they can stay in the same order they are in)

For the selection sort, you should keep track of the latest date you currently have in the current pass and that is the value that is swapped on that pass. 

 

The sort-by-event-length function should sort the events in order from shortest to longest using the merge sort algorithm.  The function should print the sorted arrays when this is done.  Remember that ALL the arrays, not just the integer array, have to be sorted together for this to work properly

 

The update option should take the user to a second screen to allow them to update information in the arrays.  This screen should print the venues and events in the database for them to choose from, ask whether they wish to update a venue or an event, get the appropriate info from the user for that data, and search for that item.  Once the correct event/venue is determined save its [index] and give the user a menu of the following options.  NOTE: for Lab #4, the user may choose to add or delete seating types within a venue.

 

 

      o   Change a venue size code

      o   Change a venue type of seating and/or the amount of those seats

      o   Add an additional type of seating and associated data for this venue

      o   Delete an existing type of seating and associated data for this venue  //ÓDeleteÓ means remove the values and replace them with 0s or other default values

      o   Change a venue hourly rental amount

      o...Change percent of discounted tickets expected to be sold for a given seat type

      o...Change percent of regular tickets expected to be sold for a given seat type

      o   Change the event date

      o   Change the event size

      o   Change the event length

      o   Change the event fixed cost

      o   Change the event profit percentage or fixed amount

      o   Add a new venue

      o   Delete a venue  //ÓDeleteÓ means remove the values and replace them with 0s or other default values

      o   Add an event

      o   Delete an event  //ÓDeleteÓ means remove the values and replace them with 0s or other default values

      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 info at [index].   [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.

 

 

***************************

 

 

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.

 

 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, passing by reference (except arrays), or linked lists.

 

Develop your program in small steps.  Test and debug as you go.

 

 

Implementation Requirements:

 

For Lab #4 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.

 

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.  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 #3 Design Document must be turned in in order for your Lab #4 assignment to be graded.

 

 

The program should use the following data structures:

            Multi-dimensional integer, floating point and string arrays, single-dimensional character arrays

            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

            Recursion for binary search and merge sort

 

The program should NOT use:

            global variables

            exit

            break (except in a switch)

            continue

            pointers (excluding passing arrays and use of string pointers if desired)

            any topic not covered in class before the lab DUE date unless approved by the instructor

 

Programming practices:

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:

 

Example 1:

/* Find A by multiplying L times W */

A = L * W;      // A is the product

 

Example 2:

/* 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. Do not code the entire program in main!

 

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.

 

Output requirements:

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 at least 8 venues and 6 events. You may only have two venues that have only one kind of seating - all other venues must have multiple kinds of seating.  Please use real data for venues and events.  Feel free to use venue websites to "plan" the event data for this lab.  See the Miscellaneous section below for other useful info.

 

 

Testing:

This program must be run with at least two different sets of test data for the input data.  You must create two different data sets and run your program with both of them.  I will give you a small amount of sample data at the end of this lab 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 at least 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 myprogram.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 #3 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)

 

 

Grading Scale:

Code:  (60%)

            Program header and function headers for all functions          (2 points)

            Comments (line comments and block comments)      (3 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)

            Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)  (2 points)

 

            Correct definition of the struct data type for venues, events, and seating (3 points)

            Correct manipulation of the struct data type for venues, events, and seating (4 points)

            Correct manipulation of the arrays of structs (6 pts)

            Correct implementation of recursive binary search algorithm (5 pts)

            Correct implementation of recursive merge sort algorithm (5 pts)

            Proper implementation of additional seating types  and user-input discount information (2 pts)

            Correct implementation of revised calculation of ticket prices (3 pts)

            Proper implementation of file input and input error checking (4 points)

            Proper implementation of individual data input or line of data input including error checking (4 points)

            Proper implementation of error-checking of dates using system time (1 pt)

            Correct implementation of bubble sort algorithm (3 points)

            Correct implementation of selection sort algorithm (2 points)

            Correct implementation of linear search algorithm (2 points)

            Proper implementation of data update and error checking

                        Change values (2 pts)

                        Add values [venues, events or seating] (2 pts)

                        Delete values (2 pts)

 

Output:              (40%)

            User clearly understands what is being requested for input (3 points)

            Linear Search tasks perform correctly (2 points)

            Bnary Search tasks perform correctly (4 points)

            List-all tasks perform correctly (2 points)

            Revised calculate tasks perform correctly (3 points)

            Bubble Sort tasks perform correctly (2 points)

            Selection Sort tasks perform correctly (2 points)

            Insertion Sort tasks perform correctly (2 points)

            Merge Sort tasks perform correctly (4 points)

            Update Ð make changes - tasks perform correctly (2 points)

            Update Ð additions - tasks perform correctly (2 points)

            Update Ð 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 contains all test data set as defined (2 points)

            Two test data files turned in with assignment (4 points)

 

Grading Deductions:

            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]

            Use of pointer or linked lists will result in 50 (fifty) point deduction per use [-50 deduction] (excluding passing arrays to functions which is allowed and char * data type is allowed)

 

            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 design document will result in an overall grade of 0 (zero) [-100 deduction]

            Late submission of softcopy of code and/or script file will result in an overall grade of 0 (zero) UNLESS

                        student has obtained prior instructor approval [-100 deduction]

            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:

 

Venue code structure:  The code will be a 4-digit number.  The leftmost two digits (1,000s place and 100s place) will indicate the city as follows:

01 Arlington

02 Fort Worth

03 Dallas

04 Irving

05 Plano

06 Garland

07 Grand Prairie

08 Carrollton

09 Other city in center of Metroplex

10 Other city on east side of Metroplex

11 Other city on west side of Metroplex

12 Other city on north side of Metroplex

13 Other city on south side of Metroplex

14 Other North Texas city

15 Other Texas city

20 Other US city

 

 

Following the city value will be a value in the 10s and 1s places that indicates one of the  below.  The codes for those digits will be:

01 College Park Center

02 Lone Star Theater

03 Texas Hall

04 Bluebonnet Ballroom

11 Levitt Pavilion

21 Bass Hall

22 Will Rogers Auditorium

23 Fort Worth Botanical Gardens

31 Myerson Symphony Center

40 Any other venue in DFW area

50 Any other venue in North Texas

70 Any other venue in Texas

90 Any other venue in the US

 

Therefore the venue code for the UT Arlington Bluebonnet Ballroom is 104 (or 0104 if you want) and the code for Radio City Music Hall in NY, NY would be 2090.

 

Sample input:

0104 L 1 F 400 1.00 0.75 500 24 2 2012 G A 7 9600.00 0.1 1000 Bluebonnet Ballroom UTA

0221 T 2 S P 850 150 0.90 0.75 0.7 0.65 1200 5 3 2012 A L 12 47000.00 0.4 100000 Bass Hall

 

 

0104 L 1 F 400 0.45 1.00 0.75 500 Bluebonnet Ballroom UTA 24 2 2012 G A 7 9600.00 0.1 1000 ACM Annual Dinner

0221 T 2 S P 850 150 0.1 0.02 0.90 0.75 0.7 0.65 1200  Bass Hall 5 3 2012 A L 12 47000.00 0.4 100000 Lyle Lovett and his Large Band

 

Or

 

0104 L 1 F 400 0.45 1.00 0.75 500 Bluebonnet Ballroom UTA                    Alternate order of seating items is OK.  Ex. below

0221 T 2 S P 850 150 0.1 0.02 0.90 0.75 0.7 0.65 1200 Bass Hall                0221 T 2 S 850 0.1 0.90 0.75 P 150 0.02 0.7 0.65 1200 Bass Hall

24 2 2012 G A 7 9600.00 0.1 1000 ACM Annual Dinner

5 3 2012 A L 12 47000.00 0.4 100000 Lyle Lovett and his Large Band

 

 

Your test data should be drawn from real venues and events.  Go online and look up some locations and some types of events that occur there and use that for your data.  Mix up the events and venues when you enter the data.