100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Otro

Working with map<> and ::iterator

Puntuación
-
Vendido
-
Páginas
1
Subido en
06-11-2025
Escrito en
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.

Mostrar más Leer menos
Institución
Grado








Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
6 de noviembre de 2025
Número de páginas
1
Escrito en
2025/2026
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

#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;
}
}
$11.49
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
tinahuynh

Conoce al vendedor

Seller avatar
tinahuynh California State University, Long Beach
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
Nuevo en Stuvia
Miembro desde
1 mes
Número de seguidores
0
Documentos
68
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes