1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
# include<iostream>
# include<string>
# include<iomanip>
using namespace std;
string numToBinString(int);
string prettyStr(string);
void prtOneRow ( int num )
{
//The count is located in main
cout << right;
cout << setw(9) <<dec << num << setw(13) << showbase << hex << num << setw(8) << oct << num << setw(11) << numToBinString(num) << endl;
}
string numToBinString( int num )
{
string str = " ";
do
{
int digit = num%2;
num = num/2;
char ch = '0' + digit;
str = ch + str ;
}while(num != 0);
return str ;
}
string prettyStr(string fixed)
{
for(int p = 0; p <35; p++ )
{
string space = "_";
fixed = fixed.insert(4*p,space);//!!! here is Where i need help!!!
}
return fixed;
}
int scoutsNumber(int num)
{
int weridNum[]= {64, 128, 256, 512, 1021, 2048, 4096, 8192, 16384, 32768, 65536};
return weridNum[num];
}
int main()
{
int n;
cout << setfill('=') <<setw(43) << " " << endl;
cout << "12345678901234567890123456789012345678901234567890123456789" << endl;
cout << setfill(' ') << setw(9) << "decimal" << setw(13) << "hexidecimal" << setw(8) << "octal" << setw(11) << "binary" << setfill( '=' ) << endl;
for ( int i = 0; i < 34; i++ )
{
cout << setw(42) << " " << setfill(' ') << endl;
prtOneRow(i);
}
cout << setfill('~') <<setw(58) << " " << endl;
cout << setfill(' ') << setw(9) << "decimal" << setw(13) << "hexidecimal" << setw(11) << "octal" << setw(23) << "binary" << setfill( ' ' ) << endl;
cout << setfill('~') <<setw(58) << " " << setfill(' ') << endl;
for(n = 0; n < 11; n++)
{
int n0 = 0;
n0= n0 + scoutsNumber(n);
int n1,n2,n3;
n1= n0 - 1;
n2= n0;
n3= n0 + 1;
// The 3 lines of code bellow more than likely code have been place some how in a loop of ther own.
// however I could not figure out how to do this to clean this part up.
cout << setw(9) <<dec << n1 << setw(13) << showbase << hex << n1 << setw(11) << oct << n1 << setw(24) << numToBinString(n1) << endl;
cout << setw(9) <<dec << n2 << setw(13) << showbase << hex << n2 << setw(11) << oct << n2 << setw(24) << numToBinString(n2) << endl;
cout << setw(9) <<dec << n3 << setw(13) << showbase << hex << n3 << setw(11) << oct << n3 << setw(24) << numToBinString(n3) << endl;
}
cout << "HEllo"<< endl;
cout << numToBinString( 601 ) << endl;
cout << prettyStr(numToBinString(1231)) << endl;
cout << prettyStr(" Hello world") << endl;//checking how far the code as ran
|