diff options
author | Oskar <[email protected]> | 2024-08-09 12:46:41 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-09 12:46:41 +0200 |
commit | 97df48a5d420072c1ed487b7d5306d1665e692db (patch) | |
tree | 9fd129a1b108828d02cf4baa6cbeef54be371afe /3p21.cpp | |
parent | 9b931cfed1551961c8bbb93b21051104c0c4c716 (diff) |
more exercises
Diffstat (limited to '3p21.cpp')
-rw-r--r-- | 3p21.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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 <iostream> +#include <vector> +#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<int> vx) { + + for(auto itr = vx.cbegin() ; itr != vx.cend() ; itr++) { + cout << "'" << *itr << "'"; + } + + cout << endl; +} + +void cout_vector_string_iterator(vector<string> vxs) { + + for(auto itr = vxs.cbegin() ; itr != vxs.cend() ; itr++) { + cout << "'" << *itr << "'"; + } + + cout << endl; +} + +int main () { + + vector<int> v1; // 0 elements? + vector<int> v2(10); // 10 elements, default initialized + vector<int> v3(10, 42); // 10 elements, all initialized to 42 + vector<int> v4{10}; // 1 element, initialized to 10. + vector<int> v5{10, 42}; // 2 elements, first one 10, second one 42 + vector<string> v6{10}; // Not really valid but it creates 10 elements of default initialized strings. Empty strings. + vector<string> 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; +} |