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

COS2611 Assignment 1 2024 memo

Rating
5,0
(1)
Sold
12
Pages
19
Uploaded on
10-05-2024
Written in
2023/2024

COS2611 Assignment 1 2024 memo











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

Document information

Uploaded on
May 10, 2024
Number of pages
19
Written in
2023/2024
Type
Other
Person
Unknown

Subjects

Content preview

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();

Reviews from verified buyers

Showing all reviews
1 year ago

5,0

1 reviews

5
1
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
foxNotes Acsess Business Academy
View profile
Follow You need to be logged in order to follow users or courses
Sold
112
Member since
2 year
Number of followers
63
Documents
35
Last sold
1 month ago
saveNotes

5,0

5 reviews

5
5
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