diff --git a/point/hashmap.cpp b/point/hashmap.cpp new file mode 100644 index 0000000..7ae285b --- /dev/null +++ b/point/hashmap.cpp @@ -0,0 +1,28 @@ +/* Hash map example + * November 18, 2023 */ +#include +#include +#include +using namespace std; + +int main(void) { + unordered_map mymap { + {"Uno", 1}, + {"Dos", 2}, + {"Tres", 3}, + {"Quatro", 4}, + {"Cinco", 5}, + }; + + cout << "Printing mymap:" << endl; + + for (const auto& x: mymap) { + string s = x.first; + int v = x.second; + + cout << "mymap[" << s << "] = " << v << endl; + } + + return 0; +} + diff --git a/point/list.cpp b/point/list.cpp new file mode 100644 index 0000000..278174a --- /dev/null +++ b/point/list.cpp @@ -0,0 +1,86 @@ +/* C++ list + * November 18, 2023 */ +#include +#include +#include +#include +using namespace std; + +class Color { +private: + short red; + short green; + short blue; + string name; + +public: + Color(void) { + red = 0; + green = 0; + blue = 0; + cout << "Constructed color" << endl; + } + Color(int r) { + red = (short)r; + green = 0; + blue = 0; + cout << "Constructed color" << endl; + } + Color(int r, int g, int b) { + red = (short)r; + green = (short)g; + blue = (short)b; + cout << "Constructed color" << endl; + } + Color(string n, int r, int g, int b) { + name = n; + red = (short)r; + green = (short)g; + blue = (short)b; + cout << "Constructed color " << n << endl; + } + ~Color(void) { + if (!name.empty()) + cout << "Destroyed color " << name << endl; + else + cout << "Destroyed color" << endl; + } + + void print(void) { + cout << "Red: " << red << endl; + cout << "Green: " << green << endl; + cout << "Blue: " << blue << endl; + if (!name.empty()) { + cout << name << endl; + } + } + + void printHex(void) { + printf("%x %x %x\n", red, green, blue); + cout << name << endl; + } +}; + +int main(void) { + list li; + li.push_back(Color("gray", 50, 50, 50)); + li.push_back(Color("purple", 255, 60, 255)); + li.push_back(Color("red", 255, 0, 0)); + cout << endl; + + for (Color c : li) { + c.printHex(); + } + cout << endl; + + li.clear(); + li.push_back(Color("yellow", 255, 255, 0)); + li.push_back(Color("blue", 0, 10, 255)); + for (Color c : li) { + c.printHex(); + } + cout << endl; + + return 0; +} +