Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MAP_H
- #define MAP_H
- using KeyType = std::string;
- using ValueType = double;
- const int DEFAULT_MAX_ITEMS = 240;
- class Map
- {
- public:
- Map(); // Create an empty map (i.e., one with no key/value pairs)
- bool empty() const;
- int size() const; // Return the number of key/value pairs in the map.
- bool insert(const std::string& key, const double& value);
- bool update(const std::string& key, const double& value);
- // If key is equal to a key currently in the map, then make that key no
- // longer map to the value it currently maps to, but instead map to
- // the value of the second parameter; return true in this case.
- // Otherwise, make no change to the map and return false.
- bool insertOrUpdate(const std::string& key, const double& value);
- // If key is equal to a key currently in the map, then make that key no
- // longer map to the value that it currently maps to, but instead map to
- // the value of the second parameter; return true in this case.
- // If key is not equal to any key currently in the map and if the
- // key/value pair can be added to the map, then do so and return true.
- // Otherwise, make no change to the map and return false (indicating
- // that the key is not already in the map and the map has a fixed
- // capacity and is full).
- bool erase(const std::string& key);
- // If key is equal to a key currently in the map, remove the key/value
- // pair with that key from the map and return true. Otherwise, make
- // no change to the map and return false.
- bool contains(const std::string& key) const;
- // Return true if key is equal to a key currently in the map, otherwise
- // false.
- bool get(const std::string& key, double& value);
- // If key is equal to a key currently in the map, set value to the
- // value in the map which that key maps to, and return true. Otherwise,
- // make no change to the value parameter of this function and return
- // false.
- bool get(int i, std::string& key, double& value);
- // If 0 <= i < size(), copy into the key and value parameters the
- // key and value of one of the key/value pairs in the map and return
- // true. Otherwise, leave the key and value parameters unchanged and
- // return false. (See below for details about this function.)
- void swap(Map& other);
- // Exchange the contents of this map with the other one.
- private:
- struct Coord
- {
- public:
- KeyType key()
- {
- return m_key;
- }
- ValueType value()
- {
- return m_value;
- }
- private:
- KeyType m_key;
- ValueType m_value;
- };
- Coord m_coord[DEFAULT_MAX_ITEMS];
- };
- bool Map::empty() const // Return true if the map is empty, otherwise false.
- {
- if (sizeof(m_coord) == 0)
- return false;
- else
- return true;
- }
- int Map::size() const
- {
- }
- bool Map::insert(const std::string& key, const double& value)
- {
- if (m_coord.size() == DEFAULT_MAX_ITEMS)
- return
- for (int iterator = 0; iterator < m_coord.size(); iterator++)
- {
- if (m_coord[iterator].key() == key)
- return false;
- }
- // If key is not equal to any key currently in the map, and if the
- // key/value pair can be added to the map, then do so and return true.
- // Otherwise, make no change to the map and return false (indicating
- // that either the key is already in the map, or the map has a fixed
- // capacity and is full).
- }
- bool Map::update(const std::string& key, const double& value)
- {
- }
- bool Map::insertOrUpdate(const std::string& key, const double& value)
- {
- }
- bool Map::erase(const std::string& key)
- {
- }
- bool Map::contains(const std::string& key) const
- {
- }
- bool Map::get(const std::string& key, double& value)
- {
- }
- bool Map::get(int i, std::string& key, double& value)
- {
- }
- void Map::swap(Map& other)
- {
- }
- #endif
- #___________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement