Intermediate Business Programming with C++
In a previous lecture, the example below was considered. Review the files so that you know how the program works.
In this maintenance exercise, instead of using text file I/O, binary file I/O is to be used so that the objects of the class bookInventory are used for I/O instead of the attribute values.
Design: Two changes need to be made in the total project. First the file: theFunctions.h has to be modified to permit binary file I/O. In particular the two functions: loadInventory() and saveInventory() need to be changed to permit binary file I/O. This is done in the new header file:theNewFunctions.h that includes the functions from the original header except that these two functions are replaced with: loadBinaryInventory() and saveBinaryInventory(). (In addition the names of the data files were changed from: inventory.dat to binaryinventory.dat. This last change was not a requirement but should help to identify the two different types of files.)
Open theNewFunctions.h and notice how the file I/O is handled differently. In addition to this change the file: doInventory.cpp needs to be replaced by the file: doBinaryInventory.cpp. These two files are the same except for the include that requests the new header: theNewFunctions.h
Take the files listed below and place them into a project and view how the text file I/O is handled.
-
bookInventory.h
-
bookInventory.cpp
-
theFunctions.h
-
doInventory.cpp
After you have built and run the project above, create another new project that contains the following files which handle the binary file I/O and see how the program is improved.
-
bookInventory.h
-
bookInventory.cpp
-
theNewFunctions.h
-
doBinaryInventory.cpp
Категории