Trying to update a data file's records (change field values,
sort, delete one particular record, etc.) is a
logistical and coding "nightmare". Is there an easier way? Since
an array is limited and a linked list is
unwieldy, what about a vector? A vector has an unlimited number
of index locations plus a series of built-in
functions.
Since a data file record has a series of fields, you would need
a struct to store these records. You would
probably want to present a user menu interface.
Load the vector from the data file when the application
starts.
What if we:
1. Read all of the target data file's records into a vector
2. Using the vector's built-in functions, we would allow the
user to sort, delete, find, add and change
field values
3. Write the records stored in the vector to the data file
(overwrite?) when the user wishes to quit this
application. All of the changes in the vector get written to the
original data file
Read in the data file from Blackboard, personnel.dat,
containing the following fields into a vector:
Employee ID (char array of size 5, such as AF101 or ND446)
Last Name (char array of size 20)
First Name (char array of size 30)
Hours (float)
Pay rate (float)
Income Tax Rate (float)
Number Dependents (int)
Allow the user to:
Display the contents of the Vector (if nothing more, this
provides confirmation)
Find a record based on Employee ID
Sort the records based on Last Name
Delete a record based on Employee ID
Change one or more of the fields, search for the target record
based on Employee ID
Add a new record to the vector
When finished, overwrite the original data file with the
vector's records
Attachment:
BB002 Skywalker Lucas 38.4 28.4 0.05
KL221 Ducke Howard 29.3 14.5 0.011
JJ287 Williams B.H. 33.1 48.3 0.023
GH121 Smith Alias 33.4 33.5 0.1
GH711 Allan Barry 36.7 80.3 0.22
HH107 Neumann Alfred 38.4 30.94 0.027
JK202 Xavier Charles 39.4 23.4 0.04
KH111 Kent Clark 40 33.5 0.01
NG201 Chen Samantha 47.5 56.75 0.05
GW101 Rodgers Steve 47.8 59.33 0.031
FG101 Doome Victor 49.5 78.25 0.02
JK290 Denvers Kara 55.6 58.95 0.077
AW109 DeMann Stan 32.4 12.35 0.09
AF101 Hill Jackie 24.5 31.32 0.1
BC217 Miller Matt 37.1 21.88 0.045