Lab #4 Assignment , CSE 1320-002 Fall 2009

 

Due Date:       Lab #4 is due absolutely no later than 8 pm Thursday Dec. 10th

                                    Extra Credit for early submission as follows:

                                                      Turned in before 11:59pm Sunday Dec 6 –                40 extra points

                                                      Turned in before 11:59pm Monday Dec 7 –              30 extra points

                                                    Turned in before 11:59pm Tuesday Dec 8 –             20 extra points

                                                    Turned in before 11:59pm Wednesday Dec 9 –     10 extra points

(see instructions on website for how to turn this in)

 

Grade value;    10% of total class grade.

 

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.

 

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.

 

-- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? -- ? --

 

In Lab #1 you started developing the Campus Activity System, CAS. Throughout the course of this semester you have worked on your CAS. Each lab assignment will build on the previous assignments and will also implement changes to make the system more efficient and so on.

 

Throughout the course of the semester you will work on this health tracking system. In lab #4 you are going to be looking at and manipulating your activity 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 still be given a list of activities along with information such as meeting dates and costs. You will write one or more class definitions that will hold the activity 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 activity/group and associated functions. The members of this class should include:

                                             Private data members for all the campus activity/group 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 income to the group/activity of the dues paid by all the members and stores the results in new data members of the object

?              Create an array of objects to store the activity data in.

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

1) Using the data in the array,

A)  Sort the activity data list by group number (any algorithm)

B)  Search for activity and group choices and data by

         i.      Meeting day and time

         ii.    Group name

C)  Calculate

         i.      Average cost to join any activity of a particular purpose (e.g. average cost to join any social group)

         ii.    Average length of a group meeting

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

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

 

Simplifying assumptions for the lab:

a) Various constants will be given for use in lab #4.

b) All groups/activities will have a unique number.

c) 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 Campus Activity System 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. (You do NOT have to clear the screen after the menu. Just let it scroll off the screen as more data is printed.)

 

?              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 calculates the total income to the group/activity of the dues paid by all the members and stores the results in new data members of the object

                  A public member function that displays all the group data for one activity

 

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.

 

o        Group/activity number - the numeric code associated with a specific group or activity. (ex. The Big Event = 004, SWE = 132, Student Senate = 488, etc.). For all the other pieces of data, the information that is in the same struct inside the array will refer to the same activity/group. (See the group/activity code list at the end of this assignment and you can add to it if desired.)

o        Group name - the string giving the name of the associated group/activity. This should be declared in the struct as a char pointer. Each name string should be read in to a temporary array, the length of the string should be found, space should then be malloced to the char pointer in the struct to hold the size of the name, then the name should be copied from the temp array to the struct char pointer space.

o        Meeting time - the hour and minute info for the meeting time of the associated group/activity. The time is represented as HH.MM as a floating point number. Make sure that the meeting hour and minute that are entered are valid.

o        Meeting half day - the a.m. or p.m. info for the meeting time of the associated group/activity. Make sure that the character that is entered is valid.

o        Next meeting day – the date of the next meeting as a two digit number. Be sure to check for validity.

o        Next meeting month – the month of the next meeting as a two digit number. Be sure to check for validity.

o        Group/activity purpose - the code of the purpose of the associated group/activity. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o        Group/activity size - the number of people involved in the associated group/activity.

·         Group/activity cost - the amount in dollars and cents that it costs to participate in the associated group/activity. Make sure this amount is not negative but it can be free to participate.

o        Meeting length – meeting length in minutes. Be sure to check for validity.

o        Income – Calculated total income from size times cost. This value is not read from the file, it is calculated by the class.

 

 

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

 

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 Group/activity purpose data member should have at least the following two public functions associated with it:

                  An accessor function, e.g. Get_Group/activity purpose(), that would return the current value of that data member, and

                  A mutator function, e.g. Set_Group/activity 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 Next meeting day and Next meeting month 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. You must write a display function for your class that prints out all the activity data that is included in an object.

 

Another member function must calculate the Income. It must be called by the mutator functions for Group/activity cost and Group/activity size so that Income will change when either of them change.

 

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

 

?              Create an array of objects to store the activity data in.

 

