SlideShare a Scribd company logo
Chapter 6
I/O Streams as an Introduction
to Objects and Classes
Overview
6.1 Streams and Basic File I/O
6.2 Tools for Stream I/O
6.3 Character I/O
Slide 6- 2
6.1
Streams and Basic File I/O
I/O Streams
 I/O refers to program input and output
 Input is delivered to your program via a stream object
 Input can be from

The keyboard

A file
 Output is delivered to the output device via a stream
object
 Output can be to

The screen

A file
Slide 6- 4
Objects
 Objects are special variables that
 Have their own special-purpose functions
 Set C++ apart from earlier programming
languages
Slide 6- 5
Streams and Basic File I/O
 Files for I/O are the same type of files used to
store programs
 A stream is a flow of data.
 Input stream: Data flow is into the program

If input stream flows from keyboard, the program will
accept data from the keyboard

If input stream flows from a file, the program will accept
data from the file
 Output stream: Data flow is out of the program

Can go to the screen

Can go to a file
Slide 6- 6
cin And cout Streams
 cin
 Input stream connected to the keyboard
 cout
 Output stream connected to the screen
 cin and cout defined in the iostream library
 Use include directive: #include <iostream>
 You can declare your own streams to use with
files.
Slide 6- 7
Why Use Files?
 The keyboard input and screen output we have used so far
deal with temporary data.
 Files allow you to store data permanently!
 Data output to a file lasts after the program ends
 An input file can be used over and over
 No typing of data again and again for testing
 Create a data file or read an output file at your
convenience
 Files allow you to deal with larger data sets
Slide 6- 8
File I/O
 Reading from a file
 Taking input from a file
 Done from beginning to the end (for now)

Just as done from the keyboard
 Writing to a file
 Sending output to a file
 Done from beginning to end (for now)

Just as done to the screen
Slide 6- 9
Stream Variables
 Like other variables, a stream variable…
 Must be declared before it can be used
 Must be initialized before it contains valid
data

Initializing a stream means connecting it to a file

The value of the stream variable can be thought of
as the file it is connected to
 Can have its value changed

Changing a stream value means disconnecting from
one file and connecting to another
Slide 6- 10
Streams and Assignment
 A stream is a special kind of variable called
an object
 Objects can use special functions to complete tasks
 Streams use special functions instead of the
assignment operator to change values
Slide 6- 11
Declaring An
Input-file Stream Variable
 Input-file streams are of type ifstream
 Type ifstream is defined in the fstream library
 You must use the include and using directives
#include <fstream>
using namespace std;
 Declare an input-file stream variable using
ifstream in_stream;
Slide 6- 12
Declaring An
Output-file Stream Variable
 Ouput-file streams of are type ofstream
 Type ofstream is defined in the fstream library
 You must use these include and using directives
#include <fstream>
using namespace std;
 Declare an output-file stream variable using
ofstream out_stream;
Slide 6- 13
Connecting To A File
 Once a stream variable is declared, connect it to
a file
 Connecting a stream to a file is opening the file
 Use the open function of the stream object
in_stream.open("infile.dat");
Slide 6- 14
Dot
File name on the disk
Double quotes
Using The Input Stream
 Once connected to a file, the input-stream
variable can be used to produce input just as
you would use cin with the extraction operator
 Example:
int one_number, another_number;
in_stream >> one_number
>> another_number;
Slide 6- 15
Using The Output Stream
 An output-stream works similarly to the input-stream
 ofstream out_stream;
out_stream.open("outfile.dat");
out_stream << "one number = "
<< one_number
<< "another number = "
<< another_number;
 After the file (i.e., "outfile.dat") is open, we should
use the stream name (e.g., out_stream) as the
name of the file.
Slide 6- 16
Closing a File
 After using a file, it is good programming practice to close
the file
 This disconnects the stream from the file
 Close files to reduce the chance of a file being
corrupted if the program terminates abnormally
 The system will automatically close files if you forget as
long as your program ends normally
Slide 6- 17
Closing a File
 Do you need to close the file?
NO
 Should you close the file?
Depends.
 Do you care about the possible error conditions
that could occur if the file fails to close correctly?
Remember that close calls setstate(failbit) if it
fails. The destructor will call close() for you
automatically but will not leave you a way of
testing the failbit as the object no longer exists.
Slide 1- 18
Display
6.1
Slide 6- 19
Objects
 An object is a variable that has functions and
data associated with it
 in_stream and out_stream each have a
function named open associated with them
 in_stream and out_stream use different
versions of a function named open

One version of open is for input files

A different version of open is for output files
Slide 6- 20
Member Functions
 A member function is a function associated
with an object
 The open function is a member function of
in_stream in the previous examples
 A different open function is a member function
of out_stream in the previous examples
Slide 6- 21
Objects and
Member Function Names
 Objects of different types have different member
functions
 Some of these member functions might have the same
name
 Different objects of the same type have the same
member functions
Slide 6- 22
Classes
 A type whose variables are objects, is called a class
 ifstream is the type of the in_stream variable (object)
 ifstream is a class
 The class of an object determines its
member functions
 Example:
ifstream in_stream1, in_stream2;

in_stream1.open and in_stream2.open are the same
function but might have different arguments
Slide 6- 23
Class Member Functions
 Member functions of an object are the member
functions of its class
 The class determines the member functions of
the object
 The class ifstream has an open function
 Every variable (object) declared of type ifstream
has that open function
Slide 6- 24
Calling a Member Function
 Calling a member function requires specifying
the object containing the function
 The calling object is separated from the member
function by the dot operator
 Example: in_stream.open("infile.dat");
Slide 6- 25
Calling object
Dot operator
Member function
Member Function
Calling Syntax
 Syntax for calling a member function:
Calling_object.Member_Function_Name(Argument_list);
Slide 6- 26
Errors On Opening Files
 Opening a file could fail for several reasons
 Common reasons for open to fail include

The file might not exist

The name might be typed incorrectly
 May be no error message if the call to open fails
 Program execution continues!
Slide 6- 27
Catching Stream Errors
 Member function fail, can be used to test the
success of a stream operation
 fail returns a boolean type (true or false)
 fail returns true if the stream operation failed
Slide 6- 28
Halting Execution
 When a stream open function fails, it is generally best to
stop the program
 The function exit, used to terminate a program
 exit causes program to end immediately
 by convention, 1 is used for a call to exit that is caused
by an error, and 0 is used otherwise
 exit is NOT a member function
 exit requires the include and using directives
#include <cstdlib>
using namespace std;
Slide 6- 29
Using fail and exit
 Immediately following the call to open, check
that the operation was successful:
in_stream.open("stuff.dat");
if( in_stream.fail( ) )
{
cout << "Input file opening failed.n";
exit(1) ;
}
Slide 6- 30
Display 6.2
Display
6.2
Slide 6- 31
Techniques for File I/O
 When reading input from a file…
 Do not include prompts or echo the input

The lines cout << "Enter the number: ";
cin >> the_number;
cout << "The number you
entered is "
<< the_number;
become just one line
in_file >> the_number;
 The input file must contain exactly the data expected
Slide 6- 32
Appending Data (optional)
 Output examples so far create new files
 If the output file already contains data, that data
is lost
 To append new output to the end an existing file
 use the constant ios::app defined in the iostream
library:
outStream.open("important.txt", ios::app);
 If the file does not exist, a new file will be created
Slide 6- 33
Display 6.3
Display
6.3
Slide 6- 34
File Names as Input (optional)
 Program users can enter the name of a file to
use for input or for output
 Program must use a variable that can hold
multiple characters
 A sequence of characters is called a string
 Declaring a variable to hold a string of characters:
char file_name[16];

file_name is the name of a variable

Brackets enclose the maximum number of characters + 1

The variable file_name contains up to 15 characters
Slide 6- 35
Using A Character String
 char file_name[16];
cout << "Enter the file_name ";
cin >> file_name;
ifstream in_stream;
in_stream.open(file_name);
if (in_stream.fail( ) )
{
cout << "Input file opening failed.n";
exit(1);
}
Slide 6- 36
Display 6.4 (1)
Display 6.4 (2)
Display 6.4
(1/2)
Slide 6- 37
Display 6.4
(2/2)
Slide 6- 38
Section 6.1 Conclusion
 Can you
 write a program that uses a stream called fin which
will be connected to an input file and a stream called
fout which will be connected to an output file? How
do you declare fin and fout? What include
directive, if any, do you need to place in your
program file?
 write a program to take its input from the file stuff1.dat and
send its output to the file stuff2.dat. What statements do
you need to place in your program in order to connect the
stream fin to the file stuff1.dat and to connect the stream
fout to the file stuff2.dat? Be sure to include checks to
make sure that the openings were successful.
Slide 6- 39
6.2
Tools for Streams I/O
The End of The File
 Input files used by a program may vary in length
 Programs may not be able to assume the number
of items in the file
 A way to know the end of the file is reached:
 The boolean expression (in_stream >> next)

Reads a value from in_stream and stores it in next

True if a value can be read and stored in next

False if there is not a value to be read (the end of the file)
Slide 6- 41
Tools for Stream I/O
 To control the format of the program's output
 We use commands that determine such details
as:

The spaces between items

The number of digits after a decimal point

