title: create a dictionary of key value pairs in c++
body: <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class item {
      int size;
      int value[30];
      char key[30][20];
      int n, k;
      int index;
      char* a[30], *b[30], search, remove;
  
  public:
  
  
      void putdatavalue(void) {
          for (int i = 0; i &lt; size; i++) {
              cout &lt;&lt; value[i] &lt;&lt; ","
                   &lt;&lt; "\n";
          }
      }
  
      void display(void) {
          for (int i = 0; i &lt; size; i++) {
              cout &lt;&lt; "(" &lt;&lt; key[i] &lt;&lt; "," &lt;&lt; value[i] &lt;&lt; ")"
                   &lt;&lt; "\n";
          }
      }
  
  
  };
  
  void item::getdata(void) {
      cout &lt;&lt; "entr size\n";
      cin &gt;&gt; size;
      for (int i = 0; i &lt; size; i++) {
          cout &lt;&lt; "entr key\n";
          cin &gt;&gt; key[i];
          cout &lt;&lt; "entr value\n";
          cin &gt;&gt; value[i];
      }
      cout &lt;&lt; "chk whether keys are different \n";
      for (int i = 0; i &lt; size; i++) {
          a[i] = key[i];
          b[i] = key[i + 1];
          if (*a[i] == *b[i]) {
              cout &lt;&lt; "key" &lt;&lt; i &lt;&lt; "and key" &lt;&lt; i + 1 &lt;&lt; "are same\n";
              cout &lt;&lt; "re-entr key\n";
              cin &gt;&gt; key[i + 1];
          } else {
              cout &lt;&lt; "key[" &lt;&lt; i &lt;&lt; "] and key[" &lt;&lt; i + 1 &lt;&lt; "] are diff\n";
          }
      }
  }
  
  int main() {
  
      item obj1;
      obj1.getdata();
      int m;
      do {
          cout &lt;&lt; "choose ur option and enter appropriate no"
               &lt;&lt; "\n";
  
          cout &lt;&lt; "\n1 : display keys \n";
          cout &lt;&lt; "\n2 : display value \n";
          cout &lt;&lt; "\n3 : display key-value pair \n";
          cout &lt;&lt; "\n4 : add a key-value pair \n";
          cout &lt;&lt; "\n5 : remove a key-value pair \n";
          cout &lt;&lt; "\n6 : search for key and its value \n";
          cout &lt;&lt; "\n7 : quit \n";
          cin &gt;&gt; m;
  
          switch (m) {
  
              break;
  
              case 1: {
                  obj1.putdatakey();
              } break;
              case 2: {
                  obj1.putdatavalue();
              } break;
              case 3: {
                  obj1.display();
              } break;
  
              case 7:
                  break;
  
              default:
                  cout &lt;&lt; "error in input \n";
          }
      } while (m != 7);
      return 0;
  }
  </code></pre>
  
  <p>I am suppose to create a dictionary of <code>key-value</code> pairs in C++ with the following functions:
  <strong>display keys, display values, display key-value pairs, add a key-value, delete a key-value pair, find out if a key is present and return it value</strong>.</p>
  
  <p>It should be possible for dictionary to be empty.</p>
  
  <p>You should overload the <code>operator+</code> to do the <em>union</em> of two dictionaries and if the dictionaries each contain the same key, output an error message.</p>
  
  <p>My teacher asked us not to use <code>strings</code> and <code>vectors</code> so i used arrays
  I am stuck with the union function and don't know how to do it. Plz help me out.</p>