Lab #4 Assignment , CSE 1320 Spring 2010
Due Date:Lab #4 is due absolutely no later than 8 pm Thursday May 13th
Extra Credit for early submission as follows:
Turned in before 11:59pm Sunday May 9 – 40 extra points
Turned in before 11:59pm Monday May 10 – 30 extra points
Turned in before 11:59pm Wednesday May 12 –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) added to total of lab grades.
Topic objectives: Classes and objects
Accessor and mutator functions
Constructors and destructors
Display/print functions
Internal calculation functions
C++ input and output
Bool data type
Searching and sorting
Algorithms
Error checking
Programming style
The goal for this lab is to provide an opportunity for practice of the C++ programming topics covered in Chapters 12 in Foster and Foster. This assignment is designed to practice those concepts by creating a program. This program must be compiled on omega using the gpp compiler and run on omega.As in Lab #3 you will be required to create a design document and turn it in prior to the due date of the lab.All material that has previously been covered may also be used in this lab.
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), or continue.
* -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
As a student as a large university 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 the classroom. 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 events that are occurring on campus that they may wish to attend. This system will be a searchable calendar and database of upcoming events with categories of event types, event purpose 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. 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. You will have to give the programÕs user a set of choices that will then guide the program in what lists are created. You will also have to report to the user the results that the program determines and the lists that are created.
The tasks for this lab #4 assignment will be:
* Introduce the Campus Activities System 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 total cost to attend all the events and stores the results in a new data member of the object
* Create an array of objects to store the event data in.
* Create and display a screen menu of the following choices for the user.
A) Sort the event array by
i. Code number (merge sort)
ii. Name (any algorithm)
B) Search by
i. Event day and time
ii. Group purpose
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
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 take place on the UTA campus.
c) All events will have a unique number and a unique name. Names will be strings but the strings have a max length of 75 characters.
d) Your program must check data VALUES at input but not data TYPES.The user is responsible for putting in the correct data type as long as your program clearly tells the user what to do.If the use inputs the wrong type (char when int is required), then this type of error is NOT counted as an execution error in your program.
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 activity data and associated functions.
The members of this class should include:
Private data members for all the data that was in the struct in lab #3 (the list is below)
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 predicts the attendance at the event and stores the result in a new private data member of
the object
A public member function that displays all the data for one event
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 representing the event
2. Name of the event
3. Event type. Specifies the form of the event to occur. The following are the valid event types:
C Concert
S Spectator
P Participatory - Competitive
N Participatory - Non-Competitive
D Dinner
L Lunch
B Breakfast
O Other
4. Purpose of the event. The purpose must be one of the following as denoted by the letter preceding it:
F - fun and social event
M - fine arts event; music, dance, art, theatre, comedy, and other types of arts activities
C - cultural; offers support and education related to a specific culture or group of cultures
S - sports; opportunities to play or support teams
V - volunteer event that does service activities of any type
L - leadership; opportunities for leadership on campus or learning skills for leadership
E - educational; offers some discipline-related content for student
A - academic; offers some sort of academic focused purpose such as tutoring, mentoring, study group, etc.
P - professional; focused on providing support to student for future professions
O - other
5. Event time consisting of
a. time of day given as hour and minute in military time (24 hour time)
b. day of the month given as a number
c. month given as a number
6. Size. Gives maximum number of event participants
7. Cost. Gives cost to participate/ attend event
8. Venue consisting of
a. building abbreviation
b. room number or name inside the building
9. Length. Gives length of event in minutes
EXTRA CREDIT (items 10 and 11 will be in the file for each event but they are extra credit if you implement them in the class.)
XC10. Event goal. The goal of the event will be one of the following:
Recruiting
Charitable fund-raising
General fund-raising
Talent demonstration
Community service
Social networking
XC11. Goal targets.The goals above have various targets associated with them:
for recruiting the target is number of new members
for either type of fund-raising the target is an amount of money
for community service the target is number of person hours of service
for talent demonstration the target is a letter grade
for social networking the target is number of participants
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. Details for the data are given below:
o Event number - the integer numeric code associated with a specific event. For this lab we will have a fixed set of events that are coded by number (ex. One Mike Stand = 842, Wheelchair Basketball Game = 110, FLOC Movie Night = 500, etc.) and that list would be displayed in the output as described below.
o Event name - the name associated with a specific event. For this lab we will have a fixed set of events that have names that are strings.The strings may have multiple words. (ex. One Mike Stand = 842, Wheelchair Basketball Game = 110, FLOC Movie Night = 500, etc.)The name string is allowed to have a maximum of 75 characters
o Event type - the character 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 purpose - the character code of the purpose of the associated event. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.
o Event hour and minute - the hour and minute info for the associated event. The hour and minute value will be entered as a single floating point number with the hour value to the left of the decimal and the minute value to the right of the decimal HH.MM . The value should be entered as military time, i.e. 24-hour clock instead of 12-hour clock. Make sure that the event hour and event minute that is entered are valid.
o Event day – a bit field for the date of the day of the of the associated event. Make sure that the number that is entered is valid, i.e. that it is a meaningful date for that month.
o Event month - a bit field for the 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 maximum size - the maximum number of people that can attend or be involved in the associated event.
o Event cost - the amount it costs to participate in the associated event. Make sure this amount is not negative but it can be free to participate.
o Event building – this should be the abbreviation used on UTA maps for a given building on campus.Determine the appropriate data type for this and declare it.
o Event room – this room designation in the building listed above.This should be a ONE WORD string in order to allow for things like ÒLoneStarAuditoriumÓ or Ò229Óor Ò143BÓ as room designations.
o Event length - the expected length in minutes of the associated event.
o Event goal – an enumerated type giving constant values representing the six kinds of goals. By default, any event has the goal of social networking if no other kind of goal is specified and social networking should have an enumerated type value of zero (0).
o Event goal target – a union containing the five different possible targets associated with the six goals. The fund raising target value should be a floating point, the grade target should be single character, and the other targets should be integers.
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 member functions: one that allows the data to be changed and one that returns the current value of the data. As an example, the Event purpose data member should have at least the following two public functions associated with it:
An accessor function, e.g. Get_Event purpose( ) [or Eventpurpose_is( )], that would return the current value of that data member, and
A mutator function, e.g. Set_Event purpose( char purp), 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 hour and minute, Event day, Event month, or Event building, and Event room all together) 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 predict the attendance. It must be called by the mutator functions for Event purpose, Event type, Event goal, and Event venue so that Predicted attendance 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.
The predicted attendance function is a calculation based on the type, purpose, and goal of the event, the size of the venue, and the previous attendance (if known) as follows:
If the event type is concert, spectator or other,
Then if the event purpose is fun, fine arts, cultural, or sports
Then if the goal is fund-raising (either) or community service,
Then predicted attendance is 120% of previous attendance or 75% of venue size if this is a new event.
Else if the goal is recruiting, talent demonstration, or social networking,
Then predicted attendance is 105% of previous attendance or 45% of venue size if this is a new event.
Else if the event purpose is volunteer, leadership, educational, academic, professional, or other,
Then predicted attendance is 103% of previous attendance or 40% of venue size if this is a new event.
Else if event type is participatory (either kind),
Then if the event purpose is fun, sports, or volunteer,
Then if the goal is recruiting, community service, or social networking,
Then predicted attendance is 110% of previous attendance or 60% of venue size if this is a new event.
Else if the goal is fund-raising (either), or talent demonstration,
Then predicted attendance is 105% of previous attendance or 45% of venue size if this is a new event.
Else if the event purpose is fine arts, cultural, leadership, educational, academic, professional, or other,
Then predicted attendance is 108% of previous attendance or 50% of venue size if this is a new event.
Else if event type is meal (any),
Then if the event purpose is fine arts, cultural, sports, volunteer, or other,
Then predicted attendance is 140% of previous attendance or 85% of venue size if this is a new event.
Else if the event purpose is fun, leadership, educational, academic, or professional,
Then if the goal is community service, or social networking,
Then predicted attendance is 118% of previous attendance or 65% of venue size if this is a new event.
Else if the goal is recruiting, fund-raising (either), or talent demonstration,
Then predicted attendance is 108% of previous attendance or 50% of venue size if this is a new event.
* Create an array of objects to store the activity data in.
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 20.
The lab must allow the user to enter any number of events into the event array up to 20 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.
File of lines input method:
Along with the Lab #3 data, you should also create your own file that is any length up to 20 lines and read the data from this 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.
Each line of the file should look like: {there must be one space only between the values}:
> 842 M C 20.00 15 2 250 10.00 UC RosebudTheatre 90 0 100 One Mike Stand
which represents event 842 (One Mike Stand) on Feb. 15, with a maximum of 250 attendees. It is a fine arts concert starting at 8:00pm and lasting 90 minutes. It costs $10.00 and is located in the University Center, Rosebud Theatre.The event goal is social networking with a target of 100 people involved.
Your program will read the first number, ex. tempcode, and then error check it and store it in correct member of the object by calling the mutator function for that data member, ex. event[index].Set_eventcode(tempcode), then read and store the purpose code into the corresponding character member of the object, then read and store the third input into its member of object and so on. Your program should read all the numbers, chars and single words within a single input command. 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 events have all been read from the file, 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. Be sure to include the value that is calculated for the predicted attendance. 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 array.
* Create and display a screen menu of the following choices for the user.
Once all the data is read into the objects in the array your program should give the user a screen menu with the following choices: (use any number scheme you wish)
External functions:
i. Sort the events by code
ii. Sort the events by name
iii. Search for an event by date
iv. Search for an event by purpose
v. List all the events
vi. End the program
Function descriptions:
Sort:
The sort events by code function should use the recursive merge sort algorithm to put the list in order by the code.
The sort events by name functions may use any sort algorithm to put the list in order by name.
Search:
The search functions for purpose or date should let the user choose the event date or purpose and then look through the list to find the first event that matches that element, then print a sentence stating that matching date/purpose was or was not found and if found, it should also print the code, the name, the month, and the day of the event. These functions may use any algorithm to search. Note that the search by date must use month and day to find the correct event.
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 list of the classes you expect to write with a list of the data members and brief (one line) descriptions of the member functions. For functions not part of a class, also give one line descriptions and a diagram showing what function calls what other functions and classes. 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. This design documentation is required to be turned in for Lab 4. The lab design is due at least ONE WEEK before the lab is due. The design may be text, graphics, handwritten or whatever. If not computer generated, please scan it in (go to the computer lab or library). E-mail your design document to the Lab4 TA (not same as Lab3 TA) for you turn it in. Use a name for your document that starts with ÒLab4 Design xxx1234Ó where xxx1234 is your login ID. Design documents must be turned in in order for Lab assignments to be graded. See the website for the DESIGN DOCUMENT due date.
* 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 NOT use:
global variables
exit
break (except in a switch)
continue
any topic not covered in class before the lab DUE date unless approved by the instructor
The overall structure of the program should perform the following actions:
Print a welcome screen for the user that introduces the system
Instantiate the array of objects
Get the needed input values from the file
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 gpp 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.
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. It is recommended that you try to fill in your data with real information. In cases where you cannot find real data you may create the missing data.
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
>gpp myprogram.cpp
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: (65%)
Program, class, and function headers for all functions (3 points)
Comments (line comments and block comments) (3 points)
Modularity and Style (5 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 (8 pts)
Correct definition of mutator functions for all data members with proper input error checking (15 pts)
Correct definition of constructor and destructor functions (4 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 sort of array (4 points)
Correct search of array (3 points)
Output: (25%)
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)
Predict attendance 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 predicted value (5 points)
Output gives clear information to explain the values to the user (2 points)
Output contains all the given test data and one additional data set (3 points)
Object orientation: (10%)
OPTIONAL: Extra credit: (4%)
Correct use of enum and union data members and input for class (4 points)
Grading Deductions:
Use of global variables will result in an overall grade of 0 (zero)
Use of the exit, break (except in a switch), or continue command will result in an overall grade of 0 (zero)
Use of linked lists will result in 50 (fifty) point deduction per use
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.
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.
Miscellaneous:
Event code list:
One Mike Stand = 842
Wheelchair Basketball = 110
Baseball Game = 120
Basketball Game Mens = 130
Basketballl Game Womens = 140
FLOC Movie Night = 500
Jazz Ensemble = 803
Choir Concert = 810
Solo Recital = 874
Maverick Speaker Series = 990
Engineering Speaker Series = 318
Electrical Engineering Speaker = 337
Engineers Week = 301
Global Grounds Coffee Hour = 554
Art Glass Sale = 868
Library Friends = 935
The Big Event = 4
Oozeball = 8
Bed Races = 10
Sample data:
842 M C 20.00 15 2 250 10.00 UC RosebudTheatre 90 0 95 60 One Mike Stand
990 E C 20.00 19 2 1250 10.00 TX TexasHall 75 4 A 825 Maverick Speaker Series
554 C N 16.45 30 1 35 0.00 UC PaloDuraLounge 60 0 20 12 Global Grounds Coffee Hour
318 E C 18.00 3 4 350 0.00 NH 100 75 4 B 200 Engineering Speaker Series
842 M C 20.00 16 4 250 10.00 UC RosebudTheatre 90 0 100 75 One Mike Stand
4 V N 9.00 26 4 2000 0.00 LIB LibraryMall 240 5 25 120 The Big Event
868 M N 10.00 2 4 600 0.00 SAC 108 360 3 500 320 Art Glass Sale