COSC 1320 - C++ Programming and
ITSE 1307 - Introduction to C++ Programming
Bob Comer, Professor of Computer Studies


Assignment 8 - Payroll Version 4.0

Read through Chapter 10 (Pointers) before beginning this assignment. Be sure to read carefully section 10.8 on dynamic memory allocation. In assignment 7 you defined a class to represent the information for one employee, and used an array of class objects to hold the employee master file. If the actual number of employees is much smaller than the array size, this would waste a lot of memory. One way around this problem is to use an array of pointers to employee objects to represent the master file. Then dynamically allocate one employee object at a time as the employee data as is read in.

Rewrite your Payroll program from Assignment 7 to dynamically allocate the memory used to store the employee information from the master file. Use an array of pointers to employee objects. Each employee object will be dynamically allocated to hold the master file data.

Your new program should produce the same output as the previous version.

Hints

I am not asking you to use a dynamically allocated array as described in section 10.8 of the Gaddis textbook. An array of pointers is not the same as a dynamically allocated array.

In the Example C++ Programs section of this web site there are several example programs that illustrate using arrays of structs, arrays of objects, and arrays of pointers to structs or objects:

Arrays of structs, sequential search

itemstru.htm

itemfile.txt

Arrays of pointers to structs with DMA

itemptr.htm

itemfile.txt

Arrays of objects, sequential search

itemclass.htm

itemfile.txt

Arrays of pointers to objects with DMA

itemptr2.htm

itemfile.txt


Return to C++ Home Page

Copyright: Ó2005 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to:
Bob Comer
Last updated: November 30, 2005