Home / utk / cs140 / sp19 / live_codings_in_lab / map_example_w_pokemon / pokemon.cpp
Directory Listing
pikachu.h
pokemon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include "pikachu.h"

using namespace std;

class pokemon {
	public:
		pokemon();
		pokemon(const string &, const string &, const bool &);
		bool operator<(const pokemon &) const;

		string get_name() const;

	private:
		string name;
		string type;
		bool shiny;
};

pokemon::pokemon(const string &n, const string &t, const bool &s) {
	name = n;
	type = t;
	shiny = s;
}

bool pokemon::operator<(const pokemon &rhs) const {
	return (name < rhs.name);
}

string pokemon::get_name() const {
	return name;
}

main() {
	map<pokemon, int> m;
	map<pokemon, int>::iterator it;

	m[pokemon("Piplup", "Water", 1)] = 3;
	m[pokemon("Pikachu", "Electric", 1)] = 2;

	for (it = m.begin(); it != m.end(); it++) {
		cout << it->first.get_name() << " -> " << it->second << endl;
	}
}