summaryrefslogtreecommitdiff
path: root/5p16.cpp
diff options
context:
space:
mode:
Diffstat (limited to '5p16.cpp')
-rw-r--r--5p16.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/5p16.cpp b/5p16.cpp
new file mode 100644
index 0000000..27c6bcb
--- /dev/null
+++ b/5p16.cpp
@@ -0,0 +1,57 @@
+#include <iostream>
+#include <vector>
+
+/*
+ *
+ * 5.16
+ *
+ *
+ */
+
+void idiomatic_while(std::vector<int> &idw) {
+
+ int i = 0;
+ while(std::cin >> i) {
+ idw.push_back(i);
+ }
+}
+
+void idiomatic_for(std::vector<int> &idf) {
+
+ for(auto a : idf) {
+ std::cout << a << std::endl;
+ }
+}
+
+void nonidiomatic_while(std::vector<int> &nidw) {
+
+ auto iter = nidw.cbegin();
+ while(iter != nidw.cend()) {
+ std::cout << *iter++ << std::endl;
+ }
+}
+
+void nonidiomatic_for(std::vector<int> &nidf) {
+
+ int i = 0;
+ for( ; std::cin >> i ; ) {
+ nidf.push_back(i);
+ }
+}
+
+int main (int argc, char *argv[]) {
+
+ if(argc > 2 || argc < 2) { return -1; }
+ std::string argv_s = argv[1];
+ std::vector<int> iv1;
+ std::vector<int> iv2;
+ if(argv_s == "1") {
+ idiomatic_while(iv1);
+ idiomatic_for(iv1);
+ } else if (argv_s == "2") {
+ nonidiomatic_for(iv2);
+ nonidiomatic_while(iv2);
+ }
+
+ return 0;
+}