Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ HW code correction. Please adjust the following code so it can output the sample output. Has to be exact! Introduction to programming C++ 3rd

C++ HW code correction. Please adjust the following code so it can output the sample output. Has to be exact!

Introduction to programming C++ 3rd edition by daniel liang

Chapter 13 Programming Excercise 13

(Create a binary datafile) Write a program to create a file named Exercise.dat if it does not exist. If it does exist, append new data to it. Write 100 integers created randomly into the file using binary I/O.

6648-13-5PE AID: 1825 | 19/04/2013 Program to create binary data file Program plan: Include the header file. Create the object binaryio for binary input and output file. Open the file. Generate 100 integers randomly using rand() function. Print the message after the data is appended to Binary.dat file. Close the file. Display the result

Sample output:

Data appended

Press any key to continue . . .

Screenshot of appending the random integers to Binary.dat file

image text in transcribed int main() {

//Create the object for binary input and output file fstream binaryio;

//Open the binary file binaryio.open("Binary.dat",ios::out |ios::binary|ios::app); srand(time(0));

//Loop executes until the condition leads to false

for(int i=0;i

binaryio.close();//Close the binary file

cout Sample output: Data appended Press any key to continue Screenshot of appending the random integers to "Binary.dat" file Excercisel3 5.dat-Notepad ile Edit Format View Help 98 1 3 29 80 5 47 17 90 56 83 83 44 29 24 55 20 80 0 26 22 42 6 855 52 28 34 73 61 50 65 7 97 7 47 30 51 30 85 53 65 50 11 9 19 34 56 52 61 51 81 55 89 39 40 61 8 99 27 37 87 46 59 47 89 19 58 0 80 59 12 20 25 20 53 99 16 37 10 78 11 47 18 23 58 27 15 95 6 62 33 19 10 9 74 89 19 16 67 The above file displays the randomly generated 100 integers, and appends them to "Binary.dat If the file does not exist, it uses binary I/O

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions