C++ stream manipulators (USE OF SETPRECISION(),CONVERSION FROM DECIMAL TO HEXA ND OCTAL DIGITS ETC)

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
int number;
cout<<"the program will tell you stream manipulators "<<endl;
cout<<endl<<"enter a number "<<endl<<"your number = ";
cin>>number;

cout<<number<<setw(2)<<"in hexadecimal = "<<hex<<number<<endl<<endl;//setw(2) used for spacing of two characters

cout<<number<<setw(2)<<"in octal = "<<oct<<number<<endl<<endl;

cout<<number<<setw(2)<<"in decimal = "<<dec<<number<<endl<<endl<<endl;
//code below this will display numbers with bases
cout<<"in order to print number with their bases "<<endl<<endl;
cout<<"number with their bases"<<endl<<endl<<showbase;

cout<<number<<"in hexadecimal = "<<hex<<number<<endl<<endl;
cout<<number<<"in octal = "<<oct<<number<<endl<<endl;
cout<<number<<"in decimal = "<<dec<<number<<endl<<endl<<endl;

//code below this demonstrates usage of precision using base function
cout<<"code below this demonstrates usage of precision using base function"<<endl;
int places;
float number1=sqrt(2.0);
for(places=1;places<=9;places++){

cout.precision(places);
cout<<"precesion of "<<places<<" = "<<number1<<endl;
}
//code below this demonstrates usage of precision using stream manipulators

     cout<<endl<<endl<<"code below this demonstrates usage of precision using base function "<<endl;
for(places=1;places<=9;places++){
cout<<"precesion of "<<places<<" = "<<setprecision(places)<<number1<<endl;
 
}
}





Previous
Next Post »

Comments:

Disqus Shortname