< previous page page_1002 next page >

Page 1002
typedef char String20[21];      // Room for 20 characters plus \0
typedef char String100[101];    // Room for 100 characters plus \0
typedef char String200[201];    // Room for 200 characters plus \0

struct AddressType
{
    String20 street;
    String20 city;
    String20 state;
};
struct PersonnelData
{
    String20    lastName;
    String20    firstName;
    AddressType address;
    String200   workHistory;
    String100   education;
    String200   payrollData;
};
Each of the eight character strings (last name, first name, street address, city, state, work history, education, and payroll data) is on a separate line in the file masterFile, and each string may contain embedded blanks.
The number of records in the file is unknown. The maximum number of employees that the company has ever had is 1000.
Output: The contents of the file masterFile with the records in alphabetical order by last name.
Discussion: Using object-oriented design (OOD) to solve this problem, we begin by identifying potential objects and their operations. Recall that a good way to start is to examine the problem definition, looking for important nouns and noun phrases (to find objects) and important verbs and verb phrases (to find operations). Additionally, implementation-level objects usually are necessary in the solution. Here is an object table for this problem:
Object
Operation
File masterFile
Open the file
Input data from the file
Personnel record
Read a record
Print a record
Record list
Read all personnel records into the list
Sort
Print all records in the list

 
< previous page page_1002 next page >