Beruflich Dokumente
Kultur Dokumente
Programming Fundamentals
Fall 2010
Objectives
The objectives of this assignment are (1) to provide you with more practice on the use of the
various C++ concepts/constructs introduced in the lectures so far, including classes, lists,
dynamic memory allocation, pointers, I/O, and dynamic data structures; and (2) to provide you
with more practice on the use of the Make utility and the debugger.
2.
Problem Statement
In this assignment, you will implement the similar functionality as that for Lab #4, but instead
of using arrays, you are to use linked lists --- in fact a list of lists. Your Lab #5 program will be
tested similar to the way your Lab #4 program was tested.
Your solution will have to implement two types of linked lists, namely a list of divisions, and a
list of employees connected to a division. Your program:
will not make use of the constants MAX_DIVISIONS and MAX_EMPLOYEES, as there
will be no such maximums;
may not use any arrays anywhere in the program, except for character arrays;
must have all class data members be private, accessing them through accessor
functions; and
must not use any global variable except for one instance of a division list.
You will have to create a database of employees that looks as follows:
Division
List
Division
Employee
List
next
division
Employee
List
next
division
Employee
List
Empl_no
Empl_no
Empl_no
next
next
next
next
A division list is organized as a set of linked division nodes. Each division node contains a
division number, which must be unique and which is the index. The division node also contains
an employee list, identifying which employees work for that division. The division nodes are to
be ordered according to the division number.
The employee list is organized as a set of employee nodes. Each employee node contains an
employee number, which is the index, the employee`s first and last name, the hourly wage, and
the hours worked. The employee list is ordered by the employee number.
Lab #5
Page 1 of 6
2.1. Input/Output
The driver function will implement the user interface to the database. It inputs from cin a
sequence of commands. Each command consists of an operation, followed by its parameters.
The command and the parameters are separated by white space. You can assume that all input
provided is syntactically correct. The function should process commands until the end-of-file
(eof) is encounters. The commands and their parameters are as follows:
newdivision divisionNum
This command creates a new division node with the division number set to divNum.
The new record is inserted into the division list at the correct location.
If there already exists a division with the same divNum, then the error message
``rror: division already exists.`` must be output. Otherwise, no
output is produced.
locate emplNum
This command locates the node with the employee number emplNum in the database,
and prints its contents to cout. If no such number exists, the error message rror:
no employee with number <emplNum> exists. must be output.
delete emplNum
This command locates the node with the employee number emplNum in the database
and deletes the node. If no such node exists, then the error Error: no employee
with number <emplNum> exists. must be output. Otherwise, nothing is
output.
deleteall
This command deletes all the nodes in the database, returning it to the empty state.
Nothing is output.
deletedivision divNum
This command deletes the division with division number divNum (and along with it all
its employees). If no such division exists, then the error Error: no division
with number divNum exists.must be output. Otherwise, nothing is output.
printdivision divNum
This command prints out all employes working for the division divNum in order of
employee number. If no such division exists, then the error rror: no division
with number divNum exists. must be output.
Lab #5
Page 2 of 6
printall
This command prints out all employees ordered first by division then by employee
number.
When employee information is to be printed out, then the following format should be used:
<employeeNum> <firstName> <lastName>
for each employee on a separate line. Note that employee numbers are always 5 digits long,
division numbers are exactly 2 digits long, and that there is exactly one space between each
field. When doing this, the employees should be output in order of their employee number. For
printall, the employee information for all employees of each division should be printed out
ordered by increasing division number then increasing employee number. For each division, the
following should be output on a separate line
Division <divisionNum>:
followed by all the employees of that division.
2.2. Global Variables
You may only have one global variable of type DivisionList; e.g.
DivisionList database ;
2.3. DivisionList Class
The DivisionList class only contains as a data member the header which points to the first node
in the list, and NULL otherwise. Most of the class functions are self-explanatory:
class DivisionList {
private:
DivisionNode* head ;
public:
DivisionList() ;
~DivisionList() ;
bool newDivision( int divNum ) ;
// returns FALSE if divNum already exists, TRUE otherwise
bool newEmployee( int emplNum, int divNum, char* firstName,
char* lastName, double hours,
double hourlyWage, int& error ) ;
// if divNum doesnt exist, set error to 1 and return FALSE
// if emplNum already exists, set error to 2 and return FALSE
// return TRUE otherwise
bool deleteDivision( int divNum ) ;
// return FALSE if divNum does not exist; else TRUE
EmployeeNode* locateEmployee( int emplNum ) ;
bool locateEmployee( int emplNum, int& divNum, char*& firstName,
char*& lastName ) ;
// return TRUE if found, setting divNum, firstname and
// lastName; and return FALSE otherwise
bool deleteEmployee( int emplNum ) ;
// if emplNum doesnt exist, return FALSE; TRUE otherwise
void printDivision( int divNum ) ;
void printAll() ;
} ;
Lab #5
Page 3 of 6
Lab #5
Page 4 of 6
3.
Procedure
Create a sub-directory called lab5 in your ece244 directory, using the mkdir command,
and protect it with the chmod command. Make it your working directory, and then copy the
files you need from your Lab 4 directory. Using these files as a starting point, generate a
solution to this assignment. Additionally, create a Makefile that will produce a lab5
executable when you type make.
You may add your own helper functions to these classes. You may also add member data to
the classes, but they must be private.
4.
Deliverables
Your lab submission should consist of only the following eight files:
main.cpp Contains the main() function for your program.
Lab #5
Page 5 of 6
Lab #5
Page 6 of 6