The numeric style: scientific notation for fixed point

Showing digits after a decimal point even if they are
zeroes

Showing plus signs in front of positive numbers

Left or right justifying numbers in a given space
Slide 6- 42
Formatting Output to Files
 Format output to the screen with:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
 Format output to a file using the out-file stream
named out_stream with:
out_stream.setf(ios::fixed);
out_stream.setf(ios::showpoint);
out_stream.precision(2);
Slide 6- 43
out_stream.precision(2);
 precision is a member function of output streams
 After out_stream.precision(2);
Output of numbers with decimal points…

will show a total of 2 significant digits
23. 2.2e7 2.2 6.9e-1
0.00069
OR

will show 2 digits after the decimal point
23.56 2.26e7 2.21 0.69 0.69e-4
 Calls to precision apply only to the stream
named in the call
Slide 6- 44
setf(ios::fixed);
 setf is a member function of output streams
 setf is an abbreviation for set flags

A flag is an instruction to do one of two options

ios::fixed is a flag
 After out_stream.setf(ios::fixed);
All further output of floating point numbers…

Will be written in fixed-point notation, the way we
normally expect to see numbers
 Calls to setf apply only to the stream named in
the call
Slide 6- 45
setf(ios::showpoint);
 After out_stream.setf(ios::showpoint);
Output of floating point numbers…

Will show the decimal point even if all digits after the
decimal point are zeroes
Slide 6- 46
Display 6.5
Creating Space in Output
 The width function specifies the number of
spaces for the next item
 Applies only to the next item of output
 Example: To print the digit 7 in four spaces use
out_stream.width(4);
out_stream << 7 << endl;
 Three of the spaces will be blank
Slide 6- 47
7 7
(ios::right) (ios::left)
Not Enough Width?
 What if the argument for width is too small?
 Such as specifying
cout.width(3);
when the value to print is 3456.45
 The entire item is always output
 If too few spaces are specified, as many more
spaces as needed are used
Slide 6- 48
Unsetting Flags
 Any flag that is set, may be unset
 Use the unsetf function
 Example:
cout.unsetf(ios::showpos);
causes the program to stop printing plus signs
on positive numbers
Slide 6- 49
Manipulators
 A manipulator is a function called in a
nontraditional way
 Manipulators in turn call member functions
 Manipulators may or may not have arguments
 Used after the insertion operator (<<) as if the
manipulator function call is an output item
Slide 6- 50
The setw Manipulator
 setw does the same task as the member
function width
 setw calls the width function to set spaces for output
 Example: cout << "Start" << setw(4) << 10
<< setw(4) << setw(6) << 30;
produces: Start 10 20 30
Slide 6- 51
Two Spaces Four Spaces
The setprecision Manipulator
 setprecision does the same task as the member
function precision
 Example: cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout << "$" << setprecision(2)
<< 10.3 << endl
<< "$" << 20.5 << endl;
produces: $10.30
$20.50
 setprecision setting stays in effect until changed
Slide 6- 52
Manipulator Definitions
 The manipulators setw and setprecision are
defined in the iomanip library
 To use these manipulators, add these lines
#include <iomanip>
using namespace std;
Slide 6- 53
Stream Names as Arguments
 Streams can be arguments to a function
 The function's formal parameter for the stream
must be call-by-reference
 Example: void make_neat(ifstream& messy_file,
ofstream&
neat_file);
Slide 6- 54
The End of The File
 Input files used by a program may vary in length
 Programs may not be able to assume the number
of items in the file
 A way to know the end of the file is reached:
 The boolean expression (in_stream >> next)

Reads a value from in_stream and stores it in next

True if a value can be read and stored in next

False if there is not a value to be read (the end of the file)
Slide 6- 55
End of File Example
 To calculate the average of the numbers in a file
 double next, sum = 0;
int count = 0;
while(in_stream >> next)
{
sum = sum + next;
count++;
}
double average = sum / count;
Slide 6- 56
Stream Arguments
and Namespaces
 Using directives have been local to function
definitions in the examples so far
 When parameter type names are in a namespace
 A using directive must be outside the function so
C++ will understand the parameter type names such
as ifstream
 Easy solution is to place the using directive at the
beginning of the file
 Many experts do not approve as this does not allow
using multiple namespaces with names in common
Slide 6- 57
Program Example
 The program in Display 6.6…
 Takes input from rawdata.dat
 Writes output to the screen and to neat.dat

Formatting instructions are used to create a neater layout

Numbers are written one per line in a field width of 12

Each number is written with 5 digits after the decimal point

Each number is written with a plus or minus sign
 Uses function make_neat that has formal parameters
for the input-file stream and output-file stream
Slide 6- 58
Display 6.6 (1) Display 6.6 (2) Display 6.6 (3)
Section 6.2 Conclusion
 Can you
 Show the output produced when the following
line
is executed?
cout << "*" << setw(3) << 12345 << "*" endl;
 Describe the effect of each of these flags?
Ios::fixed ios::scientific ios::showpoint
ios::right ios::right ios::showpos
Slide 6- 59
6.3
Character I/O
Character I/O
 All data is input and output as characters
 Output of the number 10 is two characters '1' and '0'
 Input of the number 10 is also done as '1' and '0'
 Interpretation of 10 as the number 10 or as characters
depends on the program
 Conversion between characters and numbers is
usually automatic
Slide 6- 61
Low Level Character I/O
 Low level C++ functions for character I/O
 Perform character input and output
 Do not perform automatic conversions
 Allow you to do input and output in anyway you
can devise
Slide 6- 62
Member Function get
 Function get
 Member function of every input stream
 Reads one character from an input stream
 Stores the character read in a variable of type
char, the single argument the function takes
 Does not use the extraction operator (>>)
which performs some automatic work
 Does not skip blanks
Slide 6- 63
Using get
 These lines use get to read a character and store
it in the variable next_symbol
char next_symbol;
cin.get(next_symbol);
 Any character will be read with these statements

Blank spaces too!

'n' too! (The newline character)
Slide 6- 64
get Syntax
 input_stream.get(char_variable);
 Examples: char next_symbol;
cin.get(next_symbol);
ifstream in_stream;
in_stream.open("infile.dat");
in_stream.get(next_symbol);
Slide 6- 65
More About get
 Given this code: char c1, c2, c3;
cin.get(c1);
cin.get(c2);
cin.get(c3);
and this input:
AB
CD
 c1 = 'A' c2 = 'B' c3 = 'n'
 cin >> c1 >> c2 >> c3; would place 'C' in c3
(the ">>" operator skips the newline character)
Slide 6- 66
The End of The Line
 To read and echo a line of input
 Look for 'n' at the end of the input line:
cout<<"Enter a line of input and I will "
<< "echo it.n";
char symbol;
do
{
cin.get(symbol);
cout << symbol;
} while (symbol != 'n');
 All characters, including 'n' will be output
Slide 6- 67
'n ' vs "n "
 'n'
 A value of type char
 Can be stored in a variable of type char
 "n"
 A string containing only one character
 Cannot be stored in a variable of type char
 In a cout-statement they produce the same result
Slide 6- 68
Member Function put
 Function put
 Member function of every output stream
 Requires one argument of type char
 Places its argument of type char in the output
stream
 Does not do allow you to do more than
previous output with the insertion operator and
cout
Slide 6- 69
put Syntax
 Output_stream.put(Char_expression);
 Examples: cout.put(next_symbol);
cout.put('a');
ofstream out_stream;
out_stream.open("outfile.dat");
out_stream.put('Z');
Slide 6- 70
Member Function putback
 The putback member function places a character
in the input stream
 putback is a member function of every input stream
 Useful when input continues until a specific character
is read, but you do not want to process the character
 Places its argument of type char in the input stream
 Character placed in the stream does not have to
be a character read from the stream
Slide 6- 71
putback Example
 The following code reads up to the first blank in
the input stream fin, and writes the characters to
the file connected to the output stream fout
 fin.get(next);
while (next != ' ')
{
fout.put(next);
fin.get(next);
}
fin.putback(next);
 The blank space read to end the loop is put back into
the input stream
Slide 6- 72
Program Example
Checking Input
 Incorrect input can produce worthless output
 Use input functions that allow the user to
re-enter input until it is correct, such as
 Echoing the input and asking the user if it is
correct
 If the input is not correct, allow the user to
enter the data again
Slide 6- 73
Checking Input: get_int
 The get_int function seen in Display 6.7
obtains an integer value from the user
 get_int prompts the user, reads the input, and displays
the input
 After displaying the input, get_int asks the user to
confirm the number and reads the user's response
using a variable of type character
 The process is repeated until the user indicates with
a 'Y' or 'y' that the number entered is correct
Slide 6- 74
Checking Input: new_line
 The new_line function seen in Display 6.7 is
called by the get_int function
 new_line reads all the characters remaining in the
input line but does nothing with them, essentially
discarding them
 new_line is used to discard what follows the first
character of the the user's response to get_line's
"Is that correct? (yes/no)"

The newline character is
discarded as well
Slide 6- 75
Display 6.7 (1)
Display 6.7 (2)
Slide 10- 76
Inheritance and Output
 ostream is the class of all output streams
 cout is of type ostream
 ofstream is the class of output-file streams
 The ofstream class is a child class of ostream
 More about this in Chapter 10
 This function can be called with ostream or
