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

Manipulating a Vector

Puntuación
-
Vendido
-
Páginas
3
Subido en
06-11-2025
Escrito en
2025/2026

The provided code is a C++ program that manages a collection of "Box" objects using a vector. Here's a breakdown of its components and functionality: 1. **Includes and Namespaces**: - The program includes necessary libraries such as `<iostream>` for input/output operations, `<vector>` for using vectors, and `<string>` for string manipulation. The `std` namespace is used to simplify code. 2. **Box Structure**: - A `struct` named `Box` is defined, containing two properties: a `string` for the box's name and a `float` for its height. 3. **Function Declarations**: - Four functions are declared to handle the main operations: - `insertBox`: To add a new box to the collection. - `deleteBox`: To remove a box based on its name. - `displayBoxes`: To display information about all boxes in the vector. - `eraseAllBoxes`: To clear all boxes from the vector. 4. **Main Function**: - A loop allows the user to choose from a menu to add, delete, display boxes or quit the program. - User input is processed, and the appropriate function is called based on the user's choice. 5. **Insert Box Functionality**: - This function prompts the user for box details (name and height) and asks whether to add the box to the front or back of the vector. It handles edge cases, such as when the vector is empty. 6. **Delete Box Functionality**: - This function displays all boxes and asks the user for the name of the box they want to delete. If the box is found, it removes it and provides feedback. 7. **Display Boxes Functionality**: - This function shows the current capacity, size, and details of each box in the vector, including its name and height. 8. **Erase All Boxes Functionality**: - This function removes all boxes from the vector and provides feedback on the names of the boxes being erased, ensuring the vector is empty afterward. The program effectively demonstrates basic operations with vectors in C++, alongside user interaction and basic data management. It uses a simple command-line interface for users to manage their collection of boxes.

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
3
Escrito en
2025/2026
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

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

struct Box
{
string name;
float height;
};

void insertBox(vector<Box> & boxes);
void deleteBox(vector<Box> & boxes);
void displayBoxes(vector<Box> & boxes);
void eraseAllBoxes(vector<Box> & boxes);

int main()
{
char answer = 'Y';
vector<Box> boxes;
char choice;

do {
cout << "A. add a box to the vector" << endl;
cout << "B. delete a box from the vector" << endl;
cout << "C. display the vector of boxes" << endl;
cout << "D. quit" << endl << endl;
cout << "Enter choice: ";
cin >> choice;

cin.ignore();

switch(toupper(choice))
{
case 'A': insertBox(boxes);
break;
case 'B': deleteBox(boxes);
break;
case 'C' : displayBoxes(boxes);
break;
case 'D' : eraseAllBoxes(boxes);
return 0;
default : cout << endl << endl << "Error!" << endl;
}

cout << "Enter another choice (Y or N)? ";
cin >> answer;
} while (toupper(answer) == 'Y');
}

void insertBox(vector<Box> & boxes)
{
char choice;
Box box;

cout << "Enter a name for a box: ";
getline(cin, box.name);

cout << "Enter the height of the box in inches: ";
$15.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