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

COS2611 Assignment 1 2024 memo

Puntuación
5.0
(1)
Vendido
12
Páginas
19
Subido en
10-05-2024
Escrito en
2023/2024

COS2611 Assignment 1 2024 memo

Institución
Grado










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

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
10 de mayo de 2024
Número de páginas
19
Escrito en
2023/2024
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

COS2611 2024 Assignment 1 memo
Question 1 The difference between a linear representation of a stack and a
linked implementation of a stack is that IN A LINKED IMPLEMENTATION OF
STACKS:


1. Elements are stored as nodes with references/pointers to the next element.
2. Elements are typically stored in a fixed-size array or a dynamic array.
3. The stack operations are performed based on the indices of the elements within the array.
4. None of the options given.

Question 2 Consider the provided code. Its objective is to establish a stack,
display the stack's elements, and report the stack's size.
THE USER EXPECTED THE FOLLOWING OUTPUT:
FredMaryPeterJohnThe size of the class: 4
However, the output does not align with the user's expectations.
How can the code be modified to generate the anticipated output?"


//the code
#include <stack>
#include <string>
int main()
{ std::stack<std::string> stackClass;
stackClass.push("John");
stackClass.push("Peter");
stackClass.push("Mary");
stackClass.push("Fred");
//....code to be modified
while (!stackClass.empty())
{
std::cout << stackClass.top();
stackClass.pop();
}
int size = stackClass.size();

,std::cout << "the size of the class: " << size;
//... end code to be modified return 0;}




a. while (!stackClass.empty())
{ std::cout << stackClass.top();
stackClass.pop();
}
int size = stackClass.size();
std::cout << "The size of the class: " << size << "\n";


b. while (!stackClass.empty())
{
std::cout << stackClass.top() << "\n";
stackClass.pop();
}
int size = stackClass.size();
std::cout << "The size of the class: " << size;


c. while (!stackClass.empty())
{ stackClass.pop();
std::cout << stackClass.top() << "\n";
}
int size = stackClass.size();
std::cout << "The size of the class: " << size;


d. int size = stackClass.size();
while (!stackClass.empty())
{ stackClass.pop();
std::cout << stackClass.top() << "\n";
}
std::cout << "The size of the class: " << size;

, e. None of the provided options.

Question 3 Consider the following code. In this code the function
displayClass(stackClass) is called.
Which of the following code (i) represents the correct implementation of the DISPLAYCLASS
function?
#include <stack>
#include <string>//...(i)... missing code for the function.
int main()
{
std::stack<std::string> stackClass;
stackClass.push("John");
stackClass.push("Peter");
stackClass.push("Mary");
DISPLAYCLASS(stackClass);
return 0;
}




a. void displayClass(std::stack<std::string> myStack)
{
while (!myStack.empty())
{
std::cout << myStack.top() << "\n";
myStack.pop();
}
}
b. void displayClass(std::stack<std::string> myStack)
{
while (!myStack.empty())
{
myStack.pop();
$9.38
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

Reseñas de compradores verificados

Se muestran los comentarios
1 año hace

5.0

1 reseñas

5
1
4
0
3
0
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
foxNotes Acsess Business Academy
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
112
Miembro desde
2 año
Número de seguidores
63
Documentos
35
Última venta
3 meses hace
saveNotes

5.0

5 reseñas

5
5
4
0
3
0
2
0
1
0

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