#include //STARTSOLUTION #include //ENDSOLUTION #include using namespace std; using coordinate = std::pair; using hexagon = std::string; //STARTSOLUTION class Tile { public: Tile(string name): name{name}, hexagones{} {} void create_hexagon(coordinate const& coord, hexagon const& str) { hexagones.emplace(make_pair(coord, str)); } void print_tile(ostream& os = cout) const { os << name << ":\n"; for( auto h: hexagones ) { print_hexagon(h.first, os); } } void print_hexagon(coordinate const& coord, ostream& os = cout) const { os << "Hexagon(" << coord.first << ", " << coord.second << "): "; os << "[" << hexagones.at(coord).back() << "]"; os << endl; } void push(coordinate const& coord, char c) { hexagones.at(coord).push_back(c); } private: string name; map hexagones; }; //ENDSOLUTION int main() { Tile b1{"b1"}; b1.create_hexagon(coordinate{0, 0}, hexagon{"HXOX"}); b1.print_hexagon(coordinate{0, 0}); b1.push(coordinate{0, 0}, 'O'); b1.create_hexagon(coordinate{0, 1}, hexagon{"OXXXH"}); b1.print_tile(); } // coordinate och hexagon som används i huvudprogrammet ovan // är egentligen bara smeknamn för std::pair och // std::string. Se using-direktiven på rad 8 och 9. // Om man inte använde using för coordinate och hexagon ovan // så skulle huvudprogrammet se ut på följande sätt: // int main() // { // Tile b1{"b1"}; // b1.create_hexagon(pair{0, 0}, string{"HXOX"}); // b1.print_hexagon(pair{0, 0}); // b1.push(pair{0, 0}, 'O'); // b1.create_hexagon(pair{0, 1}, string{"OXXXH"}); // b1.print_tile(); // }