Commit 3ac70b7b authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'branch5.18' into 'master'

michael.davityan:exercise_05_18

See merge request bpcarm/trainings2017!1366
parents a101d8da 6755b443
progname=exercise_05_18
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
#include <iostream>
#include <iomanip>
#include <cmath>
int
main()
{
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 << "|";
const int SYSTEM_LIMIT = 16;
for (int systemType = 2; systemType <= SYSTEM_LIMIT; systemType *= 2) {
if (4 == systemType) {
continue;
}
int denominator = SYSTEM_LIMIT / systemType;
int powerOfSystemType = std::pow(systemType, denominator + 1);
std::cout << std::setw(12);
do {
const int variableForCalculate = number / powerOfSystemType;
const char bitValue = variableForCalculate % systemType + '0';
std::cout << (bitValue < ':' ? bitValue : static_cast<char>(bitValue - 57 + 96));
powerOfSystemType /= systemType;
} while (powerOfSystemType != 0);
std::cout << "|";
}
std::cout << std::endl;
}
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