Question
C++ Program Questions 1. Write 4 very short C++ programs: one that opens a text file, write 2 integers to it, and closes it (basically
C++ Program Questions
1. Write 4 very short C++ programs: one that opens a text file, write 2 integers to it, and closes it (basically the first part of the above), one that opens the text file you wrote to, reads the 2 integers from it and prints them out to the screen (basically the second part of above). The other two does basically the same thing but with a binary file, using write() to write to the binary file, and read() to read from the binary file. For read () and write() you can use the sizeof() function to get the size of an integer. Run the programs that write to the files first and then run the programs that read from them afterwards.
2. Open the two files you created using NotePad (or other simple text editor) and take screen shots of the contents.
3. Create a class with two public members: an integer and a double. Repeat 4 and 5, 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.
4. 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.
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