diff options
author | Oskar <[email protected]> | 2024-08-15 17:26:06 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-15 17:26:06 +0200 |
commit | bec90eeec483f4fd685bb28758cdf55897bc0b3e (patch) | |
tree | 2e6199d7f62768937b3d480de905af3d537770d5 | |
parent | 19f1a70edbf2b08536c114e12f7b3c1e77469730 (diff) |
more exercises and tests
-rw-r--r-- | 3p41.cpp | 24 | ||||
-rw-r--r-- | 3p42.cpp | 30 | ||||
-rw-r--r-- | 3p43.cpp | 15 | ||||
-rw-r--r-- | multi-arr-test.cpp | 57 | ||||
-rw-r--r-- | vec-arr-test.cpp | 30 |
5 files changed, 156 insertions, 0 deletions
diff --git a/3p41.cpp b/3p41.cpp new file mode 100644 index 0000000..4ae2247 --- /dev/null +++ b/3p41.cpp @@ -0,0 +1,24 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" +#include <iterator> + +/* + * + * 3.41 + * + * Same thing as i did on my vec-arr-test.cpp + */ + +int main () { + + int arr[] = {23,432423,43253,123,787,45677,3345,657784,3453}; + std::vector<int> va(std::begin(arr), std::end(arr)); + for(auto vaa : va) { + std::cout << vaa << " "; + } + + std::cout << std::endl; + return 0; +} diff --git a/3p42.cpp b/3p42.cpp new file mode 100644 index 0000000..495a6f6 --- /dev/null +++ b/3p42.cpp @@ -0,0 +1,30 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" +#include <iterator> + +/* + * + * 3.42 + * + * + */ + +int main () { + + std::vector<int> va = {23,432423,43253,123,787,45677,3345,657784,3453,10}; + int arr[10]; // Really annoying that there is no way to take the size of the vector and use it as the size of this array. + int i = 0; + for(auto a : va) { + arr[i] = a; + ++i; + } + + for(auto a : arr) { + std::cout << a << " "; + } + + std::cout << std::endl; + return 0; +} diff --git a/3p43.cpp b/3p43.cpp new file mode 100644 index 0000000..a766d56 --- /dev/null +++ b/3p43.cpp @@ -0,0 +1,15 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.43 + * + * + */ + +int main () { + return 0; +} diff --git a/multi-arr-test.cpp b/multi-arr-test.cpp new file mode 100644 index 0000000..bdd5306 --- /dev/null +++ b/multi-arr-test.cpp @@ -0,0 +1,57 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" +#include <iterator> + +/* + * + * + * + * + */ + +int main () { + + constexpr size_t rowCnt = 3, colCnt = 4; + int ia[rowCnt][colCnt]; + for (size_t i = 0; i != rowCnt; ++i) { + for (size_t j = 0; j != colCnt; ++j) { + ia[i][j] = i * colCnt + j; + } + } + + for(auto &a : ia) { + for(auto b : a) { + std::cout << b << " "; + } + std::cout << std::endl; + } + + int ia2[rowCnt][colCnt]; + size_t counter = 0; + for(auto &row : ia2) { + for(auto &col : row) { + col = counter; + ++counter; + } + } + + std::cout << std::endl; + for(auto &a : ia2) { + for(auto b : a) { + std::cout << b << " "; + } + std::cout << std::endl; + } + + std::cout << std::endl; + for(auto a = std::begin(ia2) ; a != std::end(ia2) ; ++a) { + for(auto aa = std::begin(*a) ; aa != std::end(*a) ; ++aa) { + std::cout << *aa << " "; + } + std::cout << std::endl; + } + + return 0; +} diff --git a/vec-arr-test.cpp b/vec-arr-test.cpp new file mode 100644 index 0000000..fcfdb1f --- /dev/null +++ b/vec-arr-test.cpp @@ -0,0 +1,30 @@ +#include <iostream> +#include <vector> +#include <iterator> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * + * + * + */ + +int main () { + + int arr[] = {1,43,47,3465,3,553,2,667,31}; + std::vector<int> varr1(std::begin(arr), std::end(arr)); + std::vector<int> varr2(arr+0, arr+9); + for(auto a : varr1) { + std::cout << a << " "; + } + + std::cout << std::endl; + for(auto a : varr2) { + std::cout << a << " "; + } + + std::cout << std::endl; + return 0; +} |