diff options
-rw-r--r-- | 3p12.cpp | 27 | ||||
-rw-r--r-- | 3p13.cpp | 37 | ||||
-rw-r--r-- | 3p14.cpp | 39 | ||||
-rw-r--r-- | 3p15.cpp | 33 | ||||
-rw-r--r-- | exercise-template.cpp | 2 |
5 files changed, 138 insertions, 0 deletions
diff --git a/3p12.cpp b/3p12.cpp new file mode 100644 index 0000000..ef46169 --- /dev/null +++ b/3p12.cpp @@ -0,0 +1,27 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.12 + * + * + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; +int main () { + + vector<vector<int>> ivec; // A vector of vectors of int + //vector<string> svec = ivec; // Not valid, you can not initialize a vector of strings to with a vector of int. + vector<string> svec(10, "null"); // A vector of 10 objects of type string all initialized to "null" + + return 0; +} diff --git a/3p13.cpp b/3p13.cpp new file mode 100644 index 0000000..ca60b58 --- /dev/null +++ b/3p13.cpp @@ -0,0 +1,37 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.13 + * + * + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; +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" + + // some extra testing below + vector<string> v8(10); // same as v6? + vector<string> v9(10, "hi"); // Same as v7? + + cout << v7[1] << endl; + cout << v9[1] << endl; + return 0; +} diff --git a/3p14.cpp b/3p14.cpp new file mode 100644 index 0000000..b11a9ff --- /dev/null +++ b/3p14.cpp @@ -0,0 +1,39 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.14 + * + * Not exactly according to instructions but still learned from making this. + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; +int main () { + + int n; + vector<int> vn; + if(cin >> n) { + vn.push_back(n); + while(cin >> n){ + vn.push_back(n); + } + + } else { + return -1; + } + + for(auto vni : vn) { + cout << vni << endl; + } + + return 0; +} diff --git a/3p15.cpp b/3p15.cpp new file mode 100644 index 0000000..27a648d --- /dev/null +++ b/3p15.cpp @@ -0,0 +1,33 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.15 + * + * Not completely according to instructions but thats okay. I still learned creating this. + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; +int main () { + + string phrase; + vector<string> vp; + while(getline(cin, phrase)) { + vp.push_back(phrase); + } + + for(auto vpi : vp) { + cout << vpi << endl; + } + + return 0; +} diff --git a/exercise-template.cpp b/exercise-template.cpp index 38099b7..8986133 100644 --- a/exercise-template.cpp +++ b/exercise-template.cpp @@ -1,4 +1,5 @@ #include <iostream> +#include <vector> #include "sales_data.hpp" #include "sales_item.hpp" @@ -15,6 +16,7 @@ using std::cin; using std::cerr; using std::clog; using std::endl; +using std::vector; int main () { |