ofstream arguments
void say_hello(ostream& any_out_stream)
{
any_out_stream << "Hello";
}
Slide 10- 77
Program Example:
Another new_line Function
 The new_line function from Display 6.7 only
works with cin
 This version works for any input stream
void new_line(istream& in_stream)
{
char symbol;
do
{
in_stream.get(symbol);
} while (symbol != 'n');
}
Slide 10- 78
Program Example:
Calling new_line
 The new version of new_line can be called with
cin as the argument
new_line(cin);
 If the original version of new_line is kept in the
program, this call produces the same result
new_line( );
 New_line can also be called with an
input-file stream as an argument
new_line(fin);
Slide 10- 79
Default Arguments
 It is not necessary to have two versions of
the new_line function
 A default value can be specified in the
parameter list
 The default value is selected if no argument is
available for the parameter
 The new_line header can be written as
new_line (istream & in_stream = cin)
 If new_line is called without an argument, cin is
used
Slide 10- 80
Multiple Default Arguments
 When some formal parameters have default
values and others do not
 All formal parameters with default values must be
at the end of the parameter list
 Arguments are applied to the all formal parameters
in order just as we have seen before
 The function call must provide at least as many
arguments as there are parameters without default
values
Slide 10- 81
Default Argument Example
 void default_args(int arg1, int arg2 = -3)
{
cout << arg1 << ' ' << arg2 << endl;
}
 default_args can be called with one or
two parameters
 default_args(5); //output is 5 -3
 default_args(5, 6); //output is 5 6
Checking Input:
Check for Yes or No?
 get_int continues to ask for a number until the
user responds 'Y' or 'y' using the do-while loop
do
{
// the loop body
} while ((ans !='Y') &&(ans != 'y') )
 Why not use ((ans =='N') | | (ans == 'n') )?
 User must enter a correct response to continue
a loop tested with ((ans =='N') | | (ans == 'n') )

What if they mis-typed "Bo" instead of "No"?
 User must enter a correct response to end the loop
tested with ((ans !='Y') &&(ans != 'y') )
Slide 6- 82
Mixing cin >> and cin.get
 Be sure to deal with the 'n' that ends each
input line if using cin >> and cin.get
 "cin >>" reads up to the 'n'
 The 'n' remains in the input stream
 Using cin.get next will read the 'n'
 The new_line function from Display 6.7 can
be used to clear the 'n'
Slide 6- 83
'n' Example
 The Code:
cout << "Enter a number:n";
int number;
cin >> number;
cout << "Now enter a letter:n";
char symbol;
cin.get(symbol);
Slide 6- 84
The Dialogue:
Enter a number:
21
Now enter a letter:
A
The Result:
number = 21
symbol = 'n'
A Fix To Remove 'n'
 cout << "Enter a number:n";
int number;
cin >> number;
cout << "Now enter a letter:n";
char symbol;
cin >>symbol;
Slide 6- 85
Another 'n' Fix
 cout << "Enter a number:n";
int number;
cin >> number;
new_line( ); // From Display 6.7
cout << "Now enter a letter:n";
char symbol;
cin.get(symbol);
Slide 6- 86
Detecting the End of a File
 Member function eof detects the end of a file
 Member function of every input-file stream
 eof stands for end of file
 eof returns a boolean value

True when the end of the file has been reached

False when there is more data to read
 Normally used to determine when we are NOT
at the end of the file

Example: if ( ! in_stream.eof( ) )
Slide 6- 87
Using eof
 This loop reads each character, and writes it to
the screen
 in_stream.get(next);
while (! in_stream.eof( ) )
{
cout << next;
in_stream.get(next);
}
 ( ! In_stream.eof( ) ) becomes false when the
program reads past the last character in the file
Slide 6- 88
The End Of File Character
 End of a file is indicated by a special character
 in_stream.eof( ) is still true after the last
character of data is read
 in_stream.eof( ) becomes false when the
special end of file character is read
Slide 6- 89
How To Test End of File
 We have seen two methods
 while ( in_stream >> next)
 while ( ! in_stream.eof( ) )
 Which should be used?
 In general, use eof when input is treated as
text and using a member function get to read
input
 In general, use the extraction operator method
when processing numeric data
Slide 6- 90
Program Example:
Editing a Text File
 The program of Display 6.8…
 Reads every character of file cad.dat and copies it to
file cplusad.dat except that every 'C' is changed to
"C++" in cplusad.dat
 Preserves line breaks in cad.dat

get is used for input as the extraction operator would skip
line breaks

get is used to preserve spaces as well
 Uses eof to test for end of file
Slide 6- 91
Display 6.8 (1)
Display 6.8 (2)
Character Functions
 Several predefined functions exist to facilitate
working with characters
 The cctype library is required
 #include <cctype>
using namespace std;
Slide 6- 92
The toupper Function
 toupper returns the argument's upper case
character
 toupper('a') returns 'A'
 toupper('A') return 'A'
Slide 6- 93
toupper Returns An int
 Characters are actually stored as an integer
assigned to the character
 toupper and tolower actually return the integer
representing the character
 cout << toupper('a'); //prints the integer for 'A'
 char c = toupper('a'); //places the integer for 'A' in c
cout << c; //prints 'A'
 cout << static_cast<char>(toupper('a')); //works too
Slide 6- 94
The isspace Function
 isspace returns true if the argument is whitespace
 Whitespace is spaces, tabs, and newlines
 isspace(' ') returns true
 Example: if (isspace(next) )
cout << '-';
else
cout << next;
 Prints a '-' if next contains a space, tab, or
newline character
 See more character functions in
Slide 6- 95
Display 6.9 (1)
Display 6.9 (2)
Section 6.3 Conclusion
 Can you
 Write code that will read a line of text and echo
the line with all the uppercase letters deleted?
 Describe two methods to detect the end of an
input file:
 Describe whitespace?
Slide 6- 96
Chapter 6 -- End
Slide 6- 97
Display 6.1
Slide 6- 98
Back Next
Display 6.2
Slide 6- 99
Back Next
Display 6.3
Slide 6- 100
Back Next
Display 6.4 (1/2)
Slide 6- 101
Back Next
Display 6.4 (2/2)
Slide 6- 102
Back Next
Display 6.5
Slide 6- 103
Back Next
Display 6.6 (1/3)
Slide 6- 104
Back Next
Display 6.6 (2/3)
Slide 6- 105
Back Next
Display 6.6
(3/3)
Slide 6- 106
Back Next
Display 6.7 (1/2)
Slide 6- 107
Back Next
Display 6.7
(2/2)
Slide 6- 108
Back Next
Display 6.8 (1/2)
Slide 6- 109
Next
Back
Display 6.8 (2/2)
Slide 6- 110
Back Next
Display 6.9
(1/2)
Slide 6- 111
Back Next
Display 6.9 (2/2)
Slide 6- 112
Back Next
Call-by-Reference Parameters
 Call-by-value is not adequate when we need
a sub-task to obtain input values
 Call-by-value means that the formal parameters
receive the values of the arguments
 To obtain input values, we need to change the
variables that are arguments to the function

Recall that we have changed the values of
formal parameters in a function body, but we have not
changed the arguments found in the function call
 Call-by-reference parameters allow us to change
the variable used in the function call
 Arguments for call-by-reference parameters must be
variables, not numbers
Slide 5- 113
Call-by-Reference Example
 void get_input(double& f_variable)
{
using namespace std;
cout << “ Convert a Fahrenheit temperature”
<< “ to Celsius.n”
<< “ Enter a temperature in Fahrenheit: “;
cin >> f_variable;
}
 ‘&’ symbol (ampersand) identifies f_variable as a
call-by-reference parameter
 Used in both declaration and definition!
Slide 5- 114
Display 5.4
Call-By-Reference Details
 Call-by-reference works almost as if the
argument variable is substituted for the formal
parameter, not the argument’s value
 In reality, the memory location of the argument
variable is given to the formal parameter
 Whatever is done to a formal parameter in the
function body, is actually done to the value at the
memory location of the argument variable
Slide 5- 115
Display 5.5
5.3
Using Procedural Abstraction
Using Procedural Abstraction
 Functions should be designed so they can be
used as black boxes
 To use a function, the declaration and comment
should be sufficient
 Programmer should not need to know the
details of the function to use it
Slide 5- 117
Functions Calling Functions
 A function body may contain a call to another
function
 The called function declaration must still appear
before it is called

Functions cannot be defined in the body of another function
 Example: void order(int& n1, int& n2)
{
if (n1 > n2)
swap_values(n1, n2);
}

swap_values called if n1 and n2
are not in ascending order

After the call to order, n1 and
n2 are in ascending order
Slide 5- 118
Display 5.8
Display 5.8 (1/2)
Slide 5- 119
Display 5.8
(2/2)
Slide 5- 120
Pre and Postconditions
 Precondition
 States what is assumed to be true when the
function is called

Function should not be used unless the precondition holds
 Postcondition
 Describes the effect of the function call
 Tells what will be true after the function is
executed
(when the precondition holds)
 If the function returns a value, that value is described
 Changes to call-by-reference parameters are
