Lab #4 Assignment , CSE 1320 Summer 2010

 

Due Date:        Lab #4 is due absolutely no later than 8:00pm Tuesday August 17th

            Extra Credit for early submission as follows:

                        Turned in before 11:59pm Friday Aug 13 –          40 extra points

                        Turned in before 11:59pm Saturday Aug 14 –      30 extra points

                        Turned in before 11:59pm Sunday Aug 15 –         20 extra points

                        Turned in before 11:59pm Monday Aug 16 –        10 extra points

 

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

 

Grade value:    10% out of 100% for all grades.

 

Topic objectives:   C++

                              Classes     

                                    Objects

                                    Methods

                              Data encapsulation

                              Accessor and mutator functions

                              Constructors and destructors

                              Display/print functions

                              Internal calculation functions

                              Multiple files for class, function, and main definitions

                              Conditional compilation

 

 

The goal for this lab is to provide an opportunity for practice of C++ program development and the C++ programming topics covered in class and in Chapters 12 in Foster and Foster.  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.  

 

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), or continue.  You may  NOT use C++ container classes for this lab.

 

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

Lab #4 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 social events for a group, 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.  Over the semester 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.  In lab #4 you are going to be looking at and manipulating your event data from an object-oriented perspective. Primarily you will be moving from structs to classes and then you will be manipulating your objects to perform some of the tasks from your earlier labs. You will write one or more class definitions that will hold the event information and the functions that will be associated with that data. You will create an array of objects of this class and you will manipulate the array to perform the requested tasks. 

 

 

 

 

The tasks for this lab assignment #3 will be:

 

¨      Have the user call the program and pass in the name of the input file as a command line parameter if using file input.

¨      Introduce the event database to a new user.

¨      Define a class to hold the information about a campus event and associated functions. The members of this class should include:

              Private data members for all the campus event data that was in the struct in lab #3

              Appropriate accessor and mutator functions to use all the private data members

              At least one constructor and one destructor function

              A private member function that calculates the length of time that an event will be occurring and stores the results in a new data member(s) of the object

¨      Create an array of objects to store the event data in.  (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.)

A) Sort the event array by

      i.    City (using any algorithm)

      ii.   Name (using merge sort)

B) Search  by

      i.    Event start date (using binary search)

      ii.   Ticket price (any algorithm)

C) Print the data in the array

D) End the program

¨      Write the program in such a way to use multiple physical files with a minimum of:

      One file for the class definition

      One file for the class functions

      One file for the main routine

¨      Write the program in such a way as to be able to conditionally compile it

a) with debugging turned on or

b) with debugging turned off

 

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

 

Simplifying assumptions for the lab:

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

b) All events will have a unique start and end date combinations but the same event code and event name may be used for more than one event.  For example, the Ringling Bros. circus may play the same venue once a year and so could be in the database for two different years with the same code and name.

 

 

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.

 

¨      Define a class to hold the information about an event and associated functions

 

            The members of this class should include:

              Private data members for all the campus event data that was in the struct in lab #3

              Appropriate accessor and mutator functions to use all the private data members

              At least one constructor and one destructor function

              A private member function that calculates the Length of time that an event will be occurring and stores the results in a new data member(s) of the object

 

Data members:

 

For the lab #4, the following data should be put in the private section of the class definition. You must create the class definition to hold all the information described in detail below and all of the functions that will be needed to access and modify the data. The data will be input from a file. Each line of the file will contain the data below.

 

1.   Number code representing the event.  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 lab 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 rail and 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

 

9.   Name of event as a multiple word string.

 

10. Street address as street number, street name (all one word), and street designator (Ln, Ave, St, etc.)

 

11. Zip code given as a 5-digit value

 

12. A pointer to the struct type to be used as the link for the singly linked list.

 

 

For this lab, the data above for ONE event will be stored in a object.  The class must be defined to hold all the pieces of data above for an event.   The data members that go in the class are described below:

 

o   Event start day - the integer 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 - the integer starting month info for the event. .  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 - the integer 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

o   Event end month

o   Event end year

o   Event type - the one letter 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 transportationbest – theone  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.

o   Event transportationcheapest - the one 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 - the one 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 - the amount as a double that 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 - the amount as a double that 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 - the amount as a double that it costs for a student ticket to the associated event.  Make sure this amount is not negative but tickets can be free.

o   Event street number - an integer to hold this number

o   Event street name - a single word stored in an array with no white spaces as street name with a maximum length of 39 characters to be stored in a char array

o   Event street designator - a single word abbreviation with no white spaces i.e. Ave., St., Ln. with a maximum length of 8 characters in an array

o   Event zipcode - the integer zip code of the event location

o   Event name - a char * pointer to the name string

o   Next event - a struct pointer to another struct

 

All of these data items should be declared as members of the event class.

 

