summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--3p43.cpp35
-rw-r--r--3p44.cpp52
-rw-r--r--3p45.cpp49
-rw-r--r--multi-arr-test.cpp3
4 files changed, 139 insertions, 0 deletions
diff --git a/3p43.cpp b/3p43.cpp
index a766d56..19fa0ce 100644
--- a/3p43.cpp
+++ b/3p43.cpp
@@ -2,6 +2,7 @@
#include <vector>
#include "sales_data.hpp"
#include "sales_item.hpp"
+#include <iterator>
/*
*
@@ -11,5 +12,39 @@
*/
int main () {
+
+ int ia[3][4] = {
+ {1,2,3,4},
+ {5,6,7,8},
+ {9,10,11,12}
+ };
+
+ for (int (&a)[4] : ia) { // A reference to an array of 4 int's
+ // I'll be honest i would not have figured that out myself, i did search the internet for answers.
+ for (int aa : a) {
+ std::cout << aa << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(size_t i = 0 ; i != 3 ; ++i) {
+ for(size_t j = 0 ; j != 4 ; ++j) {
+ std::cout << ia[i][j] << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(int (*p)[4] = std::begin(ia) ; p != std::end(ia) ; ++p) {
+ for(int *pp = std::begin(*p) ; pp != std::end(*p) ; ++pp) {
+ std::cout << *pp << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
return 0;
}
diff --git a/3p44.cpp b/3p44.cpp
new file mode 100644
index 0000000..f098169
--- /dev/null
+++ b/3p44.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <vector>
+#include "sales_data.hpp"
+#include "sales_item.hpp"
+#include <iterator>
+
+/*
+ *
+ * 3.44
+ *
+ *
+ */
+
+int main () {
+
+ int ia[3][4] = {
+ {1,2,3,4},
+ {5,6,7,8},
+ {9,10,11,12}
+ };
+
+ using int_arr4 = int[4]; // I'll be honest i dont like this whole 'using' and 'typedef'
+ // It just feels like obfuscating the code when you really don't need to.
+ for (int_arr4 &a : ia) { // A reference to an array of 4 int's
+ // I'll be honest i would not have figured that out myself, i did search the internet for answers.
+ for (int aa : a) {
+ std::cout << aa << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(size_t i = 0 ; i != 3 ; ++i) {
+ for(size_t j = 0 ; j != 4 ; ++j) {
+ std::cout << ia[i][j] << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(int_arr4 *p = std::begin(ia) ; p != std::end(ia) ; ++p) {
+ for(int *pp = std::begin(*p) ; pp != std::end(*p) ; ++pp) {
+ std::cout << *pp << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ return 0;
+}
diff --git a/3p45.cpp b/3p45.cpp
new file mode 100644
index 0000000..0116a88
--- /dev/null
+++ b/3p45.cpp
@@ -0,0 +1,49 @@
+#include <iostream>
+#include <vector>
+#include "sales_data.hpp"
+#include "sales_item.hpp"
+#include <iterator>
+
+/*
+ *
+ * 3.45
+ *
+ *
+ */
+
+int main () {
+
+ int ia[3][4] = {
+ {1,2,3,4},
+ {5,6,7,8},
+ {9,10,11,12}
+ };
+
+ for (auto &a : ia) {
+ for (auto aa : a) {
+ std::cout << aa << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(size_t i = 0 ; i != 3 ; ++i) {
+ for(size_t j = 0 ; j != 4 ; ++j) {
+ std::cout << ia[i][j] << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+ for(auto p = std::begin(ia) ; p != std::end(ia) ; ++p) {
+ for(auto pp = std::begin(*p) ; pp != std::end(*p) ; ++pp) {
+ std::cout << *pp << " ";
+ }
+
+ std::cout << std::endl;
+ }
+
+ return 0;
+}
diff --git a/multi-arr-test.cpp b/multi-arr-test.cpp
index bdd5306..9abf500 100644
--- a/multi-arr-test.cpp
+++ b/multi-arr-test.cpp
@@ -25,6 +25,7 @@ int main () {
for(auto b : a) {
std::cout << b << " ";
}
+
std::cout << std::endl;
}
@@ -42,6 +43,7 @@ int main () {
for(auto b : a) {
std::cout << b << " ";
}
+
std::cout << std::endl;
}
@@ -50,6 +52,7 @@ int main () {
for(auto aa = std::begin(*a) ; aa != std::end(*a) ; ++aa) {
std::cout << *aa << " ";
}
+
std::cout << std::endl;
}