C++ for Engineers and Scientists 4th Edition Bronson Solutions Manual instant download
C++ for Engineers and Scientists 4th Edition Bronson Solutions Manual instant download
https://testbankdeal.com/product/c-for-engineers-and-
scientists-4th-edition-bronson-solutions-manual/
https://testbankdeal.com/product/c-for-engineers-and-scientists-4th-
edition-bronson-test-bank/
https://testbankdeal.com/product/statistics-for-engineers-and-
scientists-4th-edition-william-navidi-solutions-manual/
https://testbankdeal.com/product/modern-physics-for-scientists-and-
engineers-4th-edition-thornton-solutions-manual/
https://testbankdeal.com/product/quantitative-analysis-for-
management-13th-edition-render-test-bank/
Leadership and Management for Nurses 3rd Edition Finkelman
Test Bank
https://testbankdeal.com/product/leadership-and-management-for-
nurses-3rd-edition-finkelman-test-bank/
https://testbankdeal.com/product/fundamentals-of-corporate-finance-
canadian-9th-edition-ross-test-bank/
https://testbankdeal.com/product/engineering-mechanics-statics-4th-
edition-pytel-solutions-manual/
https://testbankdeal.com/product/macroeconomics-2nd-edition-acemoglu-
test-bank/
https://testbankdeal.com/product/calculus-of-a-single-variable-
hybrid-10th-edition-larson-test-bank/
Medical Surgical Nursing 7th edition Ignatavicius Test
Bank
https://testbankdeal.com/product/medical-surgical-nursing-7th-edition-
ignatavicius-test-bank/
C++ for Engineers and Scientists, Fourth Edition 8-1
Chapter 8
I/O Streams and Data Files
At a Glance
• Objectives
• Teaching Tips
• Quick Quizzes
• Additional Projects
• Additional Resources
• Key Terms
C++ for Engineers and Scientists, Fourth Edition 8-2
Lecture Notes
Overview
The data for the programs your students have used so far has been assigned internally in the
programs or entered by the user during program execution. As such, data used in these programs
is stored in the computer’s main memory and ceases to exist after the program using it has
finished executing. This type of data entry is fine for small amounts of data. However, your
students can imagine a company having to pay someone to type in the names and addresses of
hundreds or thousands of customers every month when bills are prepared and sent.
In this chapter your students will learn that storing large amounts of data outside a program on a
convenient storage medium is more sensible. They will discover that data stored together under a
common name on a storage medium other than the computer’s main memory is called a data file.
Typically, data files are stored on disks, USB drives, or CD/DVDs. Besides providing permanent
storage for data, data files can be shared between programs, so the data one program outputs can
be input in another program. In this chapter, your students learn how data files are created and
maintained in C++.
Objectives
In this chapter, students will learn about:
• I/O file stream objects and functions
• Reading and writing character-based files
• Random file access
• File streams as function arguments
• A case study about a pollen count file update
• The iostream class library
• Common programming errors
Teaching Tips
8.1 I/O File Stream Objects and Functions
1. Introduce the general concept that to store and retrieve data outside a C++ program two
things are required: a file and a file stream object.
Files
1. Introduce the concept of a file as a collection of data stored together under a common and
unique name on an external medium.
C++ for Engineers and Scientists, Fourth Edition 8-3
2. Review the characteristics of external filenames as they differ between operating systems
and over time.
Teaching Students may find the difference between character and binary file types
Tip confusing since in fact they are both comprised of sets of binary values.
3. Introduce the two basic file types: text or character-based files, and binary-based files.
1. Introduce the concept of a file stream, a one-way transmission path used to connect a
program to a file stored on a physical device.
2. Discuss the difference between input file streams and output file streams.
3. Review the important functions in the ifstream and ofstream objects, and the
related concepts of opening and closing a file.
Teaching Closing a file can be discussed in the larger context of resource management and
Tip ensuring that all resources requested from the operating system are returned.
1. Introduce the concept of the core file stream functions, including opening a file and
closing a file.
Quick Quiz 1
1. What term describes a collection of data stored under a common name?
Answer: a file
2. True or False: The two basic types of files are character-based and binary-based files.
Answer: True
C++ for Engineers and Scientists, Fourth Edition 8-4
3. Make sure that students understand how to specify a file’s location on their computer:
path + filename.
1. Introduce the concept of a logical file as a stream that connects a program to a set of
logically related data.
2. Discuss the concept of a physical file as a stream that connects a program to a hardware
device.
3. Introduce the standard input and standard output files, cin and cout.
4. Highlight the set of devices that are automatically connected when the iostream
header is included in a program.
C++ for Engineers and Scientists, Fourth Edition 8-5
Quick Quiz 2
1. True or False: The actual storage of characters in a character-based file depends on the
character codes the computer uses.
Answer: True
2. What term describes a stream that connects a file of logically related data, such as a data
file, to a program?
Answer: logical file object
3. True or False: There is a big difference between reading data from the keyboard and
reading data from a character-based file.
Answer: False
2. Highlight the difference between random access and sequential file access, touching on
the file position marker functions.
3. Introduce the concept of a file offset as a character’s zero-based position from the start of
a file.
One source of errors in a program that makes use of random file access is to
Teaching
miscalculate file offsets as one-based values. Highlighting the zero-based nature
Tip
of an offset may be very helpful to your students.
Quick Quiz 3
1. True or False: The two types of file access are called sequential and arbitrary.
Answer: False
2. True or False: Using random file access functions, any character in the opened file can be
read without having to sequentially read all characters stored ahead of it.
Answer: True
C++ for Engineers and Scientists, Fourth Edition 8-6
3. True or False: The seek() and tell() family of functions mark positions in a random
access file.
Answer: True
Quick Quiz 4
1. True or False: File stream arguments must never be passed by reference.
Answer: False
1. Review the general functionality provided by the iostream class library, including
encapsulation of the details of reading a byte-stream.
2. You might point out that buffers are used extensively in I/O operations, and that they help
compensate for different data transmission rates.
Your students may find it helpful to view the concept of a device driver in the
Teaching
context of the file as an abstraction permitting access to a large number of
Tip
devices and to data in a large number of formats.
1. Introduce the two primary base classes associated with the iostream: streambuf
and ios.
2. Highlight the set of classes that derive from the ios base class.
In-Memory Formatting
Quick Quiz 5
1. True or False: The iostream class library consists of two primary base classes,
streambuf and ios.
Answer: True
2. Name the object type that is typically used to “assemble” a string from smaller pieces
until a complete line of characters is ready to be written.
Answer: strstream
Quick Quiz 6
1. True or False: Opening a file before attempting to access it is required.
Answer: True
2. True or False: The file’s external name can be used interchangeably with the stream
object name when programming to access the file.
Answer: False
C++ for Engineers and Scientists, Fourth Edition 8-8
3. When required to make existing data available to a program, which stream object
should be used?
Answer: iostream
2. Investigate scenarios where random access is the more appropriate mechanism for file
input.
Additional Projects
1. Have the students write a small C++ program that uses sequential file access to retrieve
an arbitrary line in a text file with fixed length lines whose name and line number (base
1) is specified on the command line. Then have the students convert the program to use
random access to perform the same functions.
Additional Resources
1. Tutorial on iostream use:
www.devarticles.com/c/a/Cplusplus/Iostream-Library-and-Basic-IO-in-Cplusplus/
Key Terms
Binary-based files: Files that use the same codes as the C++ compiler uses to store data
Character-based files: Files where the data is stored using a character code set such as
ASCII
Closing a file: Closing a connection between stream objects
Device driver: A section of operating system code that accesses a hardware device and
handles data transfer between the device and the computer’s memory
C++ for Engineers and Scientists, Fourth Edition 8-9
External name: The unique name by which a file is known to the operating system
File: A collection of data stored together under a common name
File access: The process of retrieving data from a file
File organization: The way in which data is stored in a file
Logical file object: A stream that connects a file of logically related data to a program
Offset: A character’s position in a file
Opening a file: Connecting a stream object name to an external filename
Output mode: The state of a file connected to an output file stream where the stream is
available for writing
Physical file object: A stream that connects a hardware device to a program
Random access: The type of file access in which any character in the opened file can be
read without having to sequentially read all characters stored ahead of it first
Sequential access: The type of file access that involves reading characters one after
another from an open input file stream
Sequential organization: Characters in a file are stored in a sequential manner
Standard output file: The standard object, cout, that is usually automatically created
and available for data entry
Text files: Files where the data is stored using a character code set such as ASCII
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of When
Wilderness was King: A Tale of the Illinois
Country
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: English
By
RANDALL PARRISH
With six pictures in full color and other
decorations
by Troy and Margaret West Kinney
Third Edition
Chicago
A. C. McClurg & Co.
1904
Copyright
By A. C. McClurg & Co.
1904
—Benjamin F. Taylor.
When Wilderness Was King
CHAPTER I
A MESSAGE FROM THE WEST
URELY it was no longer ago than yesterday. I
had left the scythe lying at the edge of the
long grass, and gone up through the rows of
nodding Indian corn to the house, seeking a
draught of cool water from the spring. It was
hot in the July sunshine; the thick forest on
every side intercepted the breeze, and I had
been at work for some hours. How pleasant
and inviting the little river looked in the shade of the great trees,
while, as I paused a moment bending over the high bank, I could
see a lazy pike nosing about among the twisted roots below.
My mother, her sleeves rolled high over her round white arms,
was in the dark interior of the milk-house as I passed, and spoke to
me laughingly; and I could perceive my father sitting in his great
splint-bottomed chair just within the front doorway, and I marked
how the slight current of air toyed with his long gray beard. The old
Bible lay wide open upon his knee; yet his eyes were resting upon
the dark green of the woods that skirted our clearing. I wondered,
as I quaffed the cool sweet water at the spring, if he was dreaming
again of those old days when he had been a man among men. How
distinct in each detail the memory of it remains! The blue sky held
but one fleecy white cloud in all its wide arch; it seemed as if the
curling film of smoke rising from our chimney had but gathered
there and hung suspended to render the azure more pronounced. A
robin peeked impudently at me from an oak limb, and a roguish gray
squirrel chattered along the low ridge-pole, with seeming willingness
to make friends, until Rover, suddenly spying me, sprang hastily
around the corner of the house to lick my hand, with glad barkings
and a frantic effort to wave the stub of his poor old tail. It was such
a homely, quiet scene, there in the heart of the backwoods, one I
had known unchanged so long, that I little dreamed it was soon to
witness the turning over of a page of destiny in my life, that almost
from that hour I was to sever every relation of the past, and be sent
forth to buffet with the rough world alone.
There were no roads, in those days, along that valley of the
upper Maumee,—merely faint bridle-paths, following ancient Indian
trails through dense woods or across narrow strips of prairie-land;
yet as I hung the gourd back on its wooden peg, and lifted my eyes
carelessly to the northward, I saw a horseman riding slowly toward
the house along the river bank. There were flying rumors of coming
Indian outbreaks along the fringe of border settlements; but my
young eyes were keen, and after the first quick thrill of suspicion I
knew the approaching stranger to be of white blood, although his
apparel was scarcely less uncivilized than that of the savage. Yet so
unusual were visitors, that I grasped a gun from its pegs in the
kitchen, and called warningly to my mother as I passed on to meet
the new-comer.
He was a very large and powerful man, with a matted black
beard and an extremely prominent nose. A long rifle was slung at his
back, and the heavy bay horse he bestrode bore unmistakable signs
of hard travelling. As he approached, Rover, spying him, sprang out
savagely; but I caught and held him with firm grip, for to strangers
he was ever a surly brute.
"Is this yere Major Wayland's place?" the man questioned, in a
deep, gruff voice, reining in his tired horse, and carelessly flinging
one booted foot across the animal's neck as he faced me.
"Yes," I responded with caution, for we were somewhat
suspicious of stray travellers in those days, and the man's features
were not pleasing. "The Major lives here, and I am his son."
He looked at me intently, some curiosity apparent in his eyes, as
he deliberately drew a folded paper from his belt.
"No? Be ye the lad what downed Bud Eberly at the meetin' over
on the Cow-skin las' spring?" he questioned, with faintly aroused
interest.
I blushed like a school-girl, for this unexpected reference was not
wholly to my liking, though the man's intentions were evidently most
kind.
"He bullied me until I could take no more," I answered,
doubtfully; "yet I hurt him more seriously than I meant."
He laughed at the trace of apology in my words.
"Lord!" he ejaculated, "don't ever let that worry ye, boy. The hull
settlement is mighty glad 'twas done. Old Hawkins bin on the p'int o'
doin' it himself a dozen o' times. Told me so. Ye're quite a lad, ain't
ye? Weigh all o' hundred an' seventy, I'll bet; an' strong as an ox.
How old be ye, anyhow?"
"Twenty," I answered, not a little mollified by his manner. "You
must live near here, then?"
"Wal, no, but been sorter neighbor o' yourn fer a month er so
back; stoppin' up at Hawkins's shebang, at the ford, on the Military
Road, visitin'; but guess I never met up with none o' your folks
afore. My name's Burns, Ol' Tom Burns, late o' Connecticut. A sojer
from out West left this yere letter fer yer father at Hawkins's place
more nor a week ago. Said as how it was mighty important; but
blamed if this wasn't the fust chance he's hed to git it over yere
sence. I told him I'd fetch it, as it wasn't more nor a dozen miles er
so outer my way."
He held out a square paper packet; and while I turned it over
curiously in my hand,—the first letter I had ever seen,—he took
some loose tobacco from an outside pocket and proceeded leisurely
to fill his pipe.
My mother rolled my father's chair forward into the open
doorway, and stood close behind him, as was her custom, one arm
resting lightly upon the quaintly carved chair-back.
"What is it, John?" she questioned gently. Instantly aroused by
her voice, I crossed quickly over and placed the packet in my
father's thin hands. He turned it over twice before he opened it,
looking at the odd seal, and reading the superscription carefully
aloud, as if fearful there might be some mistake:
"Major David Wayland,
Along the Upper Maumee.
Leave at Hawkins Ford
"Important. on Military Road."
I can see him yet as he read it, slowly feeling his way through
the rude, uneven writing, with my mother leaning over his shoulder
and helping him, her rosy cheeks and dark tresses making strange
contrast beside his pain-racked features and iron-gray hair.
"Read it aloud, Mary," he said at last. "I shall understand it better.
'Tis from Roger Matherson, of whom you have heard me speak."
My mother was a good scholar, and she read clearly, only
hesitating now and then over some ill-written or misspelled word.
At Fort Dearborn, near the head of the
Great Lake. Twelfth June, 1812.
My Dear Old Friend:
I have come to the end of life; they tell me it will be all over by the morrow, and
there remains but one thing that greatly troubles me—my little girl, my Elsa. You know
I have never much feared death, nor do I in this hour when I face it once more; for I
have ever tried to honor God and do my duty as both man and soldier. David, I can
scarcely write, for my mind wanders strangely, and my fingers will but barely grasp the
pen. 'Tis not the grip of the old sword-hand you knew so well, for I am already very
weak, and dying. But do you yet remember the day I drew you out of the rout at
Saratoga, and bore you away safely, though the Hessians shot me twice? God knows,
old friend, I never thought to remind you of the act,—'twas no more than any comrade
would have done,—yet I am here among strangers, and there is no one else living to
whom I may turn in my need. David, in memory of it, will you not give my little orphan
child a home? Your old comrade, upon his death-bed, begs this of you with his final
breath. She is all alone here, save for me, and there is no blood kin in all the world to
whom I may appeal. I shall leave some property, but not much. As you love your own,
I pray you be merciful in this hour to my little girl.
Your old comrade,
Roger Matherson.
testbankdeal.com