Along with the data members, your class definition must include member functions to access and modify the private data members,  and to display the values.

 

Member functions:

 

Each private data member must be accessible through at least two public member functions: one that allows the data to be changed (mutator) and one that returns the current value of the data (accessor). As an example, the Event type data member should have at least the following two public functions associated with it:

An accessor function, e.g. Get_Event type( ) [or Eventtype_is( )], that would return the current value of that data member, and

A mutator function, e.g. Set_Event type( char typ), that would take in a char value, verify that the value was a legal value for this data member (for example checking that it was a meaningful choice), and if it is OK, then saving the value into the data member and returning some indication (possibly a bool) that indicates if the value was set.

 

It is OK to have member functions that get and return groups of values (like getting the Event start day, Event start monthEvent start year, all together as Get_Eventstartdate() ) but do not include more than four data members for access or modification in the same function.

 

You must write a constructor function for your class that initializes the data members. You must write a destructor function for your class that cleans up any allocated space such as the name.

 

Another public member function must print all of the data of the class in a formatted way. This function is only printing the data for one object of the class type.

 

A private member function must be included to calculate the length of time that an event will be occurring (the length that the event runs).  It must be called by the mutator functions for Event start day, Event start monthEvent start year, and the Event end day, month, and year so that Length of event run will change when any of them change.  Note that this means that a private data member must exist to hold this value as well as an accessor function to print the value with.

 

¨      Create an array of objects to store the event data in.  (This is the knowledgeable user activity.)

 

The class for events should be defined globally [using the event.h and event.cpp files]. The actual event objects should be declared as an array of maximum size 40.

 

The lab must allow the user to enter any number of events into the event array up to 40 using file input.  For the file input, the program should stop reading new events when it reaches the end of the file.  For the lab, you must read lines of event data from a data file. The file input in C++ and the input data file are described below.

 

To use an input file with C++ takes the following steps:
      1) at the top use #include < fstream.h > or just fstream without .h
      2) declare an input file stream object, connect it to a physical file, and open the file by a declaration like the following:
            ifstream infile("lab4data.dat");
      where ifstream is the input file stream class type, infile is the object, i.e. variable, name, and "lab4data.dat" is the name of a file that you want to use for the input file. Notice that this declaration does the equivalent of both declaring a FILE * variable and doing an fopen command in C. Now you should be able to use the infile object anywhere that you would use the cin object. You may choose your own object variable name. You should use the same input file as for Lab #3.

 

 

Input implementation:

 

File of lines input method:

 

When your user selects file input as the method of entering data, your program should first check to see if the user entered a file name on the command line.  If a valid file name was entered, then the program should ask the user if they wish to use the file name that was entered.  The user can choose to use the file name already given on the command line or they can enter the name of another data file to use.  Once the input file is determined and has been verified, your program will read the data from the file.

 

You must create at least two data files that contains more than 25 lines of event data and you must read the data from either file.  To do file input in C++ requires creating stream variables, opening the file and linking it to the stream variable, and then reading the data from the file using stream extraction and insertion operators in the same way that a line of data would be read from the screen.  If the file name was entered from the command line, the validity of the file name must be determined before trying to use the file for input.

 

The file will have 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.  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 410 Main St. 76010 “Leading Ladies” at Theatre Arlington

 

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.  The address is 410 Main St. at zip code 76010.

 

Your program will read the first number and store it in the current struct, then read and store the eventtype char in the struct, then read and store the third number  in the struct, and so on.  Your program should read all the numbers and chars within a single input command using concatenated stream extraction operators J .   Your program should read in as many lines of input for events as the user gives up to 40 or the end of the file whichever comes first.  You may read the string in the same stream extraction command or in a separate command getline.   For purposes of Lab #4 you can continue to use C strings and string functions. Just make sure you include the correct library files for those functions.

 

 

Input verification:

When the user has entered all the desired 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.  Be sure to include the value that is calculated for the length of time the event runs.

 

 

¨      Create and display a screen menu of 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 start date (binary search)

ii.      Search for an event by ticket price

iii.     Sort events by city

iv.     Sort events by name (merge sort)

v.      List all the events

vi.     End the program

 

Search:

The search functions should let the user choose the event start date and then look through the list to find the first event that matches that date, then print a sentence stating that matching date was or was not found and if found, it should also print the code and the name of the event.  The start date functions should use binary search (like Lab #2) on the array and it is only necessary to return the first event that is found as a match. 

 

The ticket price search should ask the user for a type of ticket and a requested price and should return the first result that is identical to the given ticket price or, if no price is identical, then the closest less expensive ticket.  The ticket price search should use linear search.  For the ticket price function, if one event is found that matches, the program must ask the user if they wish to keep searching for more events that match and then continue searching if the user wants. 

 

Sort:

The sort by city function sorts using the event codes.  You may use any sort algorithm.

 

The sort by name function should use the string comparison function to sort strings alphabetically.  For purposes of the sort you can just let them be sorted by the ASCII table and not worry about capital or small letters.  You must use the merge sort algorithm with the array like Lab #2.

 

List all:

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

 

End program:

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 classes you expect to write including data members and member function descriptions,

 

b) all the functions you expect to write that are not part of any class, and

 

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

 

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.  Each private data member in the class should have an accessor and a mutator function defined in order to use and manipulate that data member.

 

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 4.  See the website for the DESIGN DOCUMENT due date.

 

A Lab #4 Design Document must be turned in in order for your Lab #4 assignment to be graded.

 

¨      Write the program in such a way to use multiple physical files

 

Your program must have one file for the class definition that should be name with the same name as the class followed by .h . For example, if your class is Elmo then your filename for the class definition should be elmo.h . Your program should use a second file for all of the function definitions for the member functions of your class. The name of this file should be the same as the class definition file with the suffix .cpp . (Ex. elmo.cpp) Your main routine and any functions that are not part of the class should be in another file that is named using the regular class naming structure of xxx1234blahblah with the suffix of .cpp instead of .c after the name. You may split your main routine and other non-class functions into separate files if desired but it is not required.

 

In your file containing main make sure you #include the iostream file and that you have the line

 

using namespace std;

 

after the #includes to make C++ work well.  Also remember to #include the event.cpp file in the file with the main routine. The event.cpp file should #include the event.h file.

 

 

The program should use the following:

A class defined to hold data about an activity in its private area and member functions to access that data in its public area

A main routine in a separate file from the class definition

Functions that are not part of the class to sort, search and list all the objects.

 

The program should use the following data structures:

Class data type to hold one event

Array of objects instantiated from the class

Global CONSTANTS for specific and/or maximum values given in this assignment.  Constants can be done with

#define or with the const declaration. 

 

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

Recursion for binary search and merge sort

 

The program should NOT use:

global variables

exit

break (unless inside a switch)

continue

            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, at least two for getting input, at least 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 class should have a class header similar to those used in the examples in the textbook. This header should include at least the purpose of the class, and its expected use.

 

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 g++ 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 15 real events to the event data (Event code list) given below.  The name of the event, the location, the address, the zip code, 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 two data sets 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.  The example data at the bottom of the assignment may be used as part of one of the data sets.

 

NOTE ABOUT ERRORS:

 

Programs turned in for credit MUST compile and run without any compilation errors or runtime errors using the g++ 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

 

>g++ 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 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:  (63%)

Program header, class and function headers for all classes and functions     (2 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!)  (2 points)

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

Quality and correctness of code (simplicity, readability, testability, etc.) (4 points)

Correct syntactical definition of class giving class name, indicating the public section and the private section, and correct syntax for member function prototypes (5 pts)

Correct inclusion of data members in the private section of the class (5 pts)

Correct definition of accessor functions for all data members (6 pts)

Correct definition of mutator functions for all data members with proper input error checking (7 pts)

Correct definition of constructor and destructor functions (3 pts)

Correct definition of print (display) function (3 pts)

Correct input to object members using data file (4 pts)

Correct creation of the array of objects (3 points)

Correct implementation of required algorithms merge sort, binary search on array (4 points)

Correct function structure as required (4 points)

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

Output:        (27%)

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

Search (find) tasks perform correctly using accessor functions to compare (5 points)

Sort task performs correctly using accessor functions to compare (5 points)

Length of event run function perform correctly using private member function and data (3 points)

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

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

            Output contains all the given test data including 10 new events and one additional data set (5 points)

Object orientation:      (10%)

 

 

Grading Deductions:

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

            Use of the exit, break (not in switch), 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)

           Late submission of softcopy of code and/or script file to appropriate TA will result in an overall grade of 0 (zero) for Lab 4 NO EXCEPTIONS.

            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

"Zing Zang Zoom" Ringling Brothers and Barnum & Bailey Circus at AA Center: 375

"Zing Zang Zoom" Ringling Brothers and Barnum & Bailey Circus at FW Convention Center: 275

 

Example data:

150 T 4 6 2010 3 7 2010 B P A 19.00 10.00 15.00 410 Main St. 76010 “Leading Ladies” at Theatre Arlington

374 C 4 7 2010 4 7 2010 R A A 65.00 1000.00 39.00 1000 AA_Center Blvd. 75219 A.R. Rahman at AA Center

277 T 25 6 2010 27 7 2010 A T A 10.00 0.00 10.00 406 Trail_Lake Dr. 76133 “Greater Things Than These” at Unity Fort Worth

368 M 23 4 2010 4 7 2010 C D A 5.00 0.00 4.00 15 Fair_Park Ave. 75226 Freedom’s Sisters at Women’s Museum of Dallas