CIS 2003 - Introduction to C++ and C Programming
Bob Comer, Professor, CIS/CSC


Assignment 7 - Payroll Program

In assignment 6 you defined a class or a struct to represent the master file information for one employee. Most students used an array of employee objects (or structs) to store the 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 (or structs) to hold the master file. Then dynamically allocate one employee object (or struct) at a time as the employee data as is read in.

In the Example C++ Programs section of this website 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.cpp itemfile.txt
Arrays of pointers to structs with DMA itemptr.cpp itemfile.txt
Arrays of objects, sequential search itemclass.cpp itemfile.txt
Arrays of pointers to objects with DMA itemptr2.cpp itemfile.txt

Rewrite your Payroll program from Assignment 6 to dynamically allocate the memory used to store the employee information from the master file.

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


Return to C++ Home Page

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