Question
Write a function to read a binary file in random access mode. Your function will open a file that contains a list of 4-byte binary
Write a function to read a binary file in "random access" mode. Your function will open a file that contains a list of 4-byte binary integers. You should read the first integer to find the index of the next integer, print this index to an ostream, and repeat until you hit a negative integer. *IF* the file was an array of integers, you'd be doing something like this:
int i=0;
while (i >=0 ){
i = myArray[i];
cout << i << " ";
}
You can implement this using either seekg to jump around in the file or by reading the whole file into a big array first.
Your function should be called numberChase and should take two parameters, a C++ string for the filename, and an ostream to print the indices too.
(HINT: The first file that the instructors testing program checks contains the four integers +3 0 -77 +2; you're supposed to follow the integers. So after reading the 3, you jump to *integer* 3; this has the value 2, so you jump to *integer* 2; this has the value -77 so you stop.)
(You only write the function, and the instructor's given test program tests it with given binary files.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started