Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.76 KB | None | 0 0
  1. #ifndef MAP_H
  2. #define MAP_H
  3. using KeyType = std::string;
  4. using ValueType = double;
  5. const int DEFAULT_MAX_ITEMS = 240;
  6.  
  7. class Map
  8. {
  9. public:
  10.     Map();         // Create an empty map (i.e., one with no key/value pairs)
  11.  
  12.     bool empty() const;
  13.     int size() const;    // Return the number of key/value pairs in the map.
  14.  
  15.     bool insert(const std::string& key, const double& value);
  16.    
  17.  
  18.     bool update(const std::string& key, const double& value);
  19.     // If key is equal to a key currently in the map, then make that key no
  20.     // longer map to the value it currently maps to, but instead map to
  21.     // the value of the second parameter; return true in this case.
  22.     // Otherwise, make no change to the map and return false.
  23.  
  24.     bool insertOrUpdate(const std::string& key, const double& value);
  25.     // If key is equal to a key currently in the map, then make that key no
  26.     // longer map to the value that it currently maps to, but instead map to
  27.     // the value of the second parameter; return true in this case.
  28.     // If key is not equal to any key currently in the map and if the
  29.     // key/value pair can be added to the map, then do so and return true.
  30.     // Otherwise, make no change to the map and return false (indicating
  31.     // that the key is not already in the map and the map has a fixed
  32.     // capacity and is full).
  33.  
  34.     bool erase(const std::string& key);
  35.     // If key is equal to a key currently in the map, remove the key/value
  36.     // pair with that key from the map and return true.  Otherwise, make
  37.     // no change to the map and return false.
  38.  
  39.     bool contains(const std::string& key) const;
  40.     // Return true if key is equal to a key currently in the map, otherwise
  41.     // false.
  42.  
  43.     bool get(const std::string& key, double& value);
  44.     // If key is equal to a key currently in the map, set value to the
  45.     // value in the map which that key maps to, and return true.  Otherwise,
  46.     // make no change to the value parameter of this function and return
  47.     // false.
  48.  
  49.     bool get(int i, std::string& key, double& value);
  50.     // If 0 <= i < size(), copy into the key and value parameters the
  51.     // key and value of one of the key/value pairs in the map and return
  52.     // true.  Otherwise, leave the key and value parameters unchanged and
  53.     // return false.  (See below for details about this function.)
  54.  
  55.     void swap(Map& other);
  56.     // Exchange the contents of this map with the other one.
  57. private:
  58.  
  59.     struct Coord
  60.     {
  61.     public:
  62.         KeyType key()
  63.         {
  64.             return m_key;
  65.         }
  66.  
  67.         ValueType value()
  68.         {
  69.             return m_value;
  70.         }
  71.     private:
  72.         KeyType m_key;
  73.         ValueType m_value;
  74.     };
  75.     Coord m_coord[DEFAULT_MAX_ITEMS];
  76.  
  77. };
  78.  
  79. bool Map::empty() const  // Return true if the map is empty, otherwise false.
  80. {
  81.     if (sizeof(m_coord) == 0)
  82.         return false;
  83.     else
  84.         return true;
  85. }
  86. int Map::size() const
  87. {
  88.  
  89. }
  90.  
  91. bool Map::insert(const std::string& key, const double& value)
  92. {
  93.     if (m_coord.size() == DEFAULT_MAX_ITEMS)
  94.         return
  95.     for (int iterator = 0; iterator < m_coord.size(); iterator++)
  96.     {
  97.         if (m_coord[iterator].key() == key)
  98.             return false;
  99.  
  100.     }
  101.     // If key is not equal to any key currently in the map, and if the
  102.     // key/value pair can be added to the map, then do so and return true.
  103.     // Otherwise, make no change to the map and return false (indicating
  104.     // that either the key is already in the map, or the map has a fixed
  105.     // capacity and is full).
  106.  
  107. }
  108.  
  109. bool Map::update(const std::string& key, const double& value)
  110. {
  111.  
  112. }
  113.  
  114. bool Map::insertOrUpdate(const std::string& key, const double& value)
  115. {
  116.  
  117. }
  118.  
  119. bool Map::erase(const std::string& key)
  120. {
  121.  
  122. }
  123. bool Map::contains(const std::string& key) const
  124. {
  125.  
  126. }
  127.  
  128. bool Map::get(const std::string& key, double& value)
  129. {
  130.  
  131. }
  132.  
  133. bool Map::get(int i, std::string& key, double& value)
  134. {
  135.  
  136. }
  137.  
  138. void Map::swap(Map& other)
  139. {
  140.  
  141. }
  142.  
  143.  
  144.  
  145.  
  146. #endif
  147.  
  148.  
  149. #___________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement