Extra Credit Pre-Lab Assignment

CSE 1320-001

Fall 2010

 

Objective: The goal of the extra credit pre-lab is to introduce students to Dr. T’s approach to lab assignments and to reinforce and refresh previously learned material about C programming. The pre-lab also allows students to practice program development, debugging, and testing. All of these skills are crucial to success in Dr. T’s class. By doing the pre-lab assignment, students can better prepare themselves for the required assignments and get a jump start on these assignments since they will more clearly understand what is being requested for Lab 1. Plus, you get extra credit. : )

 

Topics: C functions, design of programs, input and output, single dimension arrays, data types, passing parameters, 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: You are going to put together a small database of information about certain people. 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 at least a week before the lab assignment is due. The goal of the design document is to assist you in developing the actual program.

 

This assignment has an overview section, a task description section, an implementation requirements section, a grading scale, and a deductions section. If there is additional info needed it will be in a miscellaneous section at the end of this lab assignment. Read ALL of the assignment before you start trying to develop the program.

 

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

 

Assumptions for the pre-lab:

1) A maximum of 20 and minimum of 10 people will be in the database. Use constants to define the max and min values.

 

-----------------------------------------------------

 

Problem: The people in your database will be speakers, performers, and entertainers who come to the UT Arlington campus in the 2010-2011 school year. These will include the speakers in the Maverick Speaker Series, such as Bill Nye, the Science Guy, and speakers in the Engineering Speaker Series. This will also include performers brought in by EXCEL and other campus groups. As part of this assignment you will have to find this information on the UTA website to use as input to your program. After getting all the input data for the speakers and performers, you will allow the user to do the following:

 

1) Using the data in the arrays,

    A) Search for speakers/performers by

       i. Speaker code

       ii. Date of speech/performance

    B) Calculate cost for purchase of a given number of tickets of a given type

    C) List all the speakers that meet a certain criteria

       i. In the same series

       ii. Speakers are from a certain state

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

3) End the program

 

 

Data Description:

 

You will store each piece of information in a separate array. The data values and types of info are as follows:

 

1) Speaker code – a number of less than four digits that represents the specific speaker. We are not using strings for this lab so the number will represent the speaker’s name in this pre-lab. In the next lab, you will store the name. As an example, Ken Burns is the first speaker in the Maverick Speaker Series so you could code him as 100. You will have to create codes for each possible speaker/performer who can be put in your database and you will have to inform the user what the valid codes are.

 

2) Performance date given as day, month, and year – three separate numbers.

 

3) Time of event – given in military time. [If you do not understand “military time” is then look it up or ASK.]

 

4) Series code – a character representing the series or event that the speaker/performer is part of. The valid series/event codes are:

 

    M – Maverick Speaker Series

    E – Engineering Speaker Series

    D – Engineering departmental sponsored event

    C – College of Engineering event including Engineers Week

    S – College of Science event

    U – University sponsored event including EXCEL activities, Homecoming, etc.

    L – Levitt Pavilion concert or event

    O – Other

 

5) Ticket costs – a cost in dollars and cents. Ticket cost has two values: early-bird purchase or regular purchase. Tickets can be free.

 

6) Speaker’s home state – two letter code using US postal codes or other two-letter designation where needed

 

       The format for each piece of data is listed below. Each kind of data item is stored in its own array. Do NOT use multi-dimensional arrays for this pre-lab.

 

Speaker code is a single integer value of less that four digits. Use the hundreds place digit to represent the series. For the first speaker, the speaker 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 speakercode array at the first index [index]. Error checking should make sure that the value that is entered is one of the valid values for a speaker code based on the valid codes which your program offered to the user.

 

Performance day is an integer value. It should be error checked and then a valid day value stored in the day array at index.

Performance month is an integer value. It should be error checked and then a valid month value stored in the month array at index.

Performance year is an integer value greater than 2000 and less than 2050. It should be error checked and then a valid year value stored in the year array at index.

Performance time is a floating point value in the form HH.MM where HH is the hour value in military time and MM is the minute value. You must error check both the hours and the minutes for validity. If it is valid, it should be stored in the array time[index].

 

Series code is a character value. It must match one of the valid series/event codes. If it is valid, it should be stored in the array series[index].

 

Early-bird Ticket cost is a floating point value. It must represent valid dollars and cents. An event can be free. A valid ticket price should be stored in the array ticket[index].

Regular Ticket cost is a floating point value. It must represent valid dollars and cents. An event can be free. A valid ticket price should be stored in the array ticket[index].

 

State is two character values. For the Pre-Lab you are not required to error check the state. You must read in the two characters separately and store the first char into state1[index] and the second in state2[index].

 

Input Implementation:

 

For this pre-lab the user must enter at least 10 speakers and no more than 20. 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 speakers they are entering. The program should check to make sure this count is between 10 and 20. [Note for development: start with a smaller number of speakers then increase to 10 when program is working well ] If the user’s number exceeds 20, the program should inform the user that 20 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.

 

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 individually, the second method will allow the user to input all needed pieces of data about one speaker on one line, and the third method is to read lines of speaker 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.) After getting the count of speakers from the user, the program must ask the user how they want to input the data. Your program must give them at least TWO of the following three choices of methods: Individual data method, line of data input method, or file of lines input method. Once the user has chosen the method of input, all the input will be done that way.

 

Individual data method:

    a.   Ask the user for the speaker 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 Speaker code array at [index]. As an example of an explanation, you might tell the user "Please enter Maverick Speaker Series speakers as code 1xx, i.e. Ken Burns = 100, Rick Bayless = 101, etc. Please enter Engineering Distinguished Speaker Series speakers as code 2xx, i.e. Dr. Vincent Poor = 200. …" See the Miscellaneous section at the bottom for all of the speaker codes.

   b.   Ask the user for the day of the speech/event. Make sure it is a valid number and then store it in the Day array at [index].

   c.   Do the same for the month and 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 year there is a range of years 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.]

   d.   Ask the user for the time for the speech. Make sure it is a valid hour and minute and then store in the time array at [index].

   e.   Ask the user for the series code – make sure to give them a list of the series/event codes and abbreviations. Check to make sure it is a valid type. Store this valid character in the Series array at [index].

   f.   Ask the user for the early-bird ticket price for the speech. Make sure it is a valid value and then store in the appropriate array at [index]. Do the same for the regular ticket price and store it.

   g.   Ask the user for the two letters of the speaker’s home state abbreviation. Store each in the appropriate array (state1,state2) 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 speaker code, ints for day, month, and year, chars for series code and the two char state code, and floats ticket prices and time. You must tell the user exactly how to enter the line of data. The data for a single speaker/performer will be entered by the user as values on one line as follows {there must be one space only between the values}:

 

> 100 24 9 2010 19.00 M 0.00 0.00 NY

 

which represents Ken Burns (code 100) on 24 September 2010 at 7:00pm (19.00 in military time) as part of the Maverick Speaker Series with free early-bird tickets and free regular tickets. He is from New York.

 

Your program will read the first number and store it in the speaker code array at some location index, then read and store the day integer into the corresponding location index in the day array, then read and store the third number into location index in the month 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 speakers as were originally specified by the count up to the maximum of twenty lines of input (speakers).

 

File of lines input method

You may create a file that contains between 10 and 20 lines of speaker 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 speaker 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 speakers/performers, 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 a speaker given the speaker code as input. The function could have a switch or a bunch of if statements in it.

 

Task Description:

 

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)    Search for speakers/performers by speaker code

   B)    Search for speakers/performers by date of speech/performance

   C)    Calculate cost for purchase of a given number of tickets of a given type

   D)    Find all the speakers in the same series

   E)    Find all the speakers that are from a certain state

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

   G)    End the program

 

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

 

The calculate function will ask the user for a number of tickets num and a particular speaker code and will print the total cost for num early-bird tickets and num regular tickets.

 

The find-all-in-series function should ask the user to enter the desired series code then go through every speaker and print the complete information for all speakers that are part of that series.

 

The find-all-from-state function should ask the user to enter a two-letter state code then go through every speaker and print the complete information for all speakers that have that same state code.

 

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 speaker code from the user and search for that speaker/performer. Once the correct speaker is determined save its [index] and give the user a menu of the following options:

 

   o   Change speech/performance month, day, or year array at [index]

   o   Change the series array at [index]

   o   Change the two state char arrays at [index]

   o   Change one of the ticket arrays at [index]

   o   Change the time array 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 speaker 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.

 

 

Implementation Requirements:

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 be turned in for the lab and a design will be required to be turned in for Lab 1 and all later labs. You may handwrite or draw your design but you must turn it in electronically so you must scan in anything handwritten in order to submit it.

See the website for the DESIGN DOCUMENT due date. It is usually ONE WEEK PRIOR to the lab due date.

A Pre-Lab Design Document must be turned in in order for your Pre-Lab assignment to be graded.

 

 

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 (except in a switch)

   continue

   pointers

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. 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.

 

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 data on at least 20 speakers/performers who will be at UT Arlington this year. The speaker name, the series they are part of, the date and time they are speaking, and the ticket price must all be real data. You should look at the speaker bios to determine the speaker's home state. The information for the Maverick Speaker Series, the Engineering Distinguished Speaker Series, and other speakers and programs sponsored by EXCEL can be found on the University of Texas at Arlington website. See the Miscellaneous section below for links.

 

This program must be run with 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 a total of two different data sets. The sample data sets 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 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 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 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 tasks perform correctly (6 points)

      Find-all 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) [-100 deduction]

      Use of the exit, break (outside a switch), or continue command will result in 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]

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

      Late submission of softcopy of code and/or script file to appropriate TA 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.

      Missing design document will result in an overall grade of 0 (zero) [-100 deduction]

 

Miscellaneous:

   For Maverick Speaker Series (series code M), number each speaker in order from 100. Therefore Ken Burns is speaker code 100, Rick Bayless is code 101, etc. http://www.uta.edu/maverickspeakers/index.php

   For Engineering Distinguished Speaker Series (series code E), number each speaker in order from 200. Therefore Dr. Vincent Poor is speaker 200, Dr. Cristina Amon is 201, etc.

http://www.uta.edu/engineering/speakerseries/

   Other engineering events with codes D or C should be numbered with codes starting with 300. For example, see http://www.cse.uta.edu/news/seminars/InvitedTalks.asp?pageVer=

   University Events (series code U) include concerts. The page at http://www.uta.edu/studentaffairs/universityevents/ue/ will have a listing for a Fall Concert and that performer should be included when available. University Event speakers or performers should be numbered starting with 400.

   College of Science (series code S) speakers would include astronaut Barbara Morgan. This info can be found at https://www.sallyridescience.com/festivals/10uta1030. Number College of Science speakers starting at 500.

   Concerts at Levitt Pavilion (series code L) can be included for speakers/performers. Number these performers starting with 600. http://www.levittpavilionarlington.org/

   Number any speakers from series code 0 starting with 700.

 

Format of the data: First line is the data used as an example above. Do not include the comments in your data file (if using a file).

 

100 24 9 2010 19.00 M 0.00 0.00 NY

603 4 9 2010 19.30 L 0.00 0.00 TX       // Ray Wylie Hubbard at Levitt Pavilion

501 30 10 2010 13.00 S 20.00 200.00 ID       //Barbara Morgan at Sally Ride Science Festival

201 5 10 2010 18.00 E 0.00 0.00 ON

/* Dr. Cristina Amon (code 201) on 5 October 2010 as part of the Engineering Distinguished Speaker Series with free early-bird tickets and free regular tickets. She is from Toronto, Ontario, Canada (had to fudge on the state code here and use province abbreviation) and speaks at 6pm.*/