Lab Assignment #4

                                 CSE 1320-005

                                 Spring 2006

 

Instructor : Carter Tiernan

 

ASSIGNED   : Wednesday, April 12, 2006

DUE        : Thursday, May 4, 2006

CONCEPTS   : Ch. 12 -- C++ classes and objects

WEIGHT     : 10%

LANGUAGE   : C++

COMPILER   : g++

PLATFORM   : omega

 

FORMAT OF SOURCE CODE FILES : ASCII text

 

MAIN DATA STRUCTURE: an array of 5 class pointers

 

INPUT FILES: Lab3Hires.dat

             Lab3Mods.dat

             Lab3Transfers.dat

 

OUTPUT FILE: not used in this assignment--all output goes to the screen

 

SOURCE CODE FILES: a constants file

                   a class definition file

                   a class member functions definitions file

                   a driver file

 

ORIGINAL: 03.02.06 RS Mod: 04.11.06 JCMT

 

Overview of the Problem:

 

 The Roberts Music Corporation is still considering expanding its operations by

opening a new store in the Dallas/Ft. Worth area.  As the Corporation continues the planning of the expansion, their software group continues the responsibility of developing and conducting a pilot study of the new store's operations.

 

 As a member of the software group, you were given the responsibility

of designing and implementing a software program to be used to model the

hiring and transferring of employees.  The software you wrote in C was used as an initial study for the larger full-fledged system that would need to be written. 

 

  Now your task is to rewrite most of your previous functions to use objects in C++ to increase the security, maintainability and reusability of the employee data.  In particular you will create a class type for the employees which securely contains all of the member data to be stored about an employee (as private data) and controls access to this data through a collection of class member functions.  The class type will replace the struct type from the previous assignment.  The class will be defined in two files.

 

The class definition file will define a class in terms of data members and member function prototypes to represent an employee. The class data members will store the same type of information as was used for the previous assignment slightly simplified.   The required data members for the class are :

 

               (1) first name

               (2) middle initial

               (3) last name

               (4) employee id    // as a long int

               (5) title          // as a string not an enumerated type

               (6) monthly salary // always a double for this assignment

 

Notice that no enumerated type or union are required for this assignment.  All of the data members listed above must be stored in the private section of the class type. 

 

  In order to access this data, the public part of the class must contain member functions to construct a class object (constructor), to access or “get” the current value of each data member of an object (6 accessor functions), to change or “set” new values in each data member (6 mutator functions), a print function to display all the data values of the class object, and a function to delete the object (destructor).  The prototypes for these member functions are part of the class definition. 

 

  The member function definitions for this class will be in a separate class member functions file.  Each of the 15 member functions listed above must be defined in this file.  These member functions are the mechanism used in C++ to implement error-checking on input values, valid initialization of objects, range checking on data member values (ex. No salaries less than 0.00), and protection of the data members from unwanted access by other parts of the system.

 

  Using this class type (defined by the definition and member function files), your program will declare an array of five (5) pointers to this type. This array should be declared in the main function and the values of all pointers should be initialized to NULL. These pointers will then be used in the program to hold the locations of constructed objects and to allow access to the member functions of these objects.  This array will replace the linked list from Lab 3 as the principal data structure for the assignment.

 

  With the creation of the array of class object pointers, the program is now ready to perform the tasks related to employee hiring, pay and transfers.  Your program will implement the following tasks as separate functions except as noted:

 

In the main function, read the needed employee data file names from the program command line;

 

Call a function to open these files and test to make sure the files opened correctly or end the program in the files could not be opened correctly.

 

Dynamically allocate a class object allocated to a pointer in the array;

 

“Hire” new employees by reading employee data from the input files and storing each employee into a class object allocated to a pointer in the array.  Note that the hires file may have data for more than 5 employees or less than 5.  Be sure to handle these cases.  The input data files are in the same format as in the previous assignment.  Also print each new employee hired and the updated array of employees after each hiring.  Print messages to indicate if there are no more employees to hire (less than 5) or if there are no more positions available to hire into (more than 5 people in file).;

 

Print all employee data.  Be sure to check the value of each pointer in the array before trying to print member data.;

 

Read in data to modify employee salary information and make the appropriate changes.  This should follow the same requirements as in the previous assignment.;

 

“Transfer” individual employees out of this store by removing them from the data storage structure.  Be sure to deallocate any dynamically allocated space for the object before setting the array pointer to NULL. Again, follow the same requirements for printing, etc. as for the previous assignment.;

 

“Close” a store by transferring all employees out of a store by removing them from the data storage structure (deallocating space and setting pointers to NULL).  Print the  array to indicate there are no employees. ;

 

To demonstrate the complete functionality of the class definition, be sure to use every member function at least once in your program.  For example, the “set” functions will be used to store data in an object and the “get” functions will be used to print the data.

 

 

 

 

TURN IN in class on the due date a script session of the code developed for this

 assignment, in the order shown below.  This script session must be produced on

 the student's own OMEGA account.  If the assignment has not been completed,

 turn in as much as has been done, as a script session, in the order shown

 below.

 

The order for the script session is:

 

1.  a "cat" of the constants file

2.  a compilation of the constants file

3.  a "cat" of the class definition file

4.  a compilation of the class definition file

5.  a "cat" of the class member functions file

6.  a compilation of the class member functions file

7.  a "cat" of the driver file

8.  a compilation of the driver file

9.  the execution command line and arguments

10. the output

 

Also, EMAIL the source code files to the TA on or before the due date/time.

 

 

 

HINTS in no particular order

 

      HINT:  open one window per file, and two SecureShell windows, for a

              total of six windows open on the desktop at the same time,

              for faster code development

             

          HINT:  Develop files incrementally (a little at a time) and compile

               files incrementally (after each expansion of the code in the

               file)

 

  HINT:  When coding the driver file, stub each function initially just so that

           the compiler can check the spelling, syntax, etc.  This limits the

           required corrections to a small number of possible errors for this

           stage of development.  Then, as each function is actually defined,

           additional compilation will not include the spelling and syntax

           errors which were corrected after the function stubs were compiled

           but will focus on the most recent changes.

 

 

 

      NOTE:  The order of the #include statements in the four files is:

     

          a.  the constants file will #include all required system files

               (iostream, stdlib, etc), listed in alphabetical order by

               file name

              

               NOTE:  if the compiler complains that a particular system

                       file, as listed, has been deprecated or something

                       to that effect, try removing the .h extension

                       from the file in the #include statement, or adding

                       a 'c' character to the name of the file, etc.

                      

                      An example of possible variations on the iostream

                       file preprocessor directive include:

                      

                          #include<iostream.h>

                          #include<iostream>

                          #include<ciostream>

                          #include<ciostream.h>

                       

          b.  the class definition file will #include the constants file

          c.  the class member functions file will #include the class

               definition file

          d.  the driver file will #include the class member functions file

         

          The purpose of the above ordering of the #include preprocessor

           directives is to ensure that the compiler will have encountered

           the definition of each type before any actual uses of that type.

 

HINT:  Define a constants file, which will be responsible for

    

          a.  #including any required system files

          b.  defining/initializing any required symbolic constants

          c.  defining/initializing any required constant variables

d.        prototyping all global functions except the main function 

Definitions of global functions will be in the file with main

 

 

                  HINT:  list each file's function prototypes/definitions in

                          alphabetical order by function name, for faster

                          searching during code development.

              

          NOTE:  if the compiler complains that a certain use of something is

                  not allowed to have a type, declare it using a #define

                  instead of a const int, const double, etc.

                 

          NOTE:  if the compiler complains that a certain use of something

                  must have a type, declare it using 'const' instead of

                  '#define'.

                 

                     NOTE:  if any of the fields in the class definition are

                             pointers, be sure to dynamically allocate

                             sufficient memory for each such pointer in the

                             constructor member function.

 

NOTE:    emphasize printing the values of all attributes of an employee

                  on a single line, to reduce the number of lines in the output

                  of this function

 

 

 

 

 

Grading scale TBD  (4.11.06 jcmt)