Skip to content

Commit

Permalink
Nice
Browse files Browse the repository at this point in the history
  • Loading branch information
Babkock committed Nov 18, 2023
1 parent a6de2d9 commit e35ea6a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
28 changes: 28 additions & 0 deletions point/hashmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Hash map example
* November 18, 2023 */
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

int main(void) {
unordered_map<string, int> 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;
}

86 changes: 86 additions & 0 deletions point/list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* C++ list
* November 18, 2023 */
#include <iostream>
#include <list>
#include <string>
#include <cstdio>
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<Color> 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;
}

0 comments on commit e35ea6a

Please sign in to comment.