Extra Credit Pre-Lab Assignment , CSE 1320 Summer 2010

 

Due Date:         See class website for due date

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

 

Grade value;    Extra credit 3% (out of 100% for all grades) added to total of lab grades.

 

Topic objectives:   Arithmetic and relational operators

                              Control structures

                              Functions

                              Arrays

                              Data types

                              Global constants

                              Pre-processor directives

                              Searching

                              Program design

                              Modular programming structure

                              Error checking

                              Programming style

 

The goal for this lab is to provide an opportunity for practice of C program development and the C programming topics covered in Chapters 1–3 and parts of later chapters in Foster and Foster.  These chapters will not be covered in detail in the 1320 class and it is assumed that the student is familiar with and can use all the concepts in those chapters.  This assignment is designed to practice those concepts by creating a C program.  

 

This assignment also gives students a chance to practice or refresh their skills in using a Unix operating system, in debugging programs, and in testing programs.  The format of this assignment is similar to the assignments that will be required for the rest of the semester so a student who is unsure of their skills can use this assignment to refresh them and to ask the instructor or TA about any concepts they are unsure of.  The class instructor and the TAs will have office hours each week when students can come ask for help.  See the website for this info.

 

This assignment has an overview section, a task description section, an implementation requirements section, a grading scale, and a deductions section.  If there is additional info needed it will be in a miscellaneous section at the end of this lab assignment.  Read ALL of the assignment before you start trying to develop the program.  You will be required to turn in a DESIGN DOCUMENT before the lab assignment is due.  The goal of the design document is to assist you in developing the actual program.

 

Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties.  You may NOT use global variables, the exit command, goto, break (except in a switch), continue, structs, multiple dimension arrays, strings, passing by reference (except arrays), or linked lists.

 

• -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • --

Pre-lab Problem Statement:

 

As a student as a large university in the Metroplex you have many activities and events that you can choose to attend.  These events give you an opportunity to expand your worldview and learn things outside of UTA.  However, there are so many of these events that it can be difficult to keep track of all of them.  Your goal for this program will be to develop a computer program that helps students learn about art, music, and cultural events that are occurring in DFW that they may wish to attend.  This system will be a searchable calendar and database of upcoming events with categories of event types, event city, and other info.  Your system will have two main activities – first, a knowledgeable user, such as someone who arranges campus events, will input the event data to your system.  Once this is done, the system will then become an information provider that a participant user would access to try to find interesting events to participate in.

 

Throughout the course of this semester you will work on your event database.  Each lab assignment will build on the previous assignments and will also implement changes to make the system more efficient and so on.  For this pre-lab you will be creating the beginning components of the event database.  You will implement a program that can hold data about events such as event name, city, event date ranges, and so on.  You will write functions that can retrieve data that matches certain criteria, that can modify the data, that can output the data, and other tasks.

 

The tasks for this pre-lab assignment will be:

 

¨                  Introduce the event database to a new user.

¨                  Create one-dimensional arrays to store each type of event data in and then populate the arrays with data.  (This is the knowledgeable user activity.)

¨                  Create and display a screen menu of the following choices for the user. (This is the participant user activity.)

1)      Using the data in the arrays,

      A)  Search for events by

      i.    Event type

      ii.   Event start date

B)  Calculate cost for purchase of tickets

      i.    Regular

      ii.   Member

      iii.  Student

C)  List all the events that meet a certain criteria

      i.    In a certain city

      ii.   Can be reached by specified transportation

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

3) End the program

 

 

Each of these tasks is described in more detail below. There are also a number of simplifying assumptions for this pre-lab. Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for the pre-lab:

a) Various constants will be given for use in the pre-lab.  These constants should be declared in your program using “const” or “DEFINE”

c) All events will have a unique number.  No strings will be needed for input in this pre-lab. (Later all events will be uniquely named, i.e. not event 2 but “DaVinci exhibit at FW Museum of Science and History”.)

 

 

Task Descriptions:

 

* Introduce the event database to a new user.

 

For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key.

 

* Create one-dimensional arrays to store each type of event data in and then populate the arrays with data.

For the pre-lab, the following data will be used:

 

1.   Number code representing the event – later labs will use event names.  The event code will be a three digit number where the digit in the hundreds place represents the city where the event is held where the cities use the number code as follows:

      1 – Arlington

      2 – Fort Worth

      3 – Dallas

      4 – Grand Prairie

      5 – Mansfield

      9 – Other city

      (see the list at the bottom of this assignment for the prelab data giving numbers and events)

 

2.   Event type.  Specifies the form of the event to occur.  The following are the valid event types

      C   Concert

      M   Museum exhibit

      A   Art exhibit

      T    Theater performance

      E    Cultural event

      O   Other

 

3.   Event start date consisting of

      a. day of the month given as a number

      b. month given as a number

      c. year given as a 4-digit value

 

4.   Event end date consisting of

      a. day of the month given as a number

      b. month given as a number

      c. year given as a 4-digit value

 

5.   Transportation available to the event where the best, cheapest, and fastest transportation is recorded

            (representing transportation that ARRIVES at event even if it doesn’t leave from UTA)

      D – DART bus routes

      T – The T, Fort Worth bus routes

      R – TRE rail

      C – cabs or taxis

      A – automobile

      B – bicycle

      P – pedestrian, walking distance event from UTA

 

6.   Regular ticket price

 

7.   Member/sponsor ticket price

 

8.   Student ticket price

 

For the pre-lab, the data above will be stored in a set of one-dimensional arrays.  Each array will have 10 elements in it for a maximum of ten events being described.  (Use constants for these maximum values.) Do NOT use multi-dimensional arrays for this pre-lab. The arrays are described below:

 

o   Event type - a character array of ten elements that holds the code of the event type.  Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o   Event start day - an integer array of ten elements that holds the date of the day the associated event begins.  Make sure that the number that is entered is valid, i.e. that it is a meaningful date for that month.

o   Event start month - an integer array of ten elements that holds the starting month info for the event. The event month [n] corresponds to event code [n].  Make sure that the event month that is entered is valid, e.g. how many months are there in a year?

o   Event start year - an integer array of ten elements that holds the year that the associated event starts.  Make sure that the number that is entered is meaningful – since these are supposed to be events people can attend, should the date be in the past?

o   Event end day- an integer array of ten elements

o   Event end month - an integer array of ten elements

o   Event end year- an integer array of ten elements

o   Event transportationbest - a character array of ten elements that holds the letter associated with the “best” mode of transportation to get to an event. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters. The event transportationbest [n] corresponds to event code [n].

o   Event transportationcheapest - a character array of ten elements that holds the letter associated with the cheapest reasonable mode of transportation to get to an event. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters. [“Reasonable” means that it is a sensible way to travel and that it is the cheapest of the sensible ways to travel.  For example, it would be cheap but not sensible to walk to Dallas for an event.]

o   Event transportationfastest - a character array of ten elements that holds the letter associated with the fastest mode of transportation to get to an event. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o   Event regular ticket - a float array of ten elements that holds the amount it costs for a regular ticket to the associated event.  Make sure this amount is not negative but tickets can be free.

o   Event member ticket - a float array of ten elements that holds the amount it costs for a member or sponsor to get a ticket to the associated event.  Make sure this amount is not negative but tickets can be free.

o   Event student ticket - a float array of ten elements that holds the amount it costs for a student ticket to the associated event.  Make sure this amount is not negative but tickets can be free.

 

 

For the pre-lab, you must implement at least two of the following three methods of input.  The first method will prompt the user for each piece of data about an event individually, the second method will allow the user to input all needed pieces of data about one event on one line, and the third method is to read lines of event data from a data file.  The three forms of the input and the input data file are described below.  (Just FYI, it is expected that most people will do the first two, but if you already know how to use files, than you are welcome to do that.  We will talk about files later in the semester.)

 

For this pre-lab the user must enter at least 7 events and no more than 10 events.  Since the user has a choice, then the first piece of data that the program needs from the user is a  count of how many events they are entering.  The program should check to make sure this count is between 7 and 10. [Note for development: start with a smaller number of events then increase to 7 when program is working well ] If the user’s number exceeds 10, the program should inform the user that 10 is the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (index= 0, 1, …count-1) to read and store input in one of the three following ways:  Individual data method, line of data input method, or file of lines input method.

 

Individual data method:

a.   Ask the user for the event code (don’t forget to supply a list of names and codes for them.) Read in their number, make sure it is a valid code and then store it in the Event code array at [index]

b.   Ask the user for the type of event – make sure to give them a list of the event types and abbreviations.  Check to make sure it is a valid type.  Store this valid character in the Event type array at [index].

c.   Ask the user for the month that the event starts.   Make sure it is a valid number and then store it in the Event month array at [index].

d.   Do the same for the event start day, start year, end month, end day and end year.  Be sure to check for validity of the data. [Note: checking validity where appropriate means to check the value IF there is something to check against.  For event year there is a current date to check against.  For some items there isn’t anything to check against for this lab except to make sure the size isn’t negative.]

