This commit is contained in:
ZennDev1337 2024-02-06 07:18:11 +01:00
parent c50ef8bfe3
commit 69b4f6ecf8
3 changed files with 16 additions and 25 deletions

View file

@ -25,6 +25,7 @@ void convert_char_to_ascii()
std::cin >> c;
std::cout << "You entered '" << c << "', which hass ASCII code " << static_cast<int>(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);
}

View file

@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <string>
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 <typename T>
struct TypeName
@ -45,14 +47,14 @@ void bubble_sort(int size, T *a)
template <typename T>
void bubble_sort_print(int size, T *a)
{
std::cout << "unsorted " << TypeName<T>::Get() << " Array: ";
std::cout << std::left; // left justify output
std::cout << "unsorted " << TypeName<T>::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<T>::Get() << " Array: ";
std::cout << "sorted " << TypeName<T>::Get() << std::setw(12) << " Array: ";
for (int i = 0; i < size; i++)
std::cout << a[i] << ", ";
std::cout << "\n";
std::cout << "\n\n";
};

View file

@ -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;
}