Question: Question 1 : Vector Manipulation Write a C + + program that performs the following operations on a std::vector: Initializes the vector with integers from
Question : Vector Manipulation
Write a C program that performs the following operations on a std::vector:
Initializes the vector with integers from to
Uses an iterator to traverse the vector and doubles the value of each element.
Inserts the value at the th position in the vector.
Deletes the third element from the vector.
Prints the final contents of the vector using an iterator.
Question : Stack Operations
Implement a C program to simulate a backtracking mechanism using std::stack. Your program should:
Prompt the user to enter a series of commands: forward or back.
When the user enters forward, prompt them to enter a URL and push it onto the stack.
When the user enters back, pop the last URL from the stack and display it simulating a browser back action. If the stack is empty, display a message indicating there are no more URLs to go back to
The program should exit when the user enters exit.
Question : Queue Simulation
Write a C program that uses a std::queue to simulate a customer service system where customers are served in the order they arrive. The program should:
Allow the user to add customer names to the queue by entering names.
Allow the user to process a customer by dequeuing the next customer and displaying their name.
Continue accepting new customers or processing the queue until the user decides to exit.
Display the number of customers remaining in the queue before exiting.
Question : List Operations
Create a C program that performs operations on a std::list. Your program should:
Populate the list with integers from to
Remove all even numbers from the list.
Sort the remaining elements in descending order.
Use an iterator to print the final contents of the list.
Question : Implementing a Class with Vectors
Define a C class named Library that represents a collection of books. Use a std::vector to store the names of books in the library. Your class should have the following functionalities:
A method to add a book to the library.
A method to remove a book from the library by name. If the book is not found, print an appropriate message.
A method to display all books currently in the library.
Question : Custom Stack Class
Implement a template class named CustomStack that mimics the behavior of a stack using std::vector as its underlying container. Your class should support generic data types and include the following methods:
push: Adds an element to the top of the stack.
pop: Removes the top element from the stack. If the stack is empty, print an appropriate message.
top: Returns the top element of the stack without removing it If the stack is empty, print an appropriate message.
isEmpty: Returns true if the stack is empty, otherwise false.
For each question, ensure that you include proper error handling and input validation as necessary. These questions are designed to test a range of skills from basic STL usage to more complex class design and template programming.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