e.   For the data values that are letter codes (Event transportation, Event type), ask the user for the data using the single character descriptions (don’t forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the appropriate array at [index]

f.    Ask the user for the different ticket prices to the event.   Make sure each is a valid value and then store each in the appropriate array at [index].

 

 

Line of data input method:

Your program may ask the user to enter all the information for one event on the same line.  This data would be an integer for event code, ints for event start and end month, day and year,  chars for type and transportation, and floats ticket prices.  You must tell the user exactly how to enter the line of data.  The data for a single event will be entered by the user as values on one line as follows {there must be one space only between the values}:

 

>  150 T 4 6 2010 3 7 2010 B P A 19.00 10.00 15.00

 

which represents event 150 (“Leading Ladies” at Theatre Arlington) starting June 4, 2010 and ending July 3, 2010.  The best transportation to the event would be by bicycle, the cheapest would be on foot, and the fastest would be by car.  The regular ticket price is $19.00, the sponsor ticket price is $10.00, and student tickets are $15.00.

 

Your program will read the first number and store it in the event code array at some location index, then read and store the eventtype char into the corresponding location index in the event type array, then read and store the third number into location index in the event start day array, and so on.  Your program should read all the numbers and chars within a single input command.  Your program should read in as many lines of input for events as were originally specified by the count up to the maximum of ten lines of input (events). 

 

File of lines input method

You may create a file that contains between 7 and 10 lines of event data and you may read the data from this file.  To do this will requires creating file variables, opening the file and linking it to the file variable, and then reading the data from the file variable in the same way that a line of data would be read from the screen.  The first line of data in the file should have only one integer on it which is the count of the number of lines of event data which follow in the file.  (File input may or may not be covered in class prior to this lab’s due date so you might have to learn this on your own if you wish to use it in the pre-lab.  It will be covered and required for later labs in the class.)

 

 

Input verification:

When the user has entered count number of events, print out all the input event data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels.  It is strongly suggested that this printing be written as a separate function that can be called at any time in the program to print the current contents of the arrays.  It is also suggested that a small function be written which will print the name of an event given the event code as input.  The function could have a switch or a bunch of if statements in it.

 

 

* Create and display a screen menu of the following choices for the user.

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

 

i.    Search for an event by type

ii.   Search for an event by start date

iii. Find all events in a certain city

iv. Calculate cost for X number of people to attend event

      a. Regular patrons

      b. Sponsors or members

      c. Students

v. List all events that can be reached by transportation type Y as

      a. Cheapest

      b. Fastest

      c. Best

vi.  List all the events

vii. Update the data in the arrays

viii. End the program

 

 

The search functions should let the user choose the event type or event start date and then look through the list to find the first event that matches that type/date, then print a sentence stating that matching type/date was or was not found and if found, it should also print the code and the name of the event.  For the pre-lab it is only necessary to return the first event that is found as a match.

 

The find-all-city function should ask the user to enter the desired city (using the city codes) then go through every event and determine if that event occurs in that city and if so, print that event.

 

The find-all-transportation should ask the user to enter the desired transportation (by using the codes) and then should return any event that has that type of transportation listed as the best, cheapest or fastest and should indicate which (best, cheapest or fastest type of transportation) it was.  If it was listed as more than one type, then all of the types should be listed.

 

The calculate function should ask the user for a number of people who will be buying tickets and the type of tickets they will be buying and then calculate the total cost.  For the pre-lab everyone in the group will be buying the same kind of ticket.

 

The list events function is the same as the print function described for input verification.

 

The update option should take the user to a second screen to allow them to update information in the arrays.  This screen should ask for a event code from the user and search for that event.  Once the correct event is determined save its [index] and give the user a menu of the following options:

 

o        Change Event start month, day, or year array at [index]

o        Change Event end month, day, or year array at [index]

o        Change Type array at [index]

o        Change one of the Transportation arrays at [index]

o        Change one of the Ticket arrays at [index]

o        Return to main menu

 

For any change the user wishes to make, do the same error checking as in the original data entry section.  After each change is made, print all of the event info for the event at [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.

 

Implementation requirements:

 

WRITE A DESIGN DOCUMENT FIRST.  The design should include

 

a) all the functions you expect to write,

 

b) brief (one line) descriptions of each function, and

 

c) some indication of which function calls what other functions.

 

