Pages

January 30, 2013

Manipulators in C++ (OOPs)

manipulators in C++ (OOPs)


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();
      }
output of program to show use of endl function in manipulators in C++ (OOPs)

/* 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();
      }
output of program to show use of set width function in manipulators in C++ (OOPs)

/* 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();
      }
output of program to show use of set precision function in manipulators in C++ (OOPs)

/* 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();
      }
output of program to convert decimal into binary, hex-decimal and octal using manipulators in C++ (OOPs)

No comments:

Post a Comment