Lab #3 Assignment

CSE 1320-002

Spring 2012

 

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

Lab Due Date:                        March 29, 2012 at noon (12pm)  NOTE THIS IS AFTER TEST 1

(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Ð6 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: 

            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, structs, 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 may use getline for string input if desired.

 

Assumptions for the lab #3:

 

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 #3 is 3.  Use constants to define the max value.

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

4) For date checking in Lab #3, you may make the simplifying assumption that all months have 30 days.  This will change in later labs.

5) As a simplification in Lab #3 you may use the lab due 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:

 

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)  Seach 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

3) End the program

 

 

 

Data Description:  For lab #3, you will be storing the input data in some single arrays and some multi-dimensional arrays just like in Lab #2.  The majority of arrays are the same as Lab #2 but there are a few changes.

 

The data elements and descriptions are given below.  Following this first list, the data elements are described by type.

 

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) Р  an integer of either 1, 2 or 3 followed by that many letters of either F, S, or P. 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, and special is any other type of seating which could include lousy seats like in the high balcony or good seats like boxes. 

Ex: 2 F P

 

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

 

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 6 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 and/or reg. sPecial.

 

17) Count of venue entered Ð integer that is the number of venues the user entered data for.  Max 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 6.  This number is determined by user input.

 

 

The format for each piece of data is listed below. 

 