described
Slide 5- 121
swap_values revisited
 Using preconditions and postconditions the
declaration of swap_values becomes:
void swap_values(int& n1, int& n2);
//Precondition: variable1 and variable 2 have
// been given values
// Postcondition: The values of variable1 and
// variable2 have been
// interchanged
Slide 5- 122
Function celsius
 Preconditions and postconditions make the
declaration for celsius:
double celsius(double farenheit);
//Precondition: fahrenheit is a temperature
// expressed in degrees Fahrenheit
//Postcondition: Returns the equivalent temperature
// expressed in degrees Celsius
Slide 5- 123
Why use preconditions
and postconditions?
 Preconditions and postconditions
 should be the first step in designing a function
 specify what a function should do

Always specify what a function should do before
designing how the function will do it
 Minimize design errors
 Minimize time wasted writing code that doesn’t
match the task at hand
Slide 5- 124
Case Study
Supermarket Pricing
 Problem definition
 Determine retail price of an item given suitable input
 5% markup if item should sell in a week
 10% markup if item expected to take more than a
week

5% for up to 7 days, changes to 10% at 8 days
 Input

The wholesale price and the estimate of days until item sells
 Output

The retail price of the item
Slide 5- 125
Supermarket Pricing:
Problem Analysis
 Three main subtasks
 Input the data
 Compute the retail price of the item
 Output the results
 Each task can be implemented with a function
 Notice the use of call-by-value and
call-by-reference parameters in the following
function declarations
Slide 5- 126
Supermarket Pricing:
Function get_input
 void get_input(double& cost, int& turnover);
//Precondition: User is ready to enter values
// correctly.
//Postcondition: The value of cost has been set to
// the wholesale cost of one item.
// The value of turnover has been
// set to the expected number of
// days until the item is sold.
Slide 5- 127
Supermarket Pricing:
Function price
 double price(double cost, int turnover);
//Precondition: cost is the wholesale cost of one
// item. turnover is the expected
// number of days until the item is
// sold.
//Postcondition: returns the retail price of the item
Slide 5- 128
Supermarket Pricing:
Function give_output
 void give_output(double cost, int turnover, double price);
//Precondition: cost is the wholesale cost of one item;
// turnover is the expected time until sale
// of the item; price is the retail price of
// the item.
//Postcondition: The values of cost, turnover, and price
// been written to the screen.
Slide 5- 129
Supermarket Pricing:
The main function
 With the functions declared, we can write the
main function:
int main()
{
double wholesale_cost, retail_price;
int shelf_time;
get_input(wholesale_cost, shelf_time);
retail_price = price(wholesale_cost, shelf_time);
give_output(wholesale_cost, shelf_time, retail_price);
return 0;
}
Slide 5- 130
Supermarket Pricing:
Algorithm Design -- price
 Implementations of get_input and give_output
are straightforward, so we concentrate on
the price function
 pseudocode for the price function
 If turnover <= 7 days then
return (cost + 5% of cost);
else
return (cost + 10% of cost);
Slide 5- 131
Supermarket Pricing:
Constants for The price Function
 The numeric values in the pseudocode will be
represented by constants
 Const double LOW_MARKUP = 0.05; // 5%
 Const double HIGH_MARKUP = 0.10; // 10%
 Const int THRESHOLD = 7; // At 8 days use
//HIGH_MARKUP
Slide 5- 132
Supermarket Pricing:
Coding The price Function
 The body of the price function
 {
if (turnover <= THRESHOLD)
return ( cost + (LOW_MARKUP * cost) ) ;
else
return ( cost + ( HIGH_MARKUP *
cost) ) ;
}
 See the complete program in
Slide 5- 133
Display 5.9
Display 5.9 (1/3)
Slide 5- 134
Display 5.9 (2/3)
Slide 5- 135
Display 5.9
(3/3)
Slide 5- 136
Supermarket Pricing :
Program Testing
 Testing strategies
 Use data that tests both the high and low markup
cases
 Test boundary conditions, where the program is
expected
to change behavior or make a choice

In function price, 7 days is a boundary condition

Test for exactly 7 days as well as one day more and one day
less
Slide 5- 137
Section 5.3 Conclusion
 Can you
 Define a function in the body of another
function?
 Call one function from the body of another
function?
 Give preconditions and postconditions for the
predefined function sqrt?
Slide 5- 138
5.4
Testing and Debugging
Test Drivers and Stubs.
Slide 1- 140
 How can you test a function that depends on other
functions?
 Test driver: set up a dummy environment that allows you
to call a function and display its return values. A driver
program should be as simple as possible.
 Stub: If the function A you are testing calls another
function B, then use a simplified version of function B,
called a stub.
A stub returns a value that is sufficient for testing. The
stub does not need to perform the real calculation.
Testing and Debugging Functions
 Each function should be tested as a separate unit
 Testing individual functions facilitates finding
mistakes
 Driver programs allow testing of individual
functions
 Once a function is tested, it can be used in the
driver program to test other functions
 Function get_input is tested in the driver program
of and
Slide 5- 141
Display 5.10 (1) Display 5.10 (2)
Display 5.10
(1/2)
Slide 5- 142
Display 5.10
(2/2)
Slide 5- 143
Stubs
 When a function being tested calls other functions
that are not yet tested, use a stub
 A stub is a simplified version of a function
 Stubs are usually provide values for testing rather
than perform the intended calculation
 Stubs should be so simple that you have confidence
they will perform correctly
 Function price is used as a stub to test the rest of
the supermarket pricing program in
and
Slide 5- 144
Display 5.11 (1) Display 5.11 (2)
Display 5.11
(1/2)
Slide 5- 145
Display 5.11
(2/2)
Slide 5- 146
Rule for Testing Functions
 Fundamental Rule for Testing Functions
 Test every function in a program in which
every other function in that program has
already been fully tested and debugged.
Slide 5- 147
Section 5.4 Conclusion
 Can you
 Describe the fundamental rule for testing functions?
 Describe a driver program?
 Write a driver program to test a function?
 Describe and use a stub?
 Write a stub?
Slide 5- 148
5.5
General Debugging
Techniques
General Debugging Techniques
 Stubs, drivers, test cases as described in the previous
section
 Keep an open mind
 Don’t assume the bug is in a particular location
 Don’t randomly change code without understanding what
you are doing until the program works
 This strategy may work for the first few small programs
you write but is doomed to failure for any programs of
moderate complexity
 Show the program to someone else
Slide 5- 150
General Debugging Techniques
 Check for common errors, e.g.
 Local vs. Reference Parameter
 = instead of ==
 Localize the error
 This temperature conversion program has a
bug
 Narrow down bug using cout statements
Slide 1- 151
Display 5.12
Display 5.13
Display 5.12
Slide 5- 152
Display 5.13 (1 of 2)
Slide 5- 153
General Debugging Techniques
 Use a debugger
 Tool typically integrated with a development
environment that allows you to stop and step through a
program line-by-line while inspecting variables
 The assert macro
 Can be used to test pre or post conditions
#include <cassert>
assert(boolean expression)
 If the boolean is false then the program will abort
Slide 5- 154
Assert Example
 Denominator should not be zero in Newton’s Method
Slide 5- 155
Section 5.5 Conclusion
 Can you
 Recognize common errors?
 Use the assert macro?
 Debug a program using cout statements to localize the
error?
 Debug a program using a debugger?
Slide 5- 156
Chapter 5 -- End
Slide 5- 157
Display 5.1
Slide 5- 158
Back Next
Display 5.2 (1/2)
Slide 5- 159
Back Next
Display 5.2
(2/2)
Slide 5- 160
Back Next
Display 5.3
Slide 5- 161
Back Next
Display 5.4 (1/2)
Slide 5- 162
Back Next
Display 5.4
(2/2)
Slide 5- 163
Back Next
Display 5.5
(1/2)
Slide 5- 164
Back Next
Display 5.5
(2/2)
Slide 5- 165
Back Next
Display 5.6
Slide 5- 166
Back Next
Display 5.7
Slide 5- 167
Back Next
Display 5.8 (1/2)
Slide 5- 168
Next
Back
Display 5.8
(2/2)
Slide 5- 169
Back Next
Display 5.9 (1/3)
Slide 5- 170
Back Next
Display 5.9 (2/3)
Slide 5- 171
Back Next
Display 5.9
(3/3)
Slide 5- 172
Back Next
Display 5.10 (1/2)
Slide 5- 173
Next
Back
Display 5.10
(2/2)
Slide 5- 174
Back Next
Display 5.11 (1/2)
Slide 5- 175
Back Next
Display 5.11 (2/2)
Slide 5- 176
Back Next
Display 5.12
Slide 5- 177
Back Next
Display 5.13 (1 of 2)
Slide 5- 178
Back Next
Display 5.13 (2 of 2)
Slide 5- 179
Back Next

More Related Content

PPT
Savitch ch 06
PPT
Savitch Ch 06
PPT
Savitch Ch 06
PPTX
Input output files in java
PDF
Data file handling
PPTX
chapter 2(IO and stream)/chapter 2, IO and stream
PPT
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
PPTX
Introduction to files management systems
Savitch ch 06
Savitch Ch 06
Savitch Ch 06
Input output files in java
Data file handling
chapter 2(IO and stream)/chapter 2, IO and stream
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
Introduction to files management systems

Similar to I/O Streams as an Introduction to Objects and Classesppt (20)

PDF
chapter-12-data-file-handling.pdf
PPTX
File Management and manipulation in C++ Programming
PPTX
Basics of file handling
PPTX
basics of file handling
PDF
Files in C++.pdf is the notes of cpp for reference
PPT
7 Data File Handling
PPTX
Stream classes in C++
PPTX
File Handling.pptx
PDF
Master of computer application python programming unit 3.pdf
PPT
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
PPT
Chapter 11
DOCX
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PDF
Input File dalam C++
PPT
file_handling_in_c.ppt......................................
PPT
file_handling_in_c.pptbbbbbbbbbbbbbbbbbbbbb
PDF
File Handling in Java.pdf
PDF
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
PDF
File Handling.pdffile handling ppt final
PPTX
Files that are designed to be read by human beings
chapter-12-data-file-handling.pdf
File Management and manipulation in C++ Programming
Basics of file handling
basics of file handling
Files in C++.pdf is the notes of cpp for reference
7 Data File Handling
Stream classes in C++
File Handling.pptx
Master of computer application python programming unit 3.pdf
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
Chapter 11
PAGE 1Input output for a file tutorialStreams and File IOI.docx
Input File dalam C++
file_handling_in_c.ppt......................................
file_handling_in_c.pptbbbbbbbbbbbbbbbbbbbbb
File Handling in Java.pdf
11_Str11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.11_Streams.eams.pdf
File Handling.pdffile handling ppt final
Files that are designed to be read by human beings
Ad

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
Presentation on HIE in infants and its manifestations
PDF
Complications of Minimal Access Surgery at WLH
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
202450812 BayCHI UCSC-SV 20250812 v17.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
VCE English Exam - Section C Student Revision Booklet
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
Presentation on HIE in infants and its manifestations
Complications of Minimal Access Surgery at WLH
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Ad

