Some standard manipulators are used in C++ (OOPs) which are stored under header file iomanip.h. Under this it has capabilities to show inter-conversions like binary, decimal, hex-decimal, set the precision for more accurate answer and various other functions like you can see in the programs.
/* Program to show use of endl function in C++ */
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
cout<<"\n Bansal B.tech Learning";
cout<<endl;
cout<<" Stairs of Bright Future...";
cout<<endl<<endl<<" Function of (endl) is making the function move to next line";
getch();
}
/* Program to show use of setw() function in C++ */
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
cout<<"\n "<<setw(20)<<"Bansal B.tech Learning"<<"\n "<<setw(19)<<"Stairs of Bright Future...";
cout<<"\n\n "<<"Function of [setw(number)] is including desired number of spaces";
getch();
}
/* Program to show use of setprecision() function in C++ */
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
int a,b;
cout<<"\n Enter any value of a and b";
cin>>a>>b;
cout<<"\n "<<setprecision(4)<<float(b)/a;
getch();
}
/* Program to convert decimal number to binary, hex-decimal and octal*/
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
int n;
cout<<"\n Enter any number";
cin>>n;
cout<<"\n Decimal value is "<<dec<<n;
cout<<"\n Octal value is "<<oct<<n;
cout<<"\n Hexa-decimal value is "<<hex<<n;
getch();
}
No comments:
Post a Comment