For the lab #4, you must implement data file input.  For this lab the user must enter at least 12 activities. There is no maximum amount of data. For file input, your program should read until it reaches the end of the file (EOF). You may also implement user input if desired but it is not required for Lab #4. For user input by line of data or pieces of data, you must tell the user what to enter that will tell the program that input is complete.

 

As the data for each activity is read in, it should be stored into one object in the array that you have declared.

  

Data file (File of lines) input method:

You must create a file that contains 12 or more lines of activity data and you must read the data from this file. You must pass the file name into the program as a command line paramete. The first line of data in the file will simply be the first record of data in the file.

 

Input verification:

When all of the activity input has been read in, print out all the input activity 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 list.

 

 

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

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

 

 

i.          Sort the activity data list by group number (any algorithm)

ii.         Search for activity and group choices and data by meeting day and time

iii.       Search for activity and group choices and data by group name

iv.       Calculate average cost to join any activity of a particular purpose (e.g. average cost to join any social group)

v.         Calculate average length of a group meeting

vi.       List all the activities and all their respective data

vii.      Update the data in the list

viii.    End the program

 

The sort (i) may be implemented with any algorithm to sort based on the group number only. The program should then sort the array and print the sorted list.

 

The searches (ii. iii) for an activity may use any search algorithm. For whichever type of search is chosen, the user must enter the data they wish to search for. The search function should search to return the first matching element, if any, printing the group number and the name of the activity. For the meeting time search, if two activities are at the same time, return the one with the smaller group number.

 

The calculate average cost function (iv) asks the user to choose a purpose (from the list of purpose codes), then goes through the list sums all the costs of groups with that purpose and then divides by the number of those groups to get the average cost of that type of group. The average length calculation (v) takes an average of the time lengths of all the activities. It should print the activity average length in minutes.

 

The list activities function (vi) is the same as the print function described for input verification.

 

The update option (vii) should take the user to a second screen to allow them to update information in the list. This screen should ask for a activity code from the user and search for that activity. Once the correct activity is determined. give the user a menu of the following options. All of the change functions must use the mutator functions to make changes.

 

o        Change Group name in that struct

o        Change Meeting time or half day

o        Change Purpose

o        Change Size

o        Change Cost

o        Return to main menu

 

After each change is made, print all of the activity info for the activity object that was changed.

 

When the user chooses ?End the program? from the main menu, print a concluding message and then gracefully end the program.

 

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

 

 

Implementation requirements:

 

DESIGN YOUR PROGRAM FIRST BEFORE CODING. 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.

 

 

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

 

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 program should perform the following actions in the given order:

Instantiate the array of objects

Print a welcome screen for the user that introduces the system

Get the needed input value from the file and 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. 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.

 

This program must be run with two different sets of test data for the activity constant 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.

 

The program output must be recorded in a script file from OMEGA using the gpp compiler. 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.

 

Grading scale:

Code:   (68%)

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 average cost function and average activity length function (4 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 (3 pts)

Correct creation of the array of objects (3 points)

Correct sort of array (4 points)

Correct search of array (3 points)

Output:      (22%)

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

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

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

Calculate tasks perform correctly using member functions (3 points)

Update tasks perform correctly using member functions (3 points)

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

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

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

Object orientation:      (10%)

 

 

Deductions:

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

            Use of exit, break (not in a switch), or continue will result in 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) without prior instructor approval

            Use of C or 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:

 

 

Activity/group code list:

The Big Event = 004

Oozeball = 008

Bed Races = 010

JCEO/ESC = 130

SWE = 132

SHPE = 133

NSBE = 134

TSPE = 135

ACM = 140

GDC = 141

IEEE = 150

IIE = 160

BMESS = 170

BMES = 171

SACNAS = 221

Concert choir = 512

Marching band = 525

Student Senate = 488

FLOC = 490

UTA Volunteers = 491

BSA = 610

FSI = 630

 

Sample data:

 

490 88 3 12.30 p W 10/7 V A UC 212A 0.0 90 3 UTA Freshman Leaders on Campus

132 43 1 12.0 p M 10/12 P E NH 110 15.00 45 1 5.00 Society of Women Engineers

8 120 3 6.0 p F 10/9 S A MAC VB1 20.00 20 0 1987 Oozeball