Professional Documents
Culture Documents
TUT4 Iomanip
TUT4 Iomanip
TUT4 Iomanip
DO THIS
Go to textbook pg 156, do
PROGRAMMING EXAMPLE:
Movie Tickets Sale and Donation to Charity
Setprecision: This function sets the precision for decimal or float values.
setw: Setw function sets the field width or number of characters that are to be displayed before a
particular field.
Setfill: Setfill function is used to fill the stream with char type c specified as a parameter.
Given below is a detailed C++ example to demonstrate the setprecision function.
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double float_value =3.14159;
cout << setprecision(4) << float_value << '\n';
cout << setprecision(9) << float_value << '\n';
cout << fixed;
cout << setprecision(5) << float_value << '\n';
cout << setprecision(10) << float_value << '\n';
return 0;
}
OUTPUT;
The setw function is demonstrated using a C++ program.
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << "The number printed with width 10"<<endl;
cout << setw(10);
cout << 77 << endl;
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setfill ('*') << setw (10);
cout << 15 << endl;
cout << setfill ('#') << setw (5);
cout << 5 << endl;
cout << setfill ('#') << setw (5);
cout << 1 << endl;
cout << setfill ('*') << setw (10);
cout << 25 << endl;
return 0;
}
OUTPUT