From 97df48a5d420072c1ed487b7d5306d1665e692db Mon Sep 17 00:00:00 2001 From: Oskar Date: Fri, 9 Aug 2024 12:46:41 +0200 Subject: more exercises --- 3p21.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 3p21.cpp (limited to '3p21.cpp') diff --git a/3p21.cpp b/3p21.cpp new file mode 100644 index 0000000..f1bad84 --- /dev/null +++ b/3p21.cpp @@ -0,0 +1,56 @@ +#include +#include +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.21 + * + * + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; + +void cout_vector_int_iterator(vector vx) { + + for(auto itr = vx.cbegin() ; itr != vx.cend() ; itr++) { + cout << "'" << *itr << "'"; + } + + cout << endl; +} + +void cout_vector_string_iterator(vector vxs) { + + for(auto itr = vxs.cbegin() ; itr != vxs.cend() ; itr++) { + cout << "'" << *itr << "'"; + } + + cout << endl; +} + +int main () { + + vector v1; // 0 elements? + vector v2(10); // 10 elements, default initialized + vector v3(10, 42); // 10 elements, all initialized to 42 + vector v4{10}; // 1 element, initialized to 10. + vector v5{10, 42}; // 2 elements, first one 10, second one 42 + vector v6{10}; // Not really valid but it creates 10 elements of default initialized strings. Empty strings. + vector v7{10, "hi"}; // Not really valid but creates 10 elements that says "hi" + cout_vector_int_iterator(v1); + cout_vector_int_iterator(v2); + cout_vector_int_iterator(v3); + cout_vector_int_iterator(v4); + cout_vector_int_iterator(v5); + cout_vector_string_iterator(v6); + cout_vector_string_iterator(v7); + return 0; +} -- cgit v1.2.3