From cda6ed407ab13a6d7fe279477c0539d0f329c3e8 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 12:20:24 +0100 Subject: [PATCH 01/19] refactor --- io.cpp => src/io.cpp | 0 io.h => src/io.h | 0 main.cpp => src/main.cpp | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename io.cpp => src/io.cpp (100%) rename io.h => src/io.h (100%) rename main.cpp => src/main.cpp (100%) diff --git a/io.cpp b/src/io.cpp similarity index 100% rename from io.cpp rename to src/io.cpp diff --git a/io.h b/src/io.h similarity index 100% rename from io.h rename to src/io.h diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp From ee652cb6ee5e8526aa2ef9fcedf5851e91bd658a Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 12:22:28 +0100 Subject: [PATCH 02/19] refactor --- dot vscode/launch.json | 4 ++-- dot vscode/tasks.json | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dot vscode/launch.json b/dot vscode/launch.json index 081340e..58291ac 100644 --- a/dot vscode/launch.json +++ b/dot vscode/launch.json @@ -4,7 +4,7 @@ "name": "Debug: C/C++", "type": "cppdbg", "request": "launch", - "program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe", + "program": "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", @@ -30,7 +30,7 @@ "name": "Release: C/C++", "type": "cppdbg", "request": "launch", - "program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe", + "program": "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", diff --git a/dot vscode/tasks.json b/dot vscode/tasks.json index 6037983..8299a09 100644 --- a/dot vscode/tasks.json +++ b/dot vscode/tasks.json @@ -6,12 +6,13 @@ "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ "-fdiagnostics-color=always", + "-I${workspaceFolder}\\include", "-ggdb", "-std=c++20", "-pedantic-errors", - "${fileDirname}/**.cpp", + "${workspaceFolder}/src/**.cpp", "-o", - "${fileDirname}\\build\\${fileBasenameNoExtension}.exe" + "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}" @@ -26,13 +27,14 @@ "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ "-fdiagnostics-color=always", + "-I${workspaceFolder}\\include", "-O2", "-DNDEBUG", "-std=c++20", "-pedantic-errors", - "${fileDirname}/**.cpp", + "${workspaceFolder}/src/**.cpp", "-o", - "${fileDirname}\\build\\${fileBasenameNoExtension}.exe" + "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}" From 943f09563ea3fbd2955383082963b4eec43e5f47 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 12:23:14 +0100 Subject: [PATCH 03/19] refactor --- include/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 include/.gitkeep diff --git a/include/.gitkeep b/include/.gitkeep new file mode 100644 index 0000000..e69de29 From 95bbaa9aab0d19445be9a4be8bb6f699b1248ee0 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 16:50:08 +0100 Subject: [PATCH 04/19] refactor snake case --- src/io.cpp | 4 ++-- src/io.h | 4 ++-- src/main.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index 6c03ca8..e8bedeb 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -1,14 +1,14 @@ #include "io.h" #include -int readNumber() +int read_number() { std::cout << "Enter a number to add: "; int x{}; std::cin >> x; return x; } -void writeAnswer(int x) +void write_answer(int x) { std::cout << "The answer is: " << x << "\n"; } \ No newline at end of file diff --git a/src/io.h b/src/io.h index 7c489bc..a9b314e 100644 --- a/src/io.h +++ b/src/io.h @@ -1,4 +1,4 @@ #pragma once -int readNumber(); -void writeAnswer(int x); \ No newline at end of file +int read_number(); +void write_answer(int x); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9cf4fd0..218873f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,8 @@ int main() { - int a{readNumber()}; - int b{readNumber()}; - writeAnswer(a + b); + int a{read_number()}; + int b{read_number()}; + write_answer(a + b); return 0; } \ No newline at end of file From 0b7f4871524eb94eeacdcfd0902ca170dd6c215c Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 19:08:07 +0100 Subject: [PATCH 05/19] update --- src/main.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 218873f..b582257 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,24 @@ #include // for std::cout +#include #include "io.h" - +#include // Definition of function main() int main() { - int a{read_number()}; - int b{read_number()}; - write_answer(a + b); + // int a{read_number()}; + // int b{read_number()}; + // write_answer(a + b); + + std::cout << std::left; // left justify output + std::cout << std::setw(16) << "bool:" << sizeof(bool) << " bytes\n"; + std::cout << std::setw(16) << "char:" << sizeof(char) << " bytes\n"; + std::cout << std::setw(16) << "short:" << sizeof(short) << " bytes\n"; + std::cout << std::setw(16) << "int:" << sizeof(int) << " bytes\n"; + std::cout << std::setw(16) << "long:" << sizeof(long) << " bytes\n"; + 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"; return 0; } \ No newline at end of file From 15d64721613c83cad80aa674475e51095c5bcd4f Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 19:08:56 +0100 Subject: [PATCH 06/19] update --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b582257..2b1859d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include // for std::cout #include #include "io.h" -#include // Definition of function main() int main() { From ebe10eb632a850a201dc9cf1c8582ba6daab94ab Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 29 Jan 2024 08:09:07 +0100 Subject: [PATCH 07/19] update --- src/io.cpp | 8 ++++++++ src/io.h | 3 ++- src/main.cpp | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/io.cpp b/src/io.cpp index e8bedeb..95a9159 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -11,4 +11,12 @@ int read_number() void write_answer(int x) { std::cout << "The answer is: " << x << "\n"; +} + +void convert_char_to_ascii() +{ + std::cout << "Enter a single character: "; + char c{}; + std::cin >> c; + std::cout << "You entered '" << c << "', which hass ASCII code " << static_cast(c) << "."; } \ No newline at end of file diff --git a/src/io.h b/src/io.h index a9b314e..ce5bab5 100644 --- a/src/io.h +++ b/src/io.h @@ -1,4 +1,5 @@ #pragma once int read_number(); -void write_answer(int x); \ No newline at end of file +void write_answer(int x); +void convert_char_to_ascii(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2b1859d..c0ebe3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ int main() // int a{read_number()}; // int b{read_number()}; // write_answer(a + b); + // convert_char_to_ascii(); std::cout << std::left; // left justify output std::cout << std::setw(16) << "bool:" << sizeof(bool) << " bytes\n"; @@ -19,5 +20,6 @@ int main() 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"; + return 0; } \ No newline at end of file From 3964df59165f2470fdd304dfa1a9854ab11e97de Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 29 Jan 2024 16:13:08 +0100 Subject: [PATCH 08/19] update --- src/io.cpp | 22 ++++++++++++++++++++-- src/io.h | 4 +++- src/main.cpp | 19 +++---------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index 95a9159..1da65ac 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -1,6 +1,12 @@ #include "io.h" #include - +#include +void add_two_numbers() +{ + int a{read_number()}; + int b{read_number()}; + write_answer(a + b); +} int read_number() { std::cout << "Enter a number to add: "; @@ -12,11 +18,23 @@ void write_answer(int x) { std::cout << "The answer is: " << x << "\n"; } - void convert_char_to_ascii() { std::cout << "Enter a single character: "; char c{}; 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 + std::cout << std::setw(16) << "bool:" << sizeof(bool) << " bytes\n"; + std::cout << std::setw(16) << "char:" << sizeof(char) << " bytes\n"; + std::cout << std::setw(16) << "short:" << sizeof(short) << " bytes\n"; + std::cout << std::setw(16) << "int:" << sizeof(int) << " bytes\n"; + std::cout << std::setw(16) << "long:" << sizeof(long) << " bytes\n"; + 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"; } \ No newline at end of file diff --git a/src/io.h b/src/io.h index ce5bab5..39c803b 100644 --- a/src/io.h +++ b/src/io.h @@ -1,5 +1,7 @@ #pragma once +void add_two_numbers(); int read_number(); void write_answer(int x); -void convert_char_to_ascii(); \ No newline at end of file +void convert_char_to_ascii(); +void print_type_size_bytes(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c0ebe3f..7d4fe6f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,12 @@ #include // for std::cout -#include #include "io.h" + // Definition of function main() int main() { - - // int a{read_number()}; - // int b{read_number()}; - // write_answer(a + b); + // add_two_numbers(); // convert_char_to_ascii(); - - std::cout << std::left; // left justify output - std::cout << std::setw(16) << "bool:" << sizeof(bool) << " bytes\n"; - std::cout << std::setw(16) << "char:" << sizeof(char) << " bytes\n"; - std::cout << std::setw(16) << "short:" << sizeof(short) << " bytes\n"; - std::cout << std::setw(16) << "int:" << sizeof(int) << " bytes\n"; - std::cout << std::setw(16) << "long:" << sizeof(long) << " bytes\n"; - 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"; + // print_type_size_bytes(); return 0; } \ No newline at end of file From 79644bad85429744f1462ac64c8aa46bc2d9822f Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 29 Jan 2024 16:46:20 +0100 Subject: [PATCH 09/19] 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 10/19] 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 11/19] 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 12/19] 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 13/19] 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 14/19] 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 15/19] 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 16/19] 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 17/19] 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 18/19] 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 19/19] 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();