Can you finish the code pleaseaccording to the instruction For the stack, perform the following operations in order - Push seven (7) objects starting from the array index 13 onwards to the stack. Peek the top of the stack - print the result. Perform three (3) pops in succession. Print the contents of the stack. Push five (5) more objects from the start of the objects array to the stack. Pop twice in succession. Print the contents of the stack. For the queue, perform the following operations in order - Enqueue the seven (7) objects at odd indexes starting from index 5 in the array. Peek the front and end of the queue - print the results. Perform two (2) dequeues in succession. Print the contents of the queue. Enqueue five (5) more objects from the index 10 in the array. Dequeue three times in succession. Print the contents of the queue. End the program with a leaving message of your choice. Remember to clean up before the program ends. Restrict all your input / output to the main driver program only, except for the existing screen print inside the Currency print methods. #include #include "Currency.h" #include "SinglyLinkedList.h" #include "Stack.h" #include "Queue.h" using namespace std; int main() { // Welcome message cout << "Welcome to the demonstration of ADTs by [your full name]" << endl << endl; // Create the Currency array Currency currencies[20] = { Currency(57.12), Currency(23.44), Currency(87.43), Currency(68.99), Currency(111.22), Currency(44.55), Currency(77.77), Currency(18.36), Currency(543.21), Currency(20.21), Currency(345.67), Currency(36.18), Currency(48.48), Currency(101.00), Currency(11.00), Currency(21.00), Currency(51.00), Currency(1.00), Currency(251.00), Currency(151.00) }; // Create SinglyLinkedList object SinglyLinkedList currencyList; // Add first 7 objects to the linked list in reverse order for (int i = 6; i >= 0; i--) { currencyList.addFirst(currencies[i]); } // Search for Kr 87.43 followed by Kr 44.56 - print the results of each cout << "Search for Kr 87.43: " << (currencyList.search(Currency(87.43)) ? "Found" : "Not found") << endl; cout << "Search for Kr 44.56: " << (currencyList.search(Currency(44.56)) ? "Found" : "Not found") << endl; // Remove node containing Kr 111.22 followed by the node at index 2 currencyList.remove(Currency(111.22)); currencyList.removeAt(2); // Print contents of the list cout << "Contents of the list: "; currencyList.print(); // Add next 4 objects to the list for (int i = 8; i < 12; i++) { currencyList.add((i % 5), currencies[i]); } // Remove two objects at indexes (countCurrency % 6) and (countCurrency / 7) int countCurrency = currencyList.size(); currencyList.removeAt(countCurrency % 6); currencyList.removeAt(countCurrency / 7); // Print contents of the list cout << "Contents of the list: "; currencyList.print(); // Create Stack object Stack currencyStack; // Push seven objects starting from array index 13 to the stack for (int i = 13; i < 20; i++) { currencyStack.push(currencies[i]); } // Peek the top of the stack cout << "Top of the stack: " << currencyStack.peek() << endl; // Perform three pops in succession cout << "Popping three elements: "; for (int i = 0; i < 3; i++) { cout << currencyStack.pop() << " "; } cout << endl; // Print contents of the stack cout << "Contents of the stack: "; currencyStack.print(); // Push five objects from the start of the objects array to the stack for (int i = 0; i < 5; i++)
Can you finish the code pleaseaccording to the instruction
-
- For the stack, perform the following operations in order -
-
- Push seven (7) objects starting from the array index 13 onwards to the stack.
- Peek the top of the stack - print the result.
- Perform three (3) pops in succession.
- Print the contents of the stack.
- Push five (5) more objects from the start of the objects array to the stack.
- Pop twice in succession.
- Print the contents of the stack.
-
- For the queue, perform the following operations in order -
-
- Enqueue the seven (7) objects at odd indexes starting from index 5 in the array.
- Peek the front and end of the queue - print the results.
- Perform two (2) dequeues in succession.
- Print the contents of the queue.
- Enqueue five (5) more objects from the index 10 in the array.
- Dequeue three times in succession.
- Print the contents of the queue.
-
- End the program with a leaving message of your choice. Remember to clean up before the program ends.
- Restrict all your input / output to the main driver program only, except for the existing screen print inside the Currency print methods.
- For the stack, perform the following operations in order -
#include <iostream>
#include "Currency.h"
#include "SinglyLinkedList.h"
#include "Stack.h"
#include "Queue.h"
using namespace std;
int main() {
// Welcome message
cout << "Welcome to the demonstration of ADTs by [your full name]" << endl << endl;
// Create the Currency array
Currency currencies[20] = {
Currency(57.12),
Currency(23.44),
Currency(87.43),
Currency(68.99),
Currency(111.22),
Currency(44.55),
Currency(77.77),
Currency(18.36),
Currency(543.21),
Currency(20.21),
Currency(345.67),
Currency(36.18),
Currency(48.48),
Currency(101.00),
Currency(11.00),
Currency(21.00),
Currency(51.00),
Currency(1.00),
Currency(251.00),
Currency(151.00)
};
// Create SinglyLinkedList object
SinglyLinkedList<Currency> currencyList;
// Add first 7 objects to the linked list in reverse order
for (int i = 6; i >= 0; i--) {
currencyList.addFirst(currencies[i]);
}
// Search for Kr 87.43 followed by Kr 44.56 - print the results of each
cout << "Search for Kr 87.43: " << (currencyList.search(Currency(87.43)) ? "Found" : "Not found") << endl;
cout << "Search for Kr 44.56: " << (currencyList.search(Currency(44.56)) ? "Found" : "Not found") << endl;
// Remove node containing Kr 111.22 followed by the node at index 2
currencyList.remove(Currency(111.22));
currencyList.removeAt(2);
// Print contents of the list
cout << "Contents of the list: ";
currencyList.print();
// Add next 4 objects to the list
for (int i = 8; i < 12; i++) {
currencyList.add((i % 5), currencies[i]);
}
// Remove two objects at indexes (countCurrency % 6) and (countCurrency / 7)
int countCurrency = currencyList.size();
currencyList.removeAt(countCurrency % 6);
currencyList.removeAt(countCurrency / 7);
// Print contents of the list
cout << "Contents of the list: ";
currencyList.print();
// Create Stack object
Stack<Currency> currencyStack;
// Push seven objects starting from array index 13 to the stack
for (int i = 13; i < 20; i++) {
currencyStack.push(currencies[i]);
}
// Peek the top of the stack
cout << "Top of the stack: " << currencyStack.peek() << endl;
// Perform three pops in succession
cout << "Popping three elements: ";
for (int i = 0; i < 3; i++) {
cout << currencyStack.pop() << " ";
}
cout << endl;
// Print contents of the stack
cout << "Contents of the stack: ";
currencyStack.print();
// Push five objects from the start of the objects array to the stack
for (int i = 0; i < 5; i++)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps