Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try

in c++ pleaseimage text in transcribed

image text in transcribed

HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened for writing and the user is prompted for integer values which are written to the output file. If the user decides to read the ints from nums.txt, then the file is opened and the integers it contains are extracted and displayed to stdout. If you'd like to see some sample runs, take a look at ReadWritelntsSampleRuns.txt. For this implementation, you'll have to write a couple of other functions in addition to the main function: . writents-this function is called from main if the user wants to save a set of integers to the nums.txt file: it accepts as an input argument an opened output file stream object that's ready for writing. It then prompts the user for five integer values, each of which are written to the output file before returning back to the caller Displaylnts this function is called from main if the user wants to display the contents of nums.txt to stdout; it accepts as an input argument an opened input file stream object that's ready for reading. It proceeds to extract the five integer values and display them to stdout. The main function will drive the whole program, it'll be responsible for determining which function to call as well as the opening and closing of files. For more information, you may want to look in your book on p.308 for an introduction to file I/O, and a simple example on p.313 where the author demonstrates the.open and.close member functions you can call once you've declared an ifstream or ofstream variable. (However, don't forget to call the .fail function after you open the file so you can check if you were successful in opening the file; see p.316 for a brief discussion of that as well as a code sample!) Finally, on p.334 where the author points out that when you pass file stream variables as arguments to functions, they must be passed by reference

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions