Page 264 - DCAP404 _Object Oriented Programming
P. 264
Unit 12: Console I/O
} Notes
cout << “Entered values: a = “ << a << “ and b = “ << b << endl;
cout << “sum(a, b) = “ << sum(a, b) << endl;
cout << “sum(a) = “ << sum(a) << endl;
return 0;
}
// Define the sum function.
float sum(float x, float y)
{
return (x + y);
}
2. This program displays use of different stream manipulators.
#include <iostream.h>
#include <iomanip.h>
int main(void)
{
int I = 100;
cout << setfile(‘.’);
cout << setiosflags(ios::left);
cout << setw(20) << “Decimal”;
cout << resetiosflags(ios::left);
cout << setw(6) << dec << I << endl;
cout << setiosflags(ios::left);
cout << setw(20) << “Hexadecimal”;
cout << resetiosflags(ios::left);
cout << setw(6) << hex << I << endl;
cout << setiosflags(ios::left);
cout << setw(6) << oct << I << endl;
}
The output of the program:
Decimal…………….100
Hexadecimal…………64
Octal………………..144
3. This program exchanges the values of two variable.
#include <iostream> // Header for stream I/O.
#include <fstream> // Header for file I/O.
#include <iomanip> // Header for I/O manipulators.
LOVELY PROFESSIONAL UNIVERSITY 257