Commit e99d71d0 by Michael

### michael.davityan:exercise_04_34v7

parent 8491c6a0
Pipeline #27125322 passed with stage
in 3 minutes and 34 seconds
 progname=exercise_04_34 CC=g++ CFLAGS=-Wall -Wextra -Werror -g3 all: test1 test2 test3 test4 test5 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
 This is the (a) point of lesson.... Encryption of your number is: 189 ------------------------------------------------------------------------------------------------------ This is the (b) point of lesson.... encrypted initial number is: 1234
 1234 189
 This is the (a) point of lesson.... Error 1: the number must be a four-digit and positive.
 100
 This is the (a) point of lesson.... Error 1: the number must be a four-digit and positive.
 10000
 This is the (a) point of lesson.... Encryption of your number is: 189 ------------------------------------------------------------------------------------------------------ This is the (b) point of lesson.... Error 2: wrong encryption... must be a positive number less than 10000.
 1234 -3
 This is the (a) point of lesson.... Encryption of your number is: 189 ------------------------------------------------------------------------------------------------------ This is the (b) point of lesson.... Error 2: wrong encryption... must be a positive number less than 10000.
 1234 10000
 #include #include int main() { /// This is the (a) point of lesson.... std::cout << "This is the (a) point of lesson....\n"; if (::isatty(STDIN_FILENO)) { std::cout << "insert a four-digit whole number: "; } int number; std::cin >> number; if (number < 1000) { std::cerr << "Error 1: the number must be a four-digit and positive." << std::endl; return 1; } if (number > 9999) { std::cerr << "Error 1: the number must be a four-digit and positive." << std::endl; return 1; } int encryption = 1000 * (((number % 100 / 10) + 7) % 10) + 100 * (((number % 10) + 7) % 10) + 10 * (((number / 1000) + 7) % 10) + (((number % 1000 / 100) + 7) % 10); std::cout << "Encryption of your number is: " << encryption << std::endl; std::cout << "------------------------------------------------------------------------------------------------------\n"; /// This is the (b) point of lesson.... std::cout << "This is the (b) point of lesson....\n"; if (::isatty(STDIN_FILENO)) { std::cout << "Insert encryption(maximum four digit.): "; } int encryptedNumber; std::cin >> encryptedNumber; if (encryptedNumber < 0) { std::cerr << "Error 2: wrong encryption...\n" << "must be a positive number less than 10000.\n"; return 2; } else if (encryptedNumber > 9999) { std::cerr << "Error 2: wrong encryption...\n" << "must be a positive number less than 10000.\n"; return 2; } int initialNumber = 1000 * (((encryptedNumber % 100 / 10) + 10 - 7) % 10) + 100 * (((encryptedNumber % 10) + 10 - 7) % 10) + 10 * (((encryptedNumber / 1000) + 10 - 7) % 10) + (((encryptedNumber % 1000 / 100) + 10 - 7) % 10); std::cout << "encrypted initial number is: "<< initialNumber << 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!