Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ program on visual studio. This is the sample code: #include #include #include #include /* this program reads a sequence of 24 binary bytes of
C++ program on visual studio.
This is the sample code:
#include#include #include #include /* this program reads a sequence of 24 binary bytes of data into different data types and prints them out. The data is output in both decimal and hex. Note: the file is opened only once, and the code rewinds the file to the beginning using ifs.seekg(0). The commented code would do essentially the same thing, by closing the file stream and re-opening it. */ using namespace std; int main( ) { char buf[24]={0}; short int sibuf[12]={0}; int ibuf[6]={0}; float fbuf[6]={0}; double dbuf[3]={0}; // Open file for reading in binary mode ifstream ifs("sample_binary.dat", ios::binary); if (!ifs) { cerr (buf[i])(buf[i])(sibuf), 12*sizeof(short int)); // output the values (in decimal). cout (ibuf), 6*sizeof(int)); cout (fbuf), 6*sizeof(float)); cout (dbuf), 3*sizeof(double)); cout Write a program which does the following: Declares two integer arrays, a & b, both eleven elements long, containing the numbers: a. array a: 543516756 1667855729 1919033451 544110447 544763750 1886221674 1986994291 1948283493 1814062440 544832097 778530660 b. array b: 0 0 0 0 0 0 0 0 0 0 0 Opens a file called "binary.dat" and writes the array a to the file in binary format Closes the file (be sure to do this, or the rest of the program won't work right!) Opens the file "binary.dat" for reading, and read the data into the array b Outputs both arrays a & b to the console so you can verify that you read the data back again properly. Look at the contents of the file with a text editor and compare it to the contents of sample_binary.dat. Does it make sense? (To open it with a plain-text editor, such as Notepad app on PC or textedit on Mac, you can copy it to "binary.txt", or select "all files" in the file-open dialog box. The sample program above should help if you get stuck (or refer back to my slides). Name your program binary_io.cpp
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