Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18.2, Problem 14STE
Program Plan Intro

“map” template class:

  • Type name for “map” of type “KeyType” elements to “T” elements  is

    “map<KeyType, T>” or “map<KeyType, T, Ordering>”

    • The “Ordering” is used to sort the values by using the key value.
    • If no “Ordering” is given, the ordering used is the binary operator “<”.
  • The library header for “map” is “<map>”.
    • It places the definition in the “std” namespace.
  • Defined type for “map” is given below:
    • “key_type” is used to represents the type of the key values.
    • “mapped_type” is used to indicate the type of the values mapped to.
    • “size_type” is used to represent the type of the size.
  • The iterators are used in the “map” template class is “iterator”, “const_iterator”, “reverse_iterator” and “const_reverse_iterator”.
  • The “map” template class uses the pair template class.
    • The pair template is used to store the association between the key and a data item.
    • Example: “map<string, int> numMap;”
      • Using the above example, user can add a mapping from “c++” to the number “8” by using “[]” operator.
      • Example for the above statement is “numMap["c++"] = 8;”.

Blurred answer
Students have asked these similar questions
In C++, declare a map <int,Student> to store serial number and student object. Student class contain id, name and cgpa. Print all map data.
"Make a program using a map where the mapping value is a custom object of your design.  It can be a one-to-one mapping or a one-to-many mapping, your choice." Maps Object Extension, Java, AP Computer Science A, simple. Hash Map. One Class.
SKELETON CODE IS PROVIDED ALONG WITH C AND H FILES.   #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h>   #include "node.h" #include "stack_functions.h"   #define NUM_VERTICES 10 /** This function takes a pointer to the     adjacency matrix of a Graph and the     size of this matrix as arguments and     prints the matrix */ void print_graph(int * graph, int size);   /** This function takes a pointer to the     adjacency matrix of a Graph, the size     of this matrix, the source and dest     node numbers along with the weight or     cost of the edge and fills the adjacency     matrix accordingly. */ void add_edge(int * graph, int size, int src, int dst, int cost);     /** This function takes a pointer to the adjacency matrix of     a graph, the size of this matrix, source and destination     vertex numbers as inputs and prints out the path from the     source vertex to the destination vertex. It also prints     the total cost of this…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning