100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Working with map<> and ::iterator

Rating
-
Sold
-
Pages
1
Uploaded on
06-11-2025
Written in
2025/2026

The provided code is a C++ program that manages a simple map of contacts with their associated names. Here's a breakdown of the key components: 1. **Includes and Namespace**: The program includes the necessary headers for input/output, string handling, and using maps from the Standard Template Library (STL). The `using namespace std;` statement allows accessing standard library features without needing to prefix them with `std::`. 2. **Main Function**: This is where the program execution begins. 3. **Map Declaration**: A `map` named `contactPerson` is declared, which uses `string` types for both keys (company names) and values (contact names). 4. **Populating the Map**: The map is populated with four entries where each company name is mapped to a fictional contact name, some of which play on jokes related to their brands (e.g., "E. Coli" for "Chipotle Mexican Grill"). 5. **Output Statements**: - It prints the contact name associated with "Takata Inc". - It displays the total number of contacts stored in the map using `contactP()`. 6. **Iterating Over the Map**: A `for` loop is used to iterate through each element in the `contactPerson` map. For each entry, it prints the company name and its associated contact. 7. **Checking for Existence**: Inside the loop, it checks if "Volkswagon of America" is in the map using `find()`. If the company is not found, it outputs a message; otherwise, it confirms its presence. However, the check is incorrectly placed inside the loop, so it will print the existence message for each contact. Overall, this program demonstrates basic map functionality in C++, including adding entries, retrieving values, iterating through the map, and checking for the existence of a key. The use of humorous names in the map values adds a light-hearted touch to the program.

Show more Read less
Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Course

Document information

Uploaded on
November 6, 2025
Number of pages
1
Written in
2025/2026
Type
Other
Person
Unknown

Subjects

Content preview

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
map<string, string>contactPerson;

contactPerson["Volkswagon of America"] = "I.B. Cheaton";
contactPerson["Wallers Fargo Bank"] = "Ima Swindler";
contactPerson["Chipotle Mexican Grill"] = "E. Coli";
contactPerson["Takata Inc"] = "I. X. Plodum";

cout << "Takata Inc = " << contactPerson["Takata Inc"] << endl << endl;
cout << "# of contacts: " << contactPerson.size() << endl << endl;

for (map<string, string>::iterator it = contactPerson.begin(); it!=
contactPerson.end(); ++it)
{
cout << (*it).first << ":\t" << (*it).second << endl << endl;

if (contactPerson.find("Volkswagon of America") == contactPerson.end())
cout << "It's not in the map!" << endl << endl;
else
cout << "It's in the map" << endl << endl;
}
}
R201,68
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
tinahuynh

Get to know the seller

Seller avatar
tinahuynh California State University, Long Beach
Follow You need to be logged in order to follow users or courses
Sold
New on Stuvia
Member since
1 month
Number of followers
0
Documents
68
Last sold
-

0,0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions