Im trying to store objects of type MapEntry in to an array that is in another class but i'm not quite sure on how to approach it. Specifically because the array is private. Can anyone be of any assistance ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main()
{
Map theMap;
MapEntry myMap("Course","001");
MapEntry myMap3("Course","150");
//store all these objects into an array
}
This is the object I am trying to store it in. All of the objects have to go into the array mapping[MAX_MAPPINGS].
class Map {
private:
staticconstint MAX_MAPPINGS = 100;
MapEntry mapping[MAX_MAPPINGS];
size_t numberOfMappings;
// Performs an ascending sort by default. If ascending is false,
// then it performs a descending sort. The actual sorting is performed
// on the key.
void SelectionSort(bool ascending = true);
// Returns the index of the next smallest key.
int GetIndexOfNextSmallest(const size_t start) const;
// Returns the index of the next largest key.
int GetIndexOfNextLargest(const size_t start) const;
// Swaps the two elements whose indices are provided.
void SwapElementsAtIndex(constint index1, constint index2);
public:
// Initializes the object by setting numberOfMappings to 0.
Map();
// Retrieves the value for the given key. If the key is not found,
// then the value is undefined (should not be used by caller), and
// method returns false. If found, method returns true.
bool GetValueAssignedToKey(const string& theKey, string& theValue);
// Sets the value for the given key. The new pair is added to the end
// of the mappings array. Keys must be unique, so if a duplicate key
// is given, raise a MapException with the message:
// "MapException: Duplicate keys are not allowed.".
void SetValueForKey(const string& theKey, const MapValueType& theValue);
// Sorts the mappings array in ascending order by default. If ascending
// is false, then it sorts in descending order. Calls the private method
// SelectionSort() to perform the actual sort.
void Sort(bool ascending = true);
// List all the key-value pairs using the format:
// Key = <key>,<space>Value = <value>
void List() const;
};// end Map