I/O Streams as an Introduction to Objects and Classesppt

  • 1. Chapter 6 I/O Streams as an Introduction to Objects and Classes
  • 2. Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6- 2
  • 4. I/O Streams  I/O refers to program input and output  Input is delivered to your program via a stream object  Input can be from  The keyboard  A file  Output is delivered to the output device via a stream object  Output can be to  The screen  A file Slide 6- 4
  • 5. Objects  Objects are special variables that  Have their own special-purpose functions  Set C++ apart from earlier programming languages Slide 6- 5
  • 6. Streams and Basic File I/O  Files for I/O are the same type of files used to store programs  A stream is a flow of data.  Input stream: Data flow is into the program  If input stream flows from keyboard, the program will accept data from the keyboard  If input stream flows from a file, the program will accept data from the file  Output stream: Data flow is out of the program  Can go to the screen  Can go to a file Slide 6- 6
  • 7. cin And cout Streams  cin  Input stream connected to the keyboard  cout  Output stream connected to the screen  cin and cout defined in the iostream library  Use include directive: #include <iostream>  You can declare your own streams to use with files. Slide 6- 7
  • 8. Why Use Files?  The keyboard input and screen output we have used so far deal with temporary data.  Files allow you to store data permanently!  Data output to a file lasts after the program ends  An input file can be used over and over  No typing of data again and again for testing  Create a data file or read an output file at your convenience  Files allow you to deal with larger data sets Slide 6- 8
  • 9. File I/O  Reading from a file  Taking input from a file  Done from beginning to the end (for now)  Just as done from the keyboard  Writing to a file  Sending output to a file  Done from beginning to end (for now)  Just as done to the screen Slide 6- 9
  • 10. Stream Variables  Like other variables, a stream variable…  Must be declared before it can be used  Must be initialized before it contains valid data  Initializing a stream means connecting it to a file  The value of the stream variable can be thought of as the file it is connected to  Can have its value changed  Changing a stream value means disconnecting from one file and connecting to another Slide 6- 10
  • 11. Streams and Assignment  A stream is a special kind of variable called an object  Objects can use special functions to complete tasks  Streams use special functions instead of the assignment operator to change values Slide 6- 11
  • 12. Declaring An Input-file Stream Variable  Input-file streams are of type ifstream  Type ifstream is defined in the fstream library  You must use the include and using directives #include <fstream> using namespace std;  Declare an input-file stream variable using ifstream in_stream; Slide 6- 12
  • 13. Declaring An Output-file Stream Variable  Ouput-file streams of are type ofstream  Type ofstream is defined in the fstream library  You must use these include and using directives #include <fstream> using namespace std;  Declare an output-file stream variable using ofstream out_stream; Slide 6- 13
  • 14. Connecting To A File  Once a stream variable is declared, connect it to a file  Connecting a stream to a file is opening the file  Use the open function of the stream object in_stream.open("infile.dat"); Slide 6- 14 Dot File name on the disk Double quotes
  • 15. Using The Input Stream  Once connected to a file, the input-stream variable can be used to produce input just as you would use cin with the extraction operator  Example: int one_number, another_number; in_stream >> one_number >> another_number; Slide 6- 15
  • 16. Using The Output Stream  An output-stream works similarly to the input-stream  ofstream out_stream; out_stream.open("outfile.dat"); out_stream << "one number = " << one_number << "another number = " << another_number;  After the file (i.e., "outfile.dat") is open, we should use the stream name (e.g., out_stream) as the name of the file. Slide 6- 16
  • 17. Closing a File  After using a file, it is good programming practice to close the file  This disconnects the stream from the file  Close files to reduce the chance of a file being corrupted if the program terminates abnormally  The system will automatically close files if you forget as long as your program ends normally Slide 6- 17
  • 18. Closing a File  Do you need to close the file? NO  Should you close the file? Depends.  Do you care about the possible error conditions that could occur if the file fails to close correctly? Remember that close calls setstate(failbit) if it fails. The destructor will call close() for you automatically but will not leave you a way of testing the failbit as the object no longer exists. Slide 1- 18
  • 20. Objects  An object is a variable that has functions and data associated with it  in_stream and out_stream each have a function named open associated with them  in_stream and out_stream use different versions of a function named open  One version of open is for input files  A different version of open is for output files Slide 6- 20
  • 21. Member Functions  A member function is a function associated with an object  The open function is a member function of in_stream in the previous examples  A different open function is a member function of out_stream in the previous examples Slide 6- 21
  • 22. Objects and Member Function Names  Objects of different types have different member functions  Some of these member functions might have the same name  Different objects of the same type have the same member functions Slide 6- 22
  • 23. Classes  A type whose variables are objects, is called a class  ifstream is the type of the in_stream variable (object)  ifstream is a class  The class of an object determines its member functions  Example: ifstream in_stream1, in_stream2;  in_stream1.open and in_stream2.open are the same function but might have different arguments Slide 6- 23
  • 24. Class Member Functions  Member functions of an object are the member functions of its class  The class determines the member functions of the object  The class ifstream has an open function  Every variable (object) declared of type ifstream has that open function Slide 6- 24
  • 25. Calling a Member Function  Calling a member function requires specifying the object containing the function  The calling object is separated from the member function by the dot operator  Example: in_stream.open("infile.dat"); Slide 6- 25 Calling object Dot operator Member function
  • 26. Member Function Calling Syntax  Syntax for calling a member function: Calling_object.Member_Function_Name(Argument_list); Slide 6- 26
  • 27. Errors On Opening Files  Opening a file could fail for several reasons  Common reasons for open to fail include  The file might not exist  The name might be typed incorrectly  May be no error message if the call to open fails  Program execution continues! Slide 6- 27
  • 28. Catching Stream Errors  Member function fail, can be used to test the success of a stream operation  fail returns a boolean type (true or false)  fail returns true if the stream operation failed Slide 6- 28
  • 29. Halting Execution  When a stream open function fails, it is generally best to stop the program  The function exit, used to terminate a program  exit causes program to end immediately  by convention, 1 is used for a call to exit that is caused by an error, and 0 is used otherwise  exit is NOT a member function  exit requires the include and using directives #include <cstdlib> using namespace std; Slide 6- 29
  • 30. Using fail and exit  Immediately following the call to open, check that the operation was successful: in_stream.open("stuff.dat"); if( in_stream.fail( ) ) { cout << "Input file opening failed.n"; exit(1) ; } Slide 6- 30 Display 6.2
  • 32. Techniques for File I/O  When reading input from a file…  Do not include prompts or echo the input  The lines cout << "Enter the number: "; cin >> the_number; cout << "The number you entered is " << the_number; become just one line in_file >> the_number;  The input file must contain exactly the data expected Slide 6- 32
  • 33. Appending Data (optional)  Output examples so far create new files  If the output file already contains data, that data is lost  To append new output to the end an existing file  use the constant ios::app defined in the iostream library: outStream.open("important.txt", ios::app);  If the file does not exist, a new file will be created Slide 6- 33 Display 6.3
  • 35. File Names as Input (optional)  Program users can enter the name of a file to use for input or for output  Program must use a variable that can hold multiple characters  A sequence of characters is called a string  Declaring a variable to hold a string of characters: char file_name[16];  file_name is the name of a variable  Brackets enclose the maximum number of characters + 1  The variable file_name contains up to 15 characters Slide 6- 35
  • 36. Using A Character String  char file_name[16]; cout << "Enter the file_name "; cin >> file_name; ifstream in_stream; in_stream.open(file_name); if (in_stream.fail( ) ) { cout << "Input file opening failed.n"; exit(1); } Slide 6- 36 Display 6.4 (1) Display 6.4 (2)
  • 39. Section 6.1 Conclusion  Can you  write a program that uses a stream called fin which will be connected to an input file and a stream called fout which will be connected to an output file? How do you declare fin and fout? What include directive, if any, do you need to place in your program file?  write a program to take its input from the file stuff1.dat and send its output to the file stuff2.dat. What statements do you need to place in your program in order to connect the stream fin to the file stuff1.dat and to connect the stream fout to the file stuff2.dat? Be sure to include checks to make sure that the openings were successful. Slide 6- 39
  • 41. The End of The File  Input files used by a program may vary in length  Programs may not be able to assume the number of items in the file  A way to know the end of the file is reached:  The boolean expression (in_stream >> next)  Reads a value from in_stream and stores it in next  True if a value can be read and stored in next  False if there is not a value to be read (the end of the file) Slide 6- 41
  • 42. Tools for Stream I/O  To control the format of the program's output  We use commands that determine such details as:  The spaces between items  The number of digits after a decimal point  The numeric style: scientific notation for fixed point  Showing digits after a decimal point even if they are zeroes  Showing plus signs in front of positive numbers  Left or right justifying numbers in a given space Slide 6- 42
  • 43. Formatting Output to Files  Format output to the screen with: cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);  Format output to a file using the out-file stream named out_stream with: out_stream.setf(ios::fixed); out_stream.setf(ios::showpoint); out_stream.precision(2); Slide 6- 43
  • 44. out_stream.precision(2);  precision is a member function of output streams  After out_stream.precision(2); Output of numbers with decimal points…  will show a total of 2 significant digits 23. 2.2e7 2.2 6.9e-1 0.00069 OR  will show 2 digits after the decimal point 23.56 2.26e7 2.21 0.69 0.69e-4  Calls to precision apply only to the stream named in the call Slide 6- 44
  • 45. setf(ios::fixed);  setf is a member function of output streams  setf is an abbreviation for set flags  A flag is an instruction to do one of two options  ios::fixed is a flag  After out_stream.setf(ios::fixed); All further output of floating point numbers…  Will be written in fixed-point notation, the way we normally expect to see numbers  Calls to setf apply only to the stream named in the call Slide 6- 45
  • 46. setf(ios::showpoint);  After out_stream.setf(ios::showpoint); Output of floating point numbers…  Will show the decimal point even if all digits after the decimal point are zeroes Slide 6- 46 Display 6.5
  • 47. Creating Space in Output  The width function specifies the number of spaces for the next item  Applies only to the next item of output  Example: To print the digit 7 in four spaces use out_stream.width(4); out_stream << 7 << endl;  Three of the spaces will be blank Slide 6- 47 7 7 (ios::right) (ios::left)
  • 48. Not Enough Width?  What if the argument for width is too small?  Such as specifying cout.width(3); when the value to print is 3456.45  The entire item is always output  If too few spaces are specified, as many more spaces as needed are used Slide 6- 48
  • 49. Unsetting Flags  Any flag that is set, may be unset  Use the unsetf function  Example: cout.unsetf(ios::showpos); causes the program to stop printing plus signs on positive numbers Slide 6- 49
  • 50. Manipulators  A manipulator is a function called in a nontraditional way  Manipulators in turn call member functions  Manipulators may or may not have arguments  Used after the insertion operator (<<) as if the manipulator function call is an output item Slide 6- 50
  • 51. The setw Manipulator  setw does the same task as the member function width  setw calls the width function to set spaces for output  Example: cout << "Start" << setw(4) << 10 << setw(4) << setw(6) << 30; produces: Start 10 20 30 Slide 6- 51 Two Spaces Four Spaces
  • 52. The setprecision Manipulator  setprecision does the same task as the member function precision  Example: cout.setf(ios::fixed); cout.setf(ios::showpoint); cout << "$" << setprecision(2) << 10.3 << endl << "$" << 20.5 << endl; produces: $10.30 $20.50  setprecision setting stays in effect until changed Slide 6- 52
  • 53. Manipulator Definitions  The manipulators setw and setprecision are defined in the iomanip library  To use these manipulators, add these lines #include <iomanip> using namespace std; Slide 6- 53
  • 54. Stream Names as Arguments  Streams can be arguments to a function  The function's formal parameter for the stream must be call-by-reference  Example: void make_neat(ifstream& messy_file, ofstream& neat_file); Slide 6- 54
  • 55. The End of The File  Input files used by a program may vary in length  Programs may not be able to assume the number of items in the file  A way to know the end of the file is reached:  The boolean expression (in_stream >> next)  Reads a value from in_stream and stores it in next  True if a value can be read and stored in next  False if there is not a value to be read (the end of the file) Slide 6- 55
  • 56. End of File Example  To calculate the average of the numbers in a file  double next, sum = 0; int count = 0; while(in_stream >> next) { sum = sum + next; count++; } double average = sum / count; Slide 6- 56
  • 57. Stream Arguments and Namespaces  Using directives have been local to function definitions in the examples so far  When parameter type names are in a namespace  A using directive must be outside the function so C++ will understand the parameter type names such as ifstream  Easy solution is to place the using directive at the beginning of the file  Many experts do not approve as this does not allow using multiple namespaces with names in common Slide 6- 57
  • 58. Program Example  The program in Display 6.6…  Takes input from rawdata.dat  Writes output to the screen and to neat.dat  Formatting instructions are used to create a neater layout  Numbers are written one per line in a field width of 12  Each number is written with 5 digits after the decimal point  Each number is written with a plus or minus sign  Uses function make_neat that has formal parameters for the input-file stream and output-file stream Slide 6- 58 Display 6.6 (1) Display 6.6 (2) Display 6.6 (3)
  • 59. Section 6.2 Conclusion  Can you  Show the output produced when the following line is executed? cout << "*" << setw(3) << 12345 << "*" endl;  Describe the effect of each of these flags? Ios::fixed ios::scientific ios::showpoint ios::right ios::right ios::showpos Slide 6- 59
  • 61. Character I/O  All data is input and output as characters  Output of the number 10 is two characters '1' and '0'  Input of the number 10 is also done as '1' and '0'  Interpretation of 10 as the number 10 or as characters depends on the program  Conversion between characters and numbers is usually automatic Slide 6- 61
  • 62. Low Level Character I/O  Low level C++ functions for character I/O  Perform character input and output  Do not perform automatic conversions  Allow you to do input and output in anyway you can devise Slide 6- 62
  • 63. Member Function get  Function get  Member function of every input stream  Reads one character from an input stream  Stores the character read in a variable of type char, the single argument the function takes  Does not use the extraction operator (>>) which performs some automatic work  Does not skip blanks Slide 6- 63
  • 64. Using get  These lines use get to read a character and store it in the variable next_symbol char next_symbol; cin.get(next_symbol);  Any character will be read with these statements  Blank spaces too!  'n' too! (The newline character) Slide 6- 64
  • 65. get Syntax  input_stream.get(char_variable);  Examples: char next_symbol; cin.get(next_symbol); ifstream in_stream; in_stream.open("infile.dat"); in_stream.get(next_symbol); Slide 6- 65
  • 66. More About get  Given this code: char c1, c2, c3; cin.get(c1); cin.get(c2); cin.get(c3); and this input: AB CD  c1 = 'A' c2 = 'B' c3 = 'n'  cin >> c1 >> c2 >> c3; would place 'C' in c3 (the ">>" operator skips the newline character) Slide 6- 66
  • 67. The End of The Line  To read and echo a line of input  Look for 'n' at the end of the input line: cout<<"Enter a line of input and I will " << "echo it.n"; char symbol; do { cin.get(symbol); cout << symbol; } while (symbol != 'n');  All characters, including 'n' will be output Slide 6- 67
  • 68. 'n ' vs "n "  'n'  A value of type char  Can be stored in a variable of type char  "n"  A string containing only one character  Cannot be stored in a variable of type char  In a cout-statement they produce the same result Slide 6- 68
  • 69. Member Function put  Function put  Member function of every output stream  Requires one argument of type char  Places its argument of type char in the output stream  Does not do allow you to do more than previous output with the insertion operator and cout Slide 6- 69
  • 70. put Syntax  Output_stream.put(Char_expression);  Examples: cout.put(next_symbol); cout.put('a'); ofstream out_stream; out_stream.open("outfile.dat"); out_stream.put('Z'); Slide 6- 70
  • 71. Member Function putback  The putback member function places a character in the input stream  putback is a member function of every input stream  Useful when input continues until a specific character is read, but you do not want to process the character  Places its argument of type char in the input stream  Character placed in the stream does not have to be a character read from the stream Slide 6- 71
  • 72. putback Example  The following code reads up to the first blank in the input stream fin, and writes the characters to the file connected to the output stream fout  fin.get(next); while (next != ' ') { fout.put(next); fin.get(next); } fin.putback(next);  The blank space read to end the loop is put back into the input stream Slide 6- 72
  • 73. Program Example Checking Input  Incorrect input can produce worthless output  Use input functions that allow the user to re-enter input until it is correct, such as  Echoing the input and asking the user if it is correct  If the input is not correct, allow the user to enter the data again Slide 6- 73
  • 74. Checking Input: get_int  The get_int function seen in Display 6.7 obtains an integer value from the user  get_int prompts the user, reads the input, and displays the input  After displaying the input, get_int asks the user to confirm the number and reads the user's response using a variable of type character  The process is repeated until the user indicates with a 'Y' or 'y' that the number entered is correct Slide 6- 74
  • 75. Checking Input: new_line  The new_line function seen in Display 6.7 is called by the get_int function  new_line reads all the characters remaining in the input line but does nothing with them, essentially discarding them  new_line is used to discard what follows the first character of the the user's response to get_line's "Is that correct? (yes/no)"  The newline character is discarded as well Slide 6- 75 Display 6.7 (1) Display 6.7 (2)
  • 76. Slide 10- 76 Inheritance and Output  ostream is the class of all output streams  cout is of type ostream  ofstream is the class of output-file streams  The ofstream class is a child class of ostream  More about this in Chapter 10  This function can be called with ostream or ofstream arguments void say_hello(ostream& any_out_stream) { any_out_stream << "Hello"; }
  • 77. Slide 10- 77 Program Example: Another new_line Function  The new_line function from Display 6.7 only works with cin  This version works for any input stream void new_line(istream& in_stream) { char symbol; do { in_stream.get(symbol); } while (symbol != 'n'); }
  • 78. Slide 10- 78 Program Example: Calling new_line  The new version of new_line can be called with cin as the argument new_line(cin);  If the original version of new_line is kept in the program, this call produces the same result new_line( );  New_line can also be called with an input-file stream as an argument new_line(fin);
  • 79. Slide 10- 79 Default Arguments  It is not necessary to have two versions of the new_line function  A default value can be specified in the parameter list  The default value is selected if no argument is available for the parameter  The new_line header can be written as new_line (istream & in_stream = cin)  If new_line is called without an argument, cin is used
  • 80. Slide 10- 80 Multiple Default Arguments  When some formal parameters have default values and others do not  All formal parameters with default values must be at the end of the parameter list  Arguments are applied to the all formal parameters in order just as we have seen before  The function call must provide at least as many arguments as there are parameters without default values
  • 81. Slide 10- 81 Default Argument Example  void default_args(int arg1, int arg2 = -3) { cout << arg1 << ' ' << arg2 << endl; }  default_args can be called with one or two parameters  default_args(5); //output is 5 -3  default_args(5, 6); //output is 5 6
  • 82. Checking Input: Check for Yes or No?  get_int continues to ask for a number until the user responds 'Y' or 'y' using the do-while loop do { // the loop body } while ((ans !='Y') &&(ans != 'y') )  Why not use ((ans =='N') | | (ans == 'n') )?  User must enter a correct response to continue a loop tested with ((ans =='N') | | (ans == 'n') )  What if they mis-typed "Bo" instead of "No"?  User must enter a correct response to end the loop tested with ((ans !='Y') &&(ans != 'y') ) Slide 6- 82
  • 83. Mixing cin >> and cin.get  Be sure to deal with the 'n' that ends each input line if using cin >> and cin.get  "cin >>" reads up to the 'n'  The 'n' remains in the input stream  Using cin.get next will read the 'n'  The new_line function from Display 6.7 can be used to clear the 'n' Slide 6- 83
  • 84. 'n' Example  The Code: cout << "Enter a number:n"; int number; cin >> number; cout << "Now enter a letter:n"; char symbol; cin.get(symbol); Slide 6- 84 The Dialogue: Enter a number: 21 Now enter a letter: A The Result: number = 21 symbol = 'n'
  • 85. A Fix To Remove 'n'  cout << "Enter a number:n"; int number; cin >> number; cout << "Now enter a letter:n"; char symbol; cin >>symbol; Slide 6- 85
  • 86. Another 'n' Fix  cout << "Enter a number:n"; int number; cin >> number; new_line( ); // From Display 6.7 cout << "Now enter a letter:n"; char symbol; cin.get(symbol); Slide 6- 86
  • 87. Detecting the End of a File  Member function eof detects the end of a file  Member function of every input-file stream  eof stands for end of file  eof returns a boolean value  True when the end of the file has been reached  False when there is more data to read  Normally used to determine when we are NOT at the end of the file  Example: if ( ! in_stream.eof( ) ) Slide 6- 87
  • 88. Using eof  This loop reads each character, and writes it to the screen  in_stream.get(next); while (! in_stream.eof( ) ) { cout << next; in_stream.get(next); }  ( ! In_stream.eof( ) ) becomes false when the program reads past the last character in the file Slide 6- 88
  • 89. The End Of File Character  End of a file is indicated by a special character  in_stream.eof( ) is still true after the last character of data is read  in_stream.eof( ) becomes false when the special end of file character is read Slide 6- 89
  • 90. How To Test End of File  We have seen two methods  while ( in_stream >> next)  while ( ! in_stream.eof( ) )  Which should be used?  In general, use eof when input is treated as text and using a member function get to read input  In general, use the extraction operator method when processing numeric data Slide 6- 90
  • 91. Program Example: Editing a Text File  The program of Display 6.8…  Reads every character of file cad.dat and copies it to file cplusad.dat except that every 'C' is changed to "C++" in cplusad.dat  Preserves line breaks in cad.dat  get is used for input as the extraction operator would skip line breaks  get is used to preserve spaces as well  Uses eof to test for end of file Slide 6- 91 Display 6.8 (1) Display 6.8 (2)
  • 92. Character Functions  Several predefined functions exist to facilitate working with characters  The cctype library is required  #include <cctype> using namespace std; Slide 6- 92
  • 93. The toupper Function  toupper returns the argument's upper case character  toupper('a') returns 'A'  toupper('A') return 'A' Slide 6- 93
  • 94. toupper Returns An int  Characters are actually stored as an integer assigned to the character  toupper and tolower actually return the integer representing the character  cout << toupper('a'); //prints the integer for 'A'  char c = toupper('a'); //places the integer for 'A' in c cout << c; //prints 'A'  cout << static_cast<char>(toupper('a')); //works too Slide 6- 94
  • 95. The isspace Function  isspace returns true if the argument is whitespace  Whitespace is spaces, tabs, and newlines  isspace(' ') returns true  Example: if (isspace(next) ) cout << '-'; else cout << next;  Prints a '-' if next contains a space, tab, or newline character  See more character functions in Slide 6- 95 Display 6.9 (1) Display 6.9 (2)
  • 96. Section 6.3 Conclusion  Can you  Write code that will read a line of text and echo the line with all the uppercase letters deleted?  Describe two methods to detect the end of an input file:  Describe whitespace? Slide 6- 96
  • 97. Chapter 6 -- End Slide 6- 97
  • 98. Display 6.1 Slide 6- 98 Back Next
  • 99. Display 6.2 Slide 6- 99 Back Next
  • 100. Display 6.3 Slide 6- 100 Back Next
  • 101. Display 6.4 (1/2) Slide 6- 101 Back Next
  • 102. Display 6.4 (2/2) Slide 6- 102 Back Next
  • 103. Display 6.5 Slide 6- 103 Back Next
  • 104. Display 6.6 (1/3) Slide 6- 104 Back Next
  • 105. Display 6.6 (2/3) Slide 6- 105 Back Next
  • 106. Display 6.6 (3/3) Slide 6- 106 Back Next
  • 107. Display 6.7 (1/2) Slide 6- 107 Back Next
  • 108. Display 6.7 (2/2) Slide 6- 108 Back Next
  • 109. Display 6.8 (1/2) Slide 6- 109 Next Back
  • 110. Display 6.8 (2/2) Slide 6- 110 Back Next
  • 111. Display 6.9 (1/2) Slide 6- 111 Back Next
  • 112. Display 6.9 (2/2) Slide 6- 112 Back Next
  • 113. Call-by-Reference Parameters  Call-by-value is not adequate when we need a sub-task to obtain input values  Call-by-value means that the formal parameters receive the values of the arguments  To obtain input values, we need to change the variables that are arguments to the function  Recall that we have changed the values of formal parameters in a function body, but we have not changed the arguments found in the function call  Call-by-reference parameters allow us to change the variable used in the function call  Arguments for call-by-reference parameters must be variables, not numbers Slide 5- 113
  • 114. Call-by-Reference Example  void get_input(double& f_variable) { using namespace std; cout << “ Convert a Fahrenheit temperature” << “ to Celsius.n” << “ Enter a temperature in Fahrenheit: “; cin >> f_variable; }  ‘&’ symbol (ampersand) identifies f_variable as a call-by-reference parameter  Used in both declaration and definition! Slide 5- 114 Display 5.4
  • 115. Call-By-Reference Details  Call-by-reference works almost as if the argument variable is substituted for the formal parameter, not the argument’s value  In reality, the memory location of the argument variable is given to the formal parameter  Whatever is done to a formal parameter in the function body, is actually done to the value at the memory location of the argument variable Slide 5- 115 Display 5.5
  • 117. Using Procedural Abstraction  Functions should be designed so they can be used as black boxes  To use a function, the declaration and comment should be sufficient  Programmer should not need to know the details of the function to use it Slide 5- 117
  • 118. Functions Calling Functions  A function body may contain a call to another function  The called function declaration must still appear before it is called  Functions cannot be defined in the body of another function  Example: void order(int& n1, int& n2) { if (n1 > n2) swap_values(n1, n2); }  swap_values called if n1 and n2 are not in ascending order  After the call to order, n1 and n2 are in ascending order Slide 5- 118 Display 5.8
  • 121. Pre and Postconditions  Precondition  States what is assumed to be true when the function is called  Function should not be used unless the precondition holds  Postcondition  Describes the effect of the function call  Tells what will be true after the function is executed (when the precondition holds)  If the function returns a value, that value is described  Changes to call-by-reference parameters are described Slide 5- 121
  • 122. swap_values revisited  Using preconditions and postconditions the declaration of swap_values becomes: void swap_values(int& n1, int& n2); //Precondition: variable1 and variable 2 have // been given values // Postcondition: The values of variable1 and // variable2 have been // interchanged Slide 5- 122
  • 123. Function celsius  Preconditions and postconditions make the declaration for celsius: double celsius(double farenheit); //Precondition: fahrenheit is a temperature // expressed in degrees Fahrenheit //Postcondition: Returns the equivalent temperature // expressed in degrees Celsius Slide 5- 123
  • 124. Why use preconditions and postconditions?  Preconditions and postconditions  should be the first step in designing a function  specify what a function should do  Always specify what a function should do before designing how the function will do it  Minimize design errors  Minimize time wasted writing code that doesn’t match the task at hand Slide 5- 124
  • 125. Case Study Supermarket Pricing  Problem definition  Determine retail price of an item given suitable input  5% markup if item should sell in a week  10% markup if item expected to take more than a week  5% for up to 7 days, changes to 10% at 8 days  Input  The wholesale price and the estimate of days until item sells  Output  The retail price of the item Slide 5- 125
  • 126. Supermarket Pricing: Problem Analysis  Three main subtasks  Input the data  Compute the retail price of the item  Output the results  Each task can be implemented with a function  Notice the use of call-by-value and call-by-reference parameters in the following function declarations Slide 5- 126
  • 127. Supermarket Pricing: Function get_input  void get_input(double& cost, int& turnover); //Precondition: User is ready to enter values // correctly. //Postcondition: The value of cost has been set to // the wholesale cost of one item. // The value of turnover has been // set to the expected number of // days until the item is sold. Slide 5- 127
  • 128. Supermarket Pricing: Function price  double price(double cost, int turnover); //Precondition: cost is the wholesale cost of one // item. turnover is the expected // number of days until the item is // sold. //Postcondition: returns the retail price of the item Slide 5- 128
  • 129. Supermarket Pricing: Function give_output  void give_output(double cost, int turnover, double price); //Precondition: cost is the wholesale cost of one item; // turnover is the expected time until sale // of the item; price is the retail price of // the item. //Postcondition: The values of cost, turnover, and price // been written to the screen. Slide 5- 129
  • 130. Supermarket Pricing: The main function  With the functions declared, we can write the main function: int main() { double wholesale_cost, retail_price; int shelf_time; get_input(wholesale_cost, shelf_time); retail_price = price(wholesale_cost, shelf_time); give_output(wholesale_cost, shelf_time, retail_price); return 0; } Slide 5- 130
  • 131. Supermarket Pricing: Algorithm Design -- price  Implementations of get_input and give_output are straightforward, so we concentrate on the price function  pseudocode for the price function  If turnover <= 7 days then return (cost + 5% of cost); else return (cost + 10% of cost); Slide 5- 131
  • 132. Supermarket Pricing: Constants for The price Function  The numeric values in the pseudocode will be represented by constants  Const double LOW_MARKUP = 0.05; // 5%  Const double HIGH_MARKUP = 0.10; // 10%  Const int THRESHOLD = 7; // At 8 days use //HIGH_MARKUP Slide 5- 132
  • 133. Supermarket Pricing: Coding The price Function  The body of the price function  { if (turnover <= THRESHOLD) return ( cost + (LOW_MARKUP * cost) ) ; else return ( cost + ( HIGH_MARKUP * cost) ) ; }  See the complete program in Slide 5- 133 Display 5.9
  • 137. Supermarket Pricing : Program Testing  Testing strategies  Use data that tests both the high and low markup cases  Test boundary conditions, where the program is expected to change behavior or make a choice  In function price, 7 days is a boundary condition  Test for exactly 7 days as well as one day more and one day less Slide 5- 137
  • 138. Section 5.3 Conclusion  Can you  Define a function in the body of another function?  Call one function from the body of another function?  Give preconditions and postconditions for the predefined function sqrt? Slide 5- 138
  • 140. Test Drivers and Stubs. Slide 1- 140  How can you test a function that depends on other functions?  Test driver: set up a dummy environment that allows you to call a function and display its return values. A driver program should be as simple as possible.  Stub: If the function A you are testing calls another function B, then use a simplified version of function B, called a stub. A stub returns a value that is sufficient for testing. The stub does not need to perform the real calculation.
  • 141. Testing and Debugging Functions  Each function should be tested as a separate unit  Testing individual functions facilitates finding mistakes  Driver programs allow testing of individual functions  Once a function is tested, it can be used in the driver program to test other functions  Function get_input is tested in the driver program of and Slide 5- 141 Display 5.10 (1) Display 5.10 (2)
  • 144. Stubs  When a function being tested calls other functions that are not yet tested, use a stub  A stub is a simplified version of a function  Stubs are usually provide values for testing rather than perform the intended calculation  Stubs should be so simple that you have confidence they will perform correctly  Function price is used as a stub to test the rest of the supermarket pricing program in and Slide 5- 144 Display 5.11 (1) Display 5.11 (2)
  • 147. Rule for Testing Functions  Fundamental Rule for Testing Functions  Test every function in a program in which every other function in that program has already been fully tested and debugged. Slide 5- 147
  • 148. Section 5.4 Conclusion  Can you  Describe the fundamental rule for testing functions?  Describe a driver program?  Write a driver program to test a function?  Describe and use a stub?  Write a stub? Slide 5- 148
  • 150. General Debugging Techniques  Stubs, drivers, test cases as described in the previous section  Keep an open mind  Don’t assume the bug is in a particular location  Don’t randomly change code without understanding what you are doing until the program works  This strategy may work for the first few small programs you write but is doomed to failure for any programs of moderate complexity  Show the program to someone else Slide 5- 150
  • 151. General Debugging Techniques  Check for common errors, e.g.  Local vs. Reference Parameter  = instead of ==  Localize the error  This temperature conversion program has a bug  Narrow down bug using cout statements Slide 1- 151 Display 5.12 Display 5.13
  • 153. Display 5.13 (1 of 2) Slide 5- 153
  • 154. General Debugging Techniques  Use a debugger  Tool typically integrated with a development environment that allows you to stop and step through a program line-by-line while inspecting variables  The assert macro  Can be used to test pre or post conditions #include <cassert> assert(boolean expression)  If the boolean is false then the program will abort Slide 5- 154
  • 155. Assert Example  Denominator should not be zero in Newton’s Method Slide 5- 155
  • 156. Section 5.5 Conclusion  Can you  Recognize common errors?  Use the assert macro?  Debug a program using cout statements to localize the error?  Debug a program using a debugger? Slide 5- 156
  • 157. Chapter 5 -- End Slide 5- 157
  • 158. Display 5.1 Slide 5- 158 Back Next
  • 159. Display 5.2 (1/2) Slide 5- 159 Back Next
  • 160. Display 5.2 (2/2) Slide 5- 160 Back Next
  • 161. Display 5.3 Slide 5- 161 Back Next
  • 162. Display 5.4 (1/2) Slide 5- 162 Back Next
  • 163. Display 5.4 (2/2) Slide 5- 163 Back Next
  • 164. Display 5.5 (1/2) Slide 5- 164 Back Next
  • 165. Display 5.5 (2/2) Slide 5- 165 Back Next
  • 166. Display 5.6 Slide 5- 166 Back Next
  • 167. Display 5.7 Slide 5- 167 Back Next
  • 168. Display 5.8 (1/2) Slide 5- 168 Next Back
  • 169. Display 5.8 (2/2) Slide 5- 169 Back Next
  • 170. Display 5.9 (1/3) Slide 5- 170 Back Next
  • 171. Display 5.9 (2/3) Slide 5- 171 Back Next
  • 172. Display 5.9 (3/3) Slide 5- 172 Back Next
  • 173. Display 5.10 (1/2) Slide 5- 173 Next Back
  • 174. Display 5.10 (2/2) Slide 5- 174 Back Next
  • 175. Display 5.11 (1/2) Slide 5- 175 Back Next
  • 176. Display 5.11 (2/2) Slide 5- 176 Back Next
  • 177. Display 5.12 Slide 5- 177 Back Next
  • 178. Display 5.13 (1 of 2) Slide 5- 178 Back Next
  • 179. Display 5.13 (2 of 2) Slide 5- 179 Back Next