create an example using dictionaries in c++ please in c++ oop and include .h .cpp all files thnx?
IF YOU LIKE THE ANSWER PLEASE UPVOTE RATHER THAN DOWNVOTE.
ANY QUESTION PLEASE DO ASK WILL BE HAPPY TO HELP YOU.
From your i could only understand is this you need a dictionary to be implemented in C++ which i have done and sharing with you. Do have a look and let me know if anything else needed.
there is only one .cpp file required which you can create with any name and paste your code it will run.
std::map is the standard library which is used to implement dictionary in c++. It uses key value pair where keys are unique and values are associated with them map is STL in C++.
#include <string>
// Map is the concept through which we implement dictionary in C++,
So including the header files.
#include <map>
#include <iostream>
using namespace std;
int main()
{
// creating the map with key and value pair
// Like in dictionary we have meaning for word here
for a particluar key we have a value.
map<int, string> m;
m[1] = "A";
m[2] = "B";
m[3] = "C";
m[4] = "D";
m[5] = "E";
m[6] = "F";
// Loop through and print elements from map
for (auto i : m)
{
cout << i.first << " :
" << i.second << endl;
}
// Fetching the value based on key
cout << "The value for key 1 is : " <<
m[1] << endl;
// Inserting a key at end.
m[7] = "9";
// Modifying the existing key and changing the value
from C to Z
m[3] = "Z";
// Loop through and print elements from map
for (auto i : m)
{
cout << i.first << " :
" << i.second << endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.