The design document may be written as lines of text or as diagrams (such as a diagram that start with the main function at the top and all others below it) or as some combination of those, but it must include the information listed for a), b), and c) above.  Each function should accomplish one main purpose and each function at a lower level should have a more specific purpose than the function that calls it.  Be sure to include all the functions that are described in this lab assignment.  This design documentation will be turned in for the pre-lab and a design will be required to be turned in for Lab 1 and all later labs.  See the website for the DESIGN DOCUMENT due date.

 

The program should use the following data structures:

One dimensional integer, character, and floating point 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

A while or for loop to read the input data

If, if-else, nested ifs, or switches to error check and implement the menu options

 

The program should NOT use:

structs

multiple dimension arrays

global variables

exit

break

continue

pointers

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

 

The program should be implemented as a set of functions with a main routine and at least one function for 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 program should perform the following actions in the given order:

Declare and initialize the variables

Print a welcome screen for the user that introduces the system

Get the needed input values from the keyboard

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

 

The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program.  If multiple files are used, each file should contain a similar header.  See your instructor’s website for SPECIFIC instructions about the program header.

 

Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook.  This header should include at least the function name, the purpose of the function, and its inputs and outputs.

 

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 add at least 5 real events to the event data (Event code list) given below.  The name of the event, the location, the start date, end date, and regular ticket price must all be real data.  If you can find the member price and student price use those values, otherwise you can make those values up.  If there is transportation info for the event include that real data too (for example, AA Center in Dallas includes info about trains in their event information.)  Otherwise you may make up the transportation data for the event.

 

This program must be run with two different sets of test data for the input data.  You must create one data set in addition to the one that I will give you and run your program with both of them.  You may run it two times within a single execution or you may execute the program two different times so that you have a total of two different data sets. The sample data set that you create must meet the guidelines given in the problem definition.

 

NOTE ABOUT ERRORS:

 

Programs turned in for credit must compile and run without any compilation errors or runtime errors.

 

Compilation errors occur while the program is being developed and they prevent the program from compiling correctly. Programs compile correctly when running

 

>gcc myprogram.c

 

gives no error messages.

 

Programs may be partially complete but all completed functions must run without any errors. A program completes without runtime errors if it ends only when the user selects for the program to end and it correctly prints the exit message.

 

Any other type of ending is a runtime error or a "crash". A program has a runtime error if it compiles and runs but then crashes in any situation, i.e. if there is any set of choices the user can make that will make the program crash. It is your responsibility to test all possible choices in your program to make sure that none of them cause a runtime error. The goal of creating input test data and running your program with it should be to test all of the various choices in your program to make sure all of them terminate correctly.

 

Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)

 

 

 

Grading scale:

Code:  (59%)

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

Comments (line comments and block comments)      (6 points)

Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!)  (10 points)

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

Correct manipulation of the 1-dimensional arrays  (9 points)

Correct use of required control structures (6 points)

Correct function structure as required (6 points)

Proper implementation of data input and input error checking (8 points)

Output:        (41%)

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

            Search (find) tasks perform correctly (6 points)

            List tasks perform correctly (4 points)

            Calculate tasks perform correctly (3 points)

            Update tasks perform correctly (6 points)

            Input verification shows valid values and list of inputs correctly saved and printed (4 points)

            Output gives clear information to explain the values to the user (8 points)

            Output contains all the given test data and one additional data set (5 points)

Grading Deductions:

            Use of global variables will result in an overall grade of 0 (zero)

            Use of the exit, break, or continue command will result in an overall grade of 0 (zero)

            Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)

            Use of structs, multiple dimension arrays, strings, or linked lists will result in 50 (fifty) point deduction per use

            Late submission of softcopy of code and/or script file to appropriate TA will result in an overall grade of 0 (zero) without prior instructor approval

            Use of C language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.

 

Miscellaneous:

 

Event code list:

 

“Leading Ladies” at Theatre Arlington : 150

DaVinci exhibit at FW Museum of Science and History : 201

Mayan art exhibit at Kimball Art Museum : 221

Ansel Adams photography at the Amon Carter Museum : 233

“Greater Things Than These” at Unity Fort Worth : 277

Freedom’s Sisters at Women’s Museum of Dallas : 368

A.R. Rahman at AA Center : 374

 

Sample data:

150 T 4 6 2010 3 7 2010 B P A 19.00 10.00 15.00

374 C 4 7 2010 4 7 2010 R A A 65.00 1000.00 39.00

277 T 25 6 2010 27 6 2010 A T A 10.00 0.00 10.00

368 M 23 4 2010 4 7 2010 C D A 5.00 0.00 4.00