From 8f54ef4d7e1c112e6dde2947a6a9a27c8393f899 Mon Sep 17 00:00:00 2001 From: Oskar Date: Fri, 30 Aug 2024 18:32:44 +0200 Subject: more --- 5p16.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 5p16.cpp (limited to '5p16.cpp') 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 +#include + +/* + * + * 5.16 + * + * + */ + +void idiomatic_while(std::vector &idw) { + + int i = 0; + while(std::cin >> i) { + idw.push_back(i); + } +} + +void idiomatic_for(std::vector &idf) { + + for(auto a : idf) { + std::cout << a << std::endl; + } +} + +void nonidiomatic_while(std::vector &nidw) { + + auto iter = nidw.cbegin(); + while(iter != nidw.cend()) { + std::cout << *iter++ << std::endl; + } +} + +void nonidiomatic_for(std::vector &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 iv1; + std::vector iv2; + if(argv_s == "1") { + idiomatic_while(iv1); + idiomatic_for(iv1); + } else if (argv_s == "2") { + nonidiomatic_for(iv2); + nonidiomatic_while(iv2); + } + + return 0; +} -- cgit v1.2.3