Overall you are required to use at least four multi-dimensional arrays (data content and sizes will be specified for each one), one array holding words (strings), at least two one dimensional arrays, and then enough one dimensional and multi-dimensional arrays to hold the remaining data.   [OK, this isn't as confusing as it seems.  J]

 

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 arrays.  In the two dimensional arrays, all the data for a single venue will be stored on the same row.  The columns will represent different pieces of data about the venue in that array.  In the string array, the name of each venue will be on the same row as in the other arrays. 

 

You will have a maximum of 8 venues for Lab 2 and a maximum of 6 events.  This information then dictates the sizes of the various types of arrays you will need.    You will create 6 multi-dimensional arrays, including an array of strings, and 3 one-dimensional arrays.  Some of the arrays hold integer data and some hold float data.  Each column then in the float and integer arrays will indicate a different piece of data about the venue or event.  In the string array, the name of each venue will be on the same row as in the other arrays.  In the two character arrays, the same row always refers to the same venue.  For the float and integer arrays, the number of columns is determined by how many pieces of data have to be stored.  The number of rows is the same as the maximum number of venues that can be stored. (8 for this lab)

 

Out of the 6 total multi-dimensional arrays, there are three multi-dimensional arrays that will be used for more complex data structures.  Another multi-dimensional array will hold the strings.  Another holds the rest of the integer data and the last holds the remaining float data.  These arrays are specified in detail below.

 

The integer array will have 8 rows and 6 columns.  The array has 8 rows because that is the max number of venues or events and it has 6 columns because there is 1 piece of integer info to be stored for each venue and 5 pieces for each event. It is recommended that you create a set of constants to use for your column indices in the integer and float arrays, e.g. VCODE = 0, EVDAY = 1, EVMO = 2, EVYR = 3, EVLEN = 4, and EVENUE = 5e.g. for integers and for floats VCOST = 0, ECOST  = 1, PROFITP =2 and PROFITA =3, and then use them as the indices for your arrays, ex.venint[4][EVDAY] would be the location of the event day of the 5th event in the integer array and venint[k][VCODE] would be the k+1th venue code in the array.   Remember with C arrays you start counting at 0, so 5 venues means 0 to 4. 

 

The float array venfloat will have 8 rows and 4 columns and will hold the venue cost, event cost, profit percentage and fixed profit amount.   Use the constants described previously.

 

The char array venchar will be 8 by 3 and will hold the venue type, event type, and event setting.  Create constants as described above.

 

There are two two-dimensional arrays holding more complex data.  The first is an array of character data that represents the kinds of seating available in the venue.  There are a maximum of 8 venues and each venue can have a maximum of 3 different types of seating.  Therefore the venseating array will have 8 rows and 3 columns.  The value in this array should be initialized to some default character that is not one of the valid choices for kinds of seating.  Then, based on use input, the actual kinds of seating will be stored in this array.  A venue may have 3 kinds of seating (F=festival, S=selected, P=special), or only 2 kinds of seating out of those three or only one kind of seating.  All non-used values in the array will contain the default character.  As an example, you might imagine that College Park Center (CPC) only has S and P seating, while Levitt Pavilion has only F seating, and the Fort Worth Botanic Garden has F, S, and P seating at its Concerts in the Garden.  (Festival seating means no assigned seats, Selected means assigned seats, and sPecial means any unique type of seating like box seats or premium floor seats.)  You might imagine that venseating array with the data above looks like this in memory:

 

S

P

 

F

 

 

F

S

P

 

 

 

 

 

 

 

 

The second two-dimensional array is also related to the kinds of seating in the venue.  This data is a set of integers representing the number of each type of seating.  The array is the same size as the char array and any place there is a char in the venseating array there will be a corresponding integer in the venamount array which indicates how many of those seats are available.  So for CPC there might be 6200 Selected seats and 1000 sPecial seats.

 

6200

1000

0

875

0

0

1200

800

200

0

0

0

0

0

0

 

 

There is one four-dimensional array.  This array has 8 strata (venues) with 3 layers (kinds of seating) with two rows(discount and regular) and two columns (expected percentage of occupied seats  and cost per seat/price).  Use the constants OCCUPIED = 0 and PRICE = 1.  Remember with C arrays you start counting at 0, so 5 venues means 0 - 4 and 3 kinds of seating means 0 - 2.  Declaring two constants DISCOUNT = 0 and REGULAR = 1 might also help.  Ergo, venseatfloat[2][0][DISCOUNT][OCCUPIED] would be the expected percentage of the discounted seats to be occupied of the 1st kind of seating of the 3rd venue, i.e. the percentage of the discounted Festival seating at the Fort Worth Botanical Garden that is expected to be occupied.

[ If the four dimensional array messes with your mind, you can create two three-dimensional arrays instead venseatoccupy and venseatprice.  You would use venseatoccupy[2][0][DISCOUNT] to store the data above and then venseatprice[2][0][DISCOUNT] would store the cost for the same seat. ]

 

The multi-dimensional array for strings will store one string per row.  The string array will have 8 rows and 40 columns, venname[5][40].  You will be using entire rows of the array rather than single characters, i.e. venname[k] will be the string that contains the name of the kth venue. Make sure to declare all your constants (such as 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 arrays 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:

 

Count of venues entered Ð integer that is the number of venues the user will enter data for.  Max is 8.  This number is determined by user input.  This should be error checked and then stored as an integer variable.

 

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 multi-dimensional array at the VCODE index on the correct row for this venue, i.e. venint[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 one or more %s specifiers in a scanf statement or 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 venname[count] in the multi-dimensional array.

 

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 venchar[count][VTYPE].

 

How many kinds of venue seating Ð an integer of either 1, 2 or 3.  This value may be stored but is not currently included in the data structures.  It could be added to venint if desired.

 

Venue kinds of seating  Р 1, 2 or 3 letters of either F, S, or P. Must include either F or S at minimum to be valid.  The number of letters is determined by the How many value just described.  The letters that are read in are stored in venseating array.  If two letters are entered for the venue at count, then the first letter is stored at venseating[count][0] and the second is stored at venseating[count][1].

 

Venue amount of seating of each kind Ð same number of integer values as previous info giving a list of number representing seats of the available types. The number of values is determined by the How many value just described.  The values that are read in are stored in venamount array.

 

Percentage of kinds of seating expected to sell Р  2, 4, or 6 floating point values representing how much  regular and discounted seating you expect to sell within each kind of seating for a venue. The number of percentage values is determined by two (2) times the How many value just described.   If there are 3 kinds of seating there will be 6 percentage values.  If there is only one kind of seating there will be 2 percentage values.  Values are given as discounted and then regular in same order as seated types.  Ex.  For kinds of seating of S P, then there will be four percentage values ex. 1.00 0.75 0.9 0.6 which would represent 100% of discounted Selected seats, 75% of regular price Selected seats, 90% of discounted sPecial seats, and 60% of regular sPecial seats. This data is stored in the venseatfloat array.  Ex. the first value above would be stored in venseatfloat[count][0][DISCOUNT][OCCUPIED] .  Note that the first two indices [count][0] are exactly the same as the two indices used in the venseating and venamount arrays.

 

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 floating point multi-dimensional array at the VCOST index on the correct row for this venue, i.e. venfloat[count][VCOST] where count represents the count +1 venue being entered.

 

Event data:

 

Count of events entered Ð integer that is the number of events the user will enter data for.  Max is 6.  This number is determined by user input.  This should be error checked and then stored as an integer variable.

 

Event date Ð Three integers representing the event date as day, month, and year - three separate numbers.  These values are stored in venint[count][EVDAY] and then in EVMO and EVYR.  The dates should be error checked.  For Lab 3, if you want to simplify this error checking, you may make the assumption that all months have exactly 30 days.

 

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 venchar[count][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 venchar[count][ESETTING].

 

Event length in hours Ð An integer (must be > 0). This value is stored in venint[count][EVLEN].

 

Fixed event cost Ð a floating point amount (must be >= 0).  This value is stored in venfloat[count][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 venfloat[count][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 venfloat[count][PROFITA].

  

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

 

Recommended ticket prices Ð 2, 4, or 6 floating point values representing the price to set for each kind of available seating.  This value will be calculated and should be stored as floating point numbers. If there are 3 kinds of seating there will be 6 prices.  If there is only one kind of seating there will be 2 prices.  Values are given as discounted and then regular in same order as seated types.  Ex.  For kinds of seating of S P, then there will be four prices calculated representing discounted Selected seats, regular price Selected seats, discounted sPecial seats, and regular sPecial seats. This data is stored in the venseatfloat array.  Ex. the discounted Selected price would be stored in venseatfloat[count][0][DISCOUNT][PRICE] .  Note that the first two indices [count][0] are exactly the same as the two indices used in the venseating and venamount arrays.

 

 

 

 

Data entry phase

 

Input Implementation:  For Lab #3 the user must enter at least 3 venues and no more than 8 and at least 2 events and no more than 6.  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 #3, you must implement the following three methods of input.  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.  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 choices of methods:  Individual data method, line of data input method, or file 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.

 

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 will run for the number of venue 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 integer array at the correct row [num] at column 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 char array venchar[num][VTYPE].

 

c.         Ask the user how many kinds of venue seating there are  and check that they enter only 1, 2 or 3.  Store the number of kinds of seating either in an array location or in a temporary variable.

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 venseating[num][loopcounter] . 

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 venamount[num][loopcounter] .

3.         Tell the user that 15% of the seats just entered will be priced as discounted tickets.  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 venseatfloat[num][loopcounter][DISCOUNT][OCCUPIED] .

4.         Tell the user that 85% of the seats just entered will be priced as regular tickets.  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 venseatfloat[num][loopcounter][REGULAR][OCCUPIED] .

 

e.         Ask the user for the venue cost per hour.  Check for validity and save this value in the float array venfloat[num][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 name string in  venname[num].

 

 

Within a loop that will run for the number of event times: (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 the integer array at venint[count][EVDAY] and then in EVMO and EVYR .  (As a simplification you may use the lab due date as the date to check against for a ÒfutureÓ 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 char array venchar[num][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 char array venchar[num][ESETTING].

j.          Ask the user the length in hours of the event.  Check that the data is valid and store in venint[num][EVLEN].

k.         Ask the user for the fixed cost of the event.  Check for valid data and store in  venfloat[num][ECOST].

l.          Ask the user for the desired percentage of profit to make from the event.  Check for valid data and store in  venfloat[num][PROFITP].

m.        Ask the user for the desired fixed amount of profit to make from the event.  Check for valid data and store in  venfloat[num][PROFITA].

 

 

Line of data input method:

 

Your program may ask the user to enter all the information for one venue and one event on the same line.  (or 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 1.00 0.75 500 24 2 2012 G A 7 9600.00 0.1 1000 Bluebonnet Ballroom UTA

 

which represents the UTA Bluebonnet Ballroom (code 0104, name ÒBluebonnet Ballroom UTA", Large room) with one kind of seating (Festival) and 400 total seats.  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.  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.90 0.75 0.7 0.65 1200 5 3 2012 A L 12 47000.00 0.4 100000 Bass Hall

 

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.  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.  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 1.00 0.75 500 Bluebonnet Ballroom UTA

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

 

> 24 2 2012 G A 7 9600.00 0.1 1000

> 5 3 2012 A L 12 47000.00 0.4 100000

 

Regardless of how the data is entered, your program will read the first number and store it in the integer array at the correct location, then read and store the character into the corresponding location in its 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 of 8 lines of input for venues and/or 6 for 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. 

 

You must create a data file that contains at least 10 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.  This can be done in two ways:

 

1) You may tell the user to name the file a specified name, i.e. "You input data file must be named lab3data.txt in order for the program to use it.  The file must be stored in the same directory as the program.  Press any key when your file is ready to be read. " You would then accept a key press from the user, set up the file pointer for the file, and then begin reading from the file one line at a time.  As one line of data is read, it should be error checked before the next line is read.  You would loop until you reach the end of the file.

 

2) If you wish to give the user more flexibility, you can 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.

 

For either approach your program needs a FILE * pointer which is connected to the file with fopen.  Ex:  Using the 2nd method above:

int filenm = 100;         // not needed for 1st method

char *filename;            // not needed for 1st method

FILE *infile;

 

printf("Please enter the complete name of your data file:  "); // use different message for 1st method above

getline(&filename, &filenm, stdin);                                        // not needed for 1st method

if (filename != NULL)                                                                        // not needed for 1st method

            infile = fopen(filename, "r");                                       // infile = fopen("lab3data.txt","r"); for 1st method

 

 

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 the fit,

                        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 first venue that matches size and 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, then 15% will be discount seats so 850 * .15 = 127.  Out of those seats we expect to sell 90% of the tickets so 127 * .9 = 114.  So we expect to sell 114 discount Selected seat tickets.  All remaining calculations would be similar (850 Ð 127 = 723 regular seats, 723 * .75 = 542 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,

numDS for Discount Selected,

numDF for Discount Festival, and

numDP for Discount sPecial.

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

      Ticket discounts are: Selected (DS) 15%, Festival (DF) 30%, sPecial (DP) 5%

 

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

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*.85)*numDS + ((RS*.5)*.7)*numDF + ((RS*3)*.95)*numDP = 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 + (.85)*numDS + (.35)*numDF + (2.85)*numDP) =     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 + (.85)*numDS + (.35)*numDF + (2.85)*numDP)

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 linear or 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 linear or 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 linear or 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 selection 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 bubble sort or 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 #3, you will not have to make changes to amount of seating types, i.e. you will not update from one type of seating (e.g. ÔFÕ) to three types of seating (e.g. F S P). You will do so in later labs.  You may change existing seating types (e.g. change F to P)]

 

      o   Change a venue size code

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

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

 

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

 

 

Implementation Requirements:

 

For Lab #3 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 #3 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 if binary search or merge sort are used

 

The program should NOT use:

            structs

            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 3 venues and 2 events. You may only have one venue that has 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:  (56%)

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

            Comments (line comments and block comments)      (4 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!)  (4 points)

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

            Correct manipulation of the 2-dimensional char, integer and float arrays  (3 points)

            Correct manipulation of the 4-dimensional array (or the two three dimensional arrays)  (3 points)

            Correct manipulation of the 2-dimensional char array of strings  (3 points)

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

            Proper implementation of line of data input and input error checking (4 points)

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

            Correct implementation of bubble sort algorithm (5 points)

            Correct implementation of selection sort algorithm (5 points)

            Correct implementation of linear search algorithm (4 points)

            Proper implementation of data update and error checking (4 points)

            Correct implementation of merge sort algorithm if used (up to 4 points extra credit)

            Correct implementation of binary search algorithm if used (up to 4 points extra credit)

Output:              (44%)

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

            Search tasks perform correctly (6 points)

            List-all tasks perform correctly (4 points)

            Calculate tasks perform correctly (3 points)

            Sort tasks perform correctly (8 points)

            Update tasks perform correctly (6 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 (5 points)

            Output contains all the given test data and additional test data set as defined (5 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, structs 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

 

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.