Commit 6755b443 authored by Michael's avatar Michael

michael.davityan:exercise_05_18v7

parent be510489
......@@ -5,12 +5,12 @@
int
main()
{
std::cout << "=====================================================================\n";
std::cout << "|------------ NUMBER SYSTEMS TABLE CONTENT... ------------|\n";
std::cout << "=====================================================================\n";
std::cout << "|" << std::setw(17) << "decimal|" << std::setw(17) << "binary|"
<< std::setw(17) << "octal|" << std::setw(17) << "hexadecimal|" << std::endl;
std::cout << "=====================================================================\n";
std::cout << "=======================================================================\n";
std::cout << "|-------------- NUMBER SYSTEMS TABLE CONTENT... ------------|\n";
std::cout << "=======================================================================\n";
std::cout << "|" << std::setw(17) << "decimal|" << std::setw(22) << "binary|"
<< std::setw(16) << "octal|" << std::setw(15) << "hexadecimal|" << std::endl;
std::cout << "=======================================================================\n";
const int DECIMAL_LIMIT = 256;
for (int number = 1; number <= DECIMAL_LIMIT; ++number) {
std::cout << "|" << std::setw(16) << number << "|";
......@@ -19,32 +19,22 @@ main()
if (4 == systemType) {
continue;
}
int denuminator = SYSTEM_LIMIT / systemType;
if (16 == systemType) {
++denuminator;
}
int powerOfSystemType = pow(systemType, denuminator + 1);
int probels = denuminator + 2;
int denominator = SYSTEM_LIMIT / systemType;
int powerOfSystemType = std::pow(systemType, denominator + 1);
std::cout << std::setw(12);
do {
const int variableForCalculate = number / powerOfSystemType;
const int bitValue = variableForCalculate % systemType;
const char bitValue = variableForCalculate % systemType + '0';
std::cout << (bitValue < ':' ? bitValue : static_cast<char>(bitValue - 57 + 96));
powerOfSystemType /= systemType;
if (bitValue < 10) {
std::cout << bitValue;
continue;
}
char afterNine = 'a';
afterNine = afterNine + (bitValue - 10);
std::cout << afterNine;
} while (powerOfSystemType != 0);
std::cout << "|";
}
std::cout << std::endl;
}
std::cout << "=====================================================================\n";
std::cout << "|----------------------- end of table... -----------------------|\n";
std::cout << "====================================================================="
std::cout << "=======================================================================\n";
std::cout << "|------------------------- end of table... -----------------------|\n";
std::cout << "======================================================================="
<< std::endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment