From 69b4f6ecf8ed159f070d701b783d9ba51d748e02 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Tue, 6 Feb 2024 07:18:11 +0100 Subject: [PATCH] update --- src/io.cpp | 23 +++++++++-------------- src/io.h | 10 ++++++---- src/main.cpp | 8 +------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index e123476..e912c59 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -25,6 +25,7 @@ void convert_char_to_ascii() std::cin >> c; std::cout << "You entered '" << c << "', which hass ASCII code " << static_cast(c) << "."; } + void print_type_size_bytes() { std::cout << std::left; // left justify output @@ -36,20 +37,14 @@ void print_type_size_bytes() std::cout << std::setw(16) << "long long:" << sizeof(long long) << " bytes\n"; std::cout << std::setw(16) << "float:" << sizeof(float) << " bytes\n"; std::cout << std::setw(16) << "double:" << sizeof(double) << " bytes\n"; - std::cout << std::setw(16) << "long double:" << sizeof(long double) << " bytes\n"; + std::cout << std::setw(16) << "long double:" << sizeof(long double) << " bytes\n\n"; } -void bubble_sort(int *a) +void bubble_sort_print_demo() { - for (size_t i = 0; i < 7; i++) - { - for (size_t j = 0; j < 7 - 1 - i; j++) - { - if (a[j] > a[j + 1]) - { - int temp{a[j]}; - a[j] = a[j + 1]; - a[j + 1] = temp; - } - } - } + int demo[]{11, 14, 3, 18, 8, 17, 43, 6, 5, 4}; + double demo2[]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3, 12.3}; + std::string demo3[]{"hallo", "velo", "kekw", "imagin"}; + bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo); + bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2); + bubble_sort_print(sizeof(demo3) / sizeof(demo3[0]), demo3); } \ No newline at end of file diff --git a/src/io.h b/src/io.h index 3556351..2a07d3a 100644 --- a/src/io.h +++ b/src/io.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include void add_two_numbers(); @@ -7,6 +8,7 @@ int read_number(); void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); +void bubble_sort_print_demo(); template struct TypeName @@ -45,14 +47,14 @@ void bubble_sort(int size, T *a) template void bubble_sort_print(int size, T *a) { - - std::cout << "unsorted " << TypeName::Get() << " Array: "; + std::cout << std::left; // left justify output + std::cout << "unsorted " << TypeName::Get() << std::setw(10) << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; bubble_sort(size, a); - std::cout << "sorted " << TypeName::Get() << " Array: "; + std::cout << "sorted " << TypeName::Get() << std::setw(12) << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; - std::cout << "\n"; + std::cout << "\n\n"; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 74fc882..2f3e99c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,16 +3,10 @@ int main() { - int demo[]{11, 14, 3, 18, 8, 17, 43, 6, 5, 4}; - double demo2[]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3, 12.3}; - std::string demo3[]{"hallo", "welo", "kekw", "imagin"}; // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); - - bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo); - bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2); - bubble_sort_print(sizeof(demo3) / sizeof(demo3[0]), demo3); + bubble_sort_print_demo(); return 0; }