2. Create a class with two public members: an integer and a double. Repeat part
ID: 3563732 • Letter: 2
Question
2. Create a class with two public members: an integer and a double. Repeat part 1 (of this assignment), but instead of 2 integers, use 2 objects of your class (put in whatever values you wish). You can use sizeof() to get the size of your object.
3.
Create an fstream to a binary file that you can both write to and read from. Write 5 objects of your class to your binary file. Then see if you can read them all back in order and print them to the screen. Next, see if you can retrieve the third object directly from the file by using seekg() and an offset from the file beginning of 2 object size.
Explanation / Answer
/* Testing Binary File IO (TestBinaryFileIO.cpp) */ #include #include #include #include using namespace std; int main() { string filename = "test.bin"; // Write to File ofstream fout(filename.c_str(), ios::out | ios::binary); if (!fout.is_open()) { cerrRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.