From c0d4e6a5f0e5f4d56f896562000c432dd6def1fd Mon Sep 17 00:00:00 2001 From: Valera Dudarev Date: Sun, 16 Jul 2017 10:55:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20-=20?= =?UTF-8?q?=D0=B1=D0=B8=D1=82=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dudarev V A/Task 2/PrintHTML.cpp | 71 ++++++++++++++++++++ Dudarev V A/Task 2/uint_32.cpp | 111 +++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 Dudarev V A/Task 2/PrintHTML.cpp create mode 100644 Dudarev V A/Task 2/uint_32.cpp diff --git a/Dudarev V A/Task 2/PrintHTML.cpp b/Dudarev V A/Task 2/PrintHTML.cpp new file mode 100644 index 0000000..6adbf5d --- /dev/null +++ b/Dudarev V A/Task 2/PrintHTML.cpp @@ -0,0 +1,71 @@ +#include "stdafx.h" + +typedef unsigned char flag; + +void PrintHtml(char const* string, int style) { + flag bold = 1; + flag italic = 1; + flag underline = 1; + bool bold_1 = false; + bool italic_1 = false; + bool underline_1 = false; + if (style & bold) { + bold_1 = true; + std::cout << ""; + } + style >>= 1; + if (style & italic) { + italic_1 = true; + std::cout << ""; + } + style >>= 1; + if (style & underline) { + underline_1 = true; + std::cout << ""; + } + std::cout << string; + if (underline_1) { + std::cout << ""; + } + if (italic_1) { + std::cout << ""; + } + if (bold_1) { + std::cout << ""; + } +} + +int choose_style() { + flag style = 0; + bool value = false; + std::cout << "Bold(0 - false, 1 - true): "; + std::cin >> value; + if (value) { + style |= 1; + value = false; + } + std::cout << "\nItalic(0 - false, 1 - true): "; + std::cin >> value; + if (value) { + style |= 0x02; + value = false; + } + std::cout << "\nUnderline(0 - false, 1 - true): "; + std::cin >> value; + if (value) { + style |= 0x04; + } + return style; +} + +int main(int argc, _TCHAR* argv[]) +{ + setlocale(LC_ALL, "RUS"); + char* some_string = (char*)malloc(256); + std::cout << "Enter the string: "; + std::cin >> some_string; + flag style = choose_style(); + + PrintHtml(some_string, style); + return 0; +} diff --git a/Dudarev V A/Task 2/uint_32.cpp b/Dudarev V A/Task 2/uint_32.cpp new file mode 100644 index 0000000..c04891f --- /dev/null +++ b/Dudarev V A/Task 2/uint_32.cpp @@ -0,0 +1,111 @@ +#include "stdafx.h" + +enum HorAlign { + left, + center, + right, + justify +}; +void PrintBinary(uint32_t flags) +{ + uint32_t flag = 0x8000; + while (flag) + { + if (flags & flag) + { + printf("1"); + } + else + { + printf("0"); + } + flag >>= 1; + } + printf("\n"); +} +uint32_t setSetting(bool bold, bool italic, bool underline, HorAlign align_, int size) { + uint32_t result = 0; + if (bold) { + result |= 1; + } + if (italic) { + result |= 0x02; + } + if (underline) { + result |= 0x04; + } + uint32_t align_value = align_ << 3; + result |= align_value; + uint32_t size_value = size << 7; + result |= size_value; + return result; +} +void printSetting(uint32_t result) { + if (result & 1) { + printf("Bold: true."); + } + else { + printf("Bold: false."); + } + if (result & 0x02) { + printf("\nItalic: true."); + } + else { + printf("\nItalic: false."); + } + if (result & 0x04) { + printf("\nUnderline: true."); + } + else { + printf("\nUnderline: false."); + } + uint32_t mask = 0x00000008 | 0x000000010 | 0x00000020 | 0x00000040; + HorAlign align = (HorAlign)((result & mask) >> 3); + mask = 0x0000ff00;; + int8_t size = (int8_t)((result & mask) >> 7); + printf("\nHorAlign: %d\nSize: %d", align, size); +} +void input() { + std::cout << "Bold(0 - false, 1 - true): "; + bool bold; + std::cin >> bold; + std::cout << "Italic(0 - false, 1 - true): "; + bool italic; + std::cin >> italic; + std::cout << "Underline(0 - false, 1 - true): "; + bool underline; + std::cin >> underline; + int align_; + std::cout << "Align(0 - left, 1 - center, 2 - right, 3 - justify): "; + std::cin >> align_; + int size; + std::cout << "Size: "; + std::cin >> size; + uint32_t result; + switch (align_) { + case 0: + result = setSetting(bold, italic, underline, left, size); + case 1: + result = setSetting(bold, italic, underline, right, size); + case 2: + result = setSetting(bold, italic, underline, center, size); + case 3: + result = setSetting(bold, italic, underline, justify, size); + } + std::cout << std::endl; + PrintBinary(result); + std::cout << std::endl; + printSetting(result); +} + +int main(int argc, _TCHAR* argv[]) +{ + setlocale(LC_ALL, "RUS"); + uint32_t result = setSetting(false, true, true, right, 60); + printSetting(result); + std::cout << std::endl; + input(); + std::cout << std::endl; + return 0; +} +