From 79644bad85429744f1462ac64c8aa46bc2d9822f Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 29 Jan 2024 16:46:20 +0100 Subject: [PATCH 01/11] update --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7d4fe6f..40a6f62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ int main() { // add_two_numbers(); // convert_char_to_ascii(); - // print_type_size_bytes(); + print_type_size_bytes(); return 0; } \ No newline at end of file From 7f0548cd6906b127fcdd232e5a061751af7e87cb Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 08:39:20 +0100 Subject: [PATCH 02/11] added Bubblesort --- src/io.cpp | 15 +++++++++++++++ src/io.h | 3 ++- src/main.cpp | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index 1da65ac..e123476 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -37,4 +37,19 @@ void print_type_size_bytes() 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"; +} +void bubble_sort(int *a) +{ + 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; + } + } + } } \ No newline at end of file diff --git a/src/io.h b/src/io.h index 39c803b..e5ae628 100644 --- a/src/io.h +++ b/src/io.h @@ -4,4 +4,5 @@ void add_two_numbers(); int read_number(); void write_answer(int x); void convert_char_to_ascii(); -void print_type_size_bytes(); \ No newline at end of file +void print_type_size_bytes(); +void bubble_sort(int *a); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 40a6f62..da47634 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,26 @@ #include // for std::cout #include "io.h" +#define ARRAY_SIZE 7 + // Definition of function main() +void bubble_sort_demo() +{ + int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; + for (int i = 0; i < 7; i++) + std::cout << demo[i] << ", "; + std::cout << "\n"; + bubble_sort(demo); + for (int i = 0; i < ARRAY_SIZE; i++) + std::cout << demo[i] << ", "; +} int main() { // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); + bubble_sort_demo(); + return 0; -} \ No newline at end of file +} From 5911856dc626a46567b1b38be202380e51fc5193 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 10:37:52 +0100 Subject: [PATCH 03/11] update --- src/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index da47634..73e863b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,23 @@ #define ARRAY_SIZE 7 -// Definition of function main() +template +void BubbleSort_T(T *a) +{ + for (size_t i = 0; i < 7; i++) + { + for (size_t j = 0; j < 7 - 1 - i; j++) + { + if (a[j] > a[j + 1]) + { + T temp{a[j]}; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +} + void bubble_sort_demo() { int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; @@ -14,13 +30,40 @@ void bubble_sort_demo() for (int i = 0; i < ARRAY_SIZE; i++) std::cout << demo[i] << ", "; } + +void bubble_sort_T_demo() +{ + int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; + double demo2[ARRAY_SIZE]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3}; + std::cout << "Demo: "; + for (int i = 0; i < 7; i++) + std::cout << demo[i] << ", "; + std::cout << "\n"; + std::cout << "Demo2: "; + + for (int i = 0; i < 7; i++) + std::cout << demo2[i] << ", "; + std::cout << "\n"; + + BubbleSort_T(demo); + BubbleSort_T(demo2); + std::cout << "Demo: "; + for (int i = 0; i < 7; i++) + std::cout << demo[i] << ", "; + std::cout << "\n"; + std::cout << "Demo2: "; + + for (int i = 0; i < 7; i++) + std::cout << demo2[i] << ", "; + std::cout << "\n"; +} int main() { // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); - bubble_sort_demo(); + bubble_sort_T_demo(); return 0; } From 29ee27dbab4b40aa39b7f25dfb055ff326d268bf Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 12:07:16 +0100 Subject: [PATCH 04/11] update --- src/io.h | 33 ++++++++++++++++++++++++++-- src/main.cpp | 61 ++++------------------------------------------------ 2 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/io.h b/src/io.h index e5ae628..16eba01 100644 --- a/src/io.h +++ b/src/io.h @@ -1,8 +1,37 @@ #pragma once - +#include // for std::cout void add_two_numbers(); int read_number(); void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); -void bubble_sort(int *a); \ No newline at end of file + +template +void bubble_sort(T *a) +{ + for (int i = 0; i < sizeof(&a) / sizeof(a); i++) + { + for (int j = 0; j < 7 - 1 - i; j++) + { + if (a[j] > a[j + 1]) + { + T temp{a[j]}; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +} +template +void bubble_sort_print(int size, T *a) +{ + std::cout << "unsorted Array: "; + for (int i = 0; i < size; i++) + std::cout << a[i] << ", "; + std::cout << "\n"; + bubble_sort(a); + std::cout << "sorted Array: "; + for (int i = 0; i < size; i++) + std::cout << a[i] << ", "; + std::cout << "\n"; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 73e863b..92dd2f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,69 +1,16 @@ #include // for std::cout #include "io.h" -#define ARRAY_SIZE 7 - -template -void BubbleSort_T(T *a) -{ - for (size_t i = 0; i < 7; i++) - { - for (size_t j = 0; j < 7 - 1 - i; j++) - { - if (a[j] > a[j + 1]) - { - T temp{a[j]}; - a[j] = a[j + 1]; - a[j + 1] = temp; - } - } - } -} - -void bubble_sort_demo() -{ - int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; - for (int i = 0; i < 7; i++) - std::cout << demo[i] << ", "; - std::cout << "\n"; - bubble_sort(demo); - for (int i = 0; i < ARRAY_SIZE; i++) - std::cout << demo[i] << ", "; -} - -void bubble_sort_T_demo() -{ - int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; - double demo2[ARRAY_SIZE]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3}; - std::cout << "Demo: "; - for (int i = 0; i < 7; i++) - std::cout << demo[i] << ", "; - std::cout << "\n"; - std::cout << "Demo2: "; - - for (int i = 0; i < 7; i++) - std::cout << demo2[i] << ", "; - std::cout << "\n"; - - BubbleSort_T(demo); - BubbleSort_T(demo2); - std::cout << "Demo: "; - for (int i = 0; i < 7; i++) - std::cout << demo[i] << ", "; - std::cout << "\n"; - std::cout << "Demo2: "; - - for (int i = 0; i < 7; i++) - std::cout << demo2[i] << ", "; - std::cout << "\n"; -} 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}; // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); - bubble_sort_T_demo(); + bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo); + bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2); return 0; } From 3f5945ca8c3a4cd7f4bb1e08d40dca1503fd0fa8 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 12:24:53 +0100 Subject: [PATCH 05/11] update --- src/io.h | 8 ++++---- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/io.h b/src/io.h index 16eba01..2ac5eb8 100644 --- a/src/io.h +++ b/src/io.h @@ -7,11 +7,11 @@ void convert_char_to_ascii(); void print_type_size_bytes(); template -void bubble_sort(T *a) +void bubble_sort(int size, T *a) { - for (int i = 0; i < sizeof(&a) / sizeof(a); i++) + for (int i = 0; i < size; i++) { - for (int j = 0; j < 7 - 1 - i; j++) + for (int j = 0; j < size - 1 - i; j++) { if (a[j] > a[j + 1]) { @@ -29,7 +29,7 @@ void bubble_sort_print(int size, T *a) for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; - bubble_sort(a); + bubble_sort(size, a); std::cout << "sorted Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; diff --git a/src/main.cpp b/src/main.cpp index 92dd2f4..9c84a8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ 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}; + double demo2[]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3, 12.3}; // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); From 921ca197bf855d17dc2df2faca7f62fb1701b573 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 12:38:25 +0100 Subject: [PATCH 06/11] Updated --- src/io.h | 23 +++++++++++++++++++++-- src/main.cpp | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/io.h b/src/io.h index 2ac5eb8..ebe4d8d 100644 --- a/src/io.h +++ b/src/io.h @@ -6,6 +6,24 @@ void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); +#include +template +struct TypeName +{ + static const char *Get() + { + return typeid(T).name(); + } +}; +template <> +struct TypeName +{ + static const char *Get() + { + return "s"; + } +}; + template void bubble_sort(int size, T *a) { @@ -25,12 +43,13 @@ void bubble_sort(int size, T *a) template void bubble_sort_print(int size, T *a) { - std::cout << "unsorted Array: "; + + std::cout << "unsorted " << TypeName::Get() << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; bubble_sort(size, a); - std::cout << "sorted Array: "; + std::cout << "sorted " << TypeName::Get() << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; diff --git a/src/main.cpp b/src/main.cpp index 9c84a8e..74fc882 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,12 +5,14 @@ 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); return 0; } From c50ef8bfe3337a0c91bff1a9ea8d915475c20824 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 12:42:03 +0100 Subject: [PATCH 07/11] update --- src/io.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/io.h b/src/io.h index ebe4d8d..3556351 100644 --- a/src/io.h +++ b/src/io.h @@ -1,12 +1,13 @@ #pragma once -#include // for std::cout +#include +#include + void add_two_numbers(); int read_number(); void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); -#include template struct TypeName { @@ -39,7 +40,8 @@ void bubble_sort(int size, T *a) } } } -} +}; + template void bubble_sort_print(int size, T *a) { @@ -53,4 +55,4 @@ void bubble_sort_print(int size, T *a) for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; -} \ No newline at end of file +}; \ No newline at end of file From 69b4f6ecf8ed159f070d701b783d9ba51d748e02 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Tue, 6 Feb 2024 07:18:11 +0100 Subject: [PATCH 08/11] 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; } From 6ecbab2b643b233d94b8010451b76199366f426b Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Thu, 8 Feb 2024 09:58:54 +0100 Subject: [PATCH 09/11] update --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2f3e99c..c5e92d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ int main() // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); - bubble_sort_print_demo(); + // bubble_sort_print_demo(); return 0; } From 6a3935cac25ab952bbed881bccb582529888a47a Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Tue, 5 Mar 2024 09:58:45 +0100 Subject: [PATCH 10/11] update 05.03.24 --- src/algo.cpp | 11 +++++++++++ src/algo.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/io.cpp | 10 +--------- src/io.h | 53 -------------------------------------------------- src/main.cpp | 1 + 5 files changed, 68 insertions(+), 62 deletions(-) create mode 100644 src/algo.cpp create mode 100644 src/algo.h diff --git a/src/algo.cpp b/src/algo.cpp new file mode 100644 index 0000000..f13f6b4 --- /dev/null +++ b/src/algo.cpp @@ -0,0 +1,11 @@ +#include "algo.h" + +void bubble_sort_print_demo() +{ + 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/algo.h b/src/algo.h new file mode 100644 index 0000000..52bc41f --- /dev/null +++ b/src/algo.h @@ -0,0 +1,55 @@ +#pragma once +#include +#include +#include + +void bubble_sort_print_demo(); + +template +struct TypeName +{ + static const char *Get() + { + return typeid(T).name(); + } +}; +template <> +struct TypeName +{ + static const char *Get() + { + return "s"; + } +}; + +template +void bubble_sort(int size, T *a) +{ + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size - 1 - i; j++) + { + if (a[j] > a[j + 1]) + { + T temp{a[j]}; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +}; + +template +void bubble_sort_print(int size, T *a) +{ + 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() << std::setw(12) << " Array: "; + for (int i = 0; i < size; i++) + std::cout << a[i] << ", "; + std::cout << "\n\n"; +}; \ No newline at end of file diff --git a/src/io.cpp b/src/io.cpp index e912c59..90f2791 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -1,6 +1,7 @@ #include "io.h" #include #include + void add_two_numbers() { int a{read_number()}; @@ -39,12 +40,3 @@ void print_type_size_bytes() std::cout << std::setw(16) << "double:" << sizeof(double) << " bytes\n"; std::cout << std::setw(16) << "long double:" << sizeof(long double) << " bytes\n\n"; } -void bubble_sort_print_demo() -{ - 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 2a07d3a..ecdefe3 100644 --- a/src/io.h +++ b/src/io.h @@ -1,60 +1,7 @@ #pragma once -#include -#include -#include void add_two_numbers(); 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 -{ - static const char *Get() - { - return typeid(T).name(); - } -}; -template <> -struct TypeName -{ - static const char *Get() - { - return "s"; - } -}; - -template -void bubble_sort(int size, T *a) -{ - for (int i = 0; i < size; i++) - { - for (int j = 0; j < size - 1 - i; j++) - { - if (a[j] > a[j + 1]) - { - T temp{a[j]}; - a[j] = a[j + 1]; - a[j + 1] = temp; - } - } - } -}; - -template -void bubble_sort_print(int size, T *a) -{ - 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() << std::setw(12) << " Array: "; - for (int i = 0; i < size; i++) - std::cout << a[i] << ", "; - std::cout << "\n\n"; -}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c5e92d2..0a793a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include // for std::cout #include "io.h" +#include "algo.h" int main() { From 4a29e375f5d96d47aa9e1249bb3a4c348aa1a6e3 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Thu, 11 Apr 2024 13:58:59 +0200 Subject: [PATCH 11/11] first commit --- src/io.cpp | 12 ++++++++++++ src/io.h | 1 + src/main.cpp | 1 + 3 files changed, 14 insertions(+) diff --git a/src/io.cpp b/src/io.cpp index 90f2791..c8a8734 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -40,3 +40,15 @@ void print_type_size_bytes() std::cout << std::setw(16) << "double:" << sizeof(double) << " bytes\n"; std::cout << std::setw(16) << "long double:" << sizeof(long double) << " bytes\n\n"; } +void string_demo() +{ + using namespace std; + cout << "Enter your full name: "; + string name{}; + getline(cin >> ws, name); + cout << "Enter your age: "; + int age{}; + cin >> age; + int letters{static_cast(name.length())}; + cout << "Your age + length of name is: " << (letters + age) << "\n"; +} \ No newline at end of file diff --git a/src/io.h b/src/io.h index ecdefe3..74cc367 100644 --- a/src/io.h +++ b/src/io.h @@ -5,3 +5,4 @@ int read_number(); void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); +void string_demo(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0a793a6..b0c8dde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ int main() { + // string_demo(); // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes();