Write a program to show use of manipulators.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
cout<<"--------- USE OF MANIPULATORS : ---------\n\n";
cout<<"Use of 'setw()' :- \nX = 234, Y = 32, Setting width = 5\n";
int x=234,y=32;
cout<<"X = "<<setw(5)<<x<<endl<<"Y = "<<setw(5)<<y<<endl;
cout<<"\nUse of 'setfill()' :- \nX = 234, Y = 32, Setting width = 5, Setfill characters : '*' and '#'\n";
cout<<"X = "<<setw(5)<<setfill('*')<<x<<endl<<"Y = "<<setw(5)<<setfill('#')<<y<<endl;
cout<<"\nUse of 'setprecision()' :-\nZ = 5.0/3.0\n";
float z = 5.0/3.0;
cout<<"Z [setprecision(2)] :\t"<<setprecision(2)<<z<<endl;
cout<<"Z [setprecision(3)] :\t"<<setprecision(3)<<z<<endl;
cout<<"Z [setprecision(4)] :\t"<<setprecision(4)<<z<<endl;
cout<<"Z [setprecision(5)] :\t"<<setprecision(5)<<z<<endl;
cout<<"\nUse of 'setbase()' :-\nD = 790\n";
int d = 790;
cout<<"Octal value of "<<d<<" is [setbase(8)] :\t"<<setbase(8)<<d<<endl;
cout<<"Decimal value of "<<d<<" is [setbase(10)] :\t"<<setbase(10)<<d<<endl;
cout<<"Hexa Decimal value of "<<d<<" is [setbase(16)] :\t"<<setbase(16)<<d<<endl<<endl;
cout<<"\nUse of 'dec','hex' and 'oct' :-\nD = 790\n";
cout<<"Octal Base of "<<d<<" (oct) is "<<oct<<d<<endl;
cout<<"Decimal Base of "<<d<<" (dec) is "<<dec<<d<<endl;
cout<<"Hexa Decimal Base of "<<d<<" (hex) is "<<hex<<d<<endl;
cout<<"\nUse of 'ends' :- \nNumber = 359\nOutput usin 'ends' : \n";
int dh = 359;
cout<<"Number = "<<dh<<ends<<endl;
cout<<"\nUse of 'ws' :-\n";
char name[50];
cout<<"Type the text line : \n";
cin>>ws>>name;
cout<<"Typed text is : "<<name<<endl;
getch();
}
OUTPUT :
No comments:
Post a Comment