Full Download C++ For Engineers and Scientists 4th Edition Bronson Solutions Manual All Chapter 2024 PDF
Full Download C++ For Engineers and Scientists 4th Edition Bronson Solutions Manual All Chapter 2024 PDF
Full Download C++ For Engineers and Scientists 4th Edition Bronson Solutions Manual All Chapter 2024 PDF
https://testbankfan.com/product/c-for-engineers-and-
scientists-4th-edition-bronson-test-bank/
https://testbankfan.com/product/statistics-for-engineers-and-
scientists-4th-edition-william-navidi-solutions-manual/
https://testbankfan.com/product/modern-physics-for-scientists-
and-engineers-4th-edition-thornton-solutions-manual/
https://testbankfan.com/product/probability-and-statistics-for-
engineers-and-scientists-for-engineers-9th-edition-johnson-
solutions-manual/
Physics For Scientists And Engineers 3rd Edition
Fishbane Solutions Manual
https://testbankfan.com/product/physics-for-scientists-and-
engineers-3rd-edition-fishbane-solutions-manual/
https://testbankfan.com/product/physics-for-scientists-and-
engineers-3rd-edition-knight-solutions-manual/
https://testbankfan.com/product/physics-for-scientists-and-
engineers-9th-edition-serway-solutions-manual/
https://testbankfan.com/product/calculus-for-scientists-and-
engineers-1st-edition-briggs-solutions-manual/
https://testbankfan.com/product/probability-and-statistics-for-
engineers-and-scientists-9th-edition-walpole-solutions-manual/
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
Another random document with
no related content on Scribd:
⎱ bardaqūsch (S.)
Ormocarpum hhemrūr, hhomrūr (H. Hodj.)
bibracteatum Bak.
Orobanche cernua Löffl. 'oddār, raúel (U.)
Orobanche minor Sutt. subb-el-qa' (M.)
áthaq (U.)
⎧
Osyris abyssinica H. ⎨ assáq (H.)
⎩
tssanddal-hēge (W.)
⎰ hhómoda (M.)
Oxalis corniculata L.
⎱ hhomēd (W. H.)
⎰ schūass (H.)
Pavetta longiflora V.
⎱ sserr (H. W.)
bunn-el-baqar (H.)
⎧
⎪ bunn-er-robách (H. M.)
⎪ fassele (W.)
Pavetta villosa Vahl. ⎨
⎪ hharmal (W.)
⎪ sser (U.), ssár (W.)
⎩
ssorä'r, ssorrer (W.)
Pavonia arabica H. gára' (U.)
Pedicellaria pentaphylla chódesch (T.)
⎰
Schr. (=
⎱ nimr (W.)
Gynandropsis)
⎧ deféss (H.)
⎪ march (U.)
Periploca ephedriformis
⎨
(Defl.) Schwf.
⎪ meslāt-nimr (H.)
⎩ uódhom (M.)
⎰ schega (U.)
Phoenix reclinata Jacq.
⎱ schótb (Hodj.)
⎰ hhōqam (Hodj.)
Pisonia aculeata L.
⎱ schuēk (Hodj.)
⎧ brābra (S.)
⎪ dérfess (H.)
Portulaca oleracea L. ⎨
⎪ dhéneb-el-fárass (Hodj.)
⎩ rigl (H.)
⎪
⎪ bssīl (H.)
⎩
kemb (H.)
Premna resinosa schúgab (H.)
Schum.
⎰ barqūq (M.)
Prunus Armeniaca L.
⎱ mischmisch (S.)
⎰ barqūq (S.)
Prunus domestica L.
⎱ ngātss (M.) (agātss)
fettách (H.)
⎧
Psiadia punctulata Vke. ⎨ schaúsam (U.)
⎩
schégeret-er-rogba (H.)
⎰ hhámsched (H.)
Pupalia lappacea Mq.T.
⎱ hhássaq (U.)
⎰ gumä' (W.)
Rhus glaucescens R.
⎱ 'ammet-el-heï̄ss (H.)
⎰ thālub (U.)
Rhus retinorrhoea St.
⎱ thálab (M. H.)
⎧ 'arscháq (H.)
⎪ hhēge, hhāga (W. H.)
Rosa abyssinica R.Br. ⎨
⎪ hhómmess (U.)
⎩ qarauan (M.)
⎰ ta'm (T.)
Rottboellia hirsuta V.
⎱ tua'm (T.)
⎰ lissān-tōr (M.)
Rumex Steudelii H.
⎱ lissān-el-baqer (M.)
⎰ quhām (H.)
Senecio odorus (F.) Defl.
⎱ kérssab (U.)
⎰ qorrēsch (Ch.)
Solanum sepicula Dun.
⎱ hhádaq (U.)
kimb (U.)
⎧
Tarchonanthus
⎨ libān (W.)
camphoratus L.
⎩
ssunjam (H.)
⎰ uarim (H.)
Teclea nobilis R.
⎱ dhúrm, dhúrum (U.)
⎰ marrār (M.)
Tripteris Vaillantii L.
⎱ jahhdāb (M.)
⎰ hhāfe
Typha angustifolia L.
⎱ hhafá' (T.)
⎰ moghēbre (H.)
Verbenac. sp. arom.
⎱ hhahhna (H.)
⎰ digré (T.)
Vigna sinensis Endl.
⎱ lúbija (S.)
⎰ rūm (Hodj.)
Zea Mays L.
⎱ rūmi (S.)
⎰ ssidr (M.)
Ziziphus spina-Christi L.
⎱ 'elan (S.)
a' b ch d dh d(e)
ا ب خ د ذ د
e' f g gh g(e) h
ا ف ج غ ج ه
hh i. j k l m n
ح ي ك ل م ن
o' q r s sch ss
ا ق ر ز ش س
t th tss tt u
ت ث ص ط و
NACHTRAG ZU b ب
a'
ا
b
ب
ch
خ