Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 15, Problem 12PP
Program Plan Intro
Priority Queue
Program Plan:
queue.h:
- Include required header files.
- Create a namespace named “queuesavitch”.
- Create a structure.
- Declare a variable and a pointer.
- Declare a class “Queue”.
- Inside “public” access specifier.
- Declare the constructor and destructor.
- Declare the functions “add ()”, “remove ()”, “empty ()”.
- Inside the “protected” access specifier,
- Create a pointer “front” that points to the head of the linked list.
- Create a pointer “back” that points to the other end of the linked list.
- Inside “public” access specifier.
- Create a structure.
queue.cpp:
- Include required header files.
- Create a namespace named “queuesavitch”.
- Declare the constructor.
- Inside the parameterized constructor,
- Declare the temporary point that moves through the nodes from front to the back.
- Create a pointer “temp_ptr_new” that is used to create new nodes.
- Create new nodes.
- Assign “emp_ptr_old->link” to “temp_ptr_old”.
- Using while condition “temp_ptr_old != NULL”.
- Create a new node.
- Assign the temporary old data to the new pointer.
- Assign NULL to the link of temporary new pointer.
- Assign “temp_ptr_new” to “back->link”.
- Assign “temp_ptr_new” to “back”.
- Assign “temp_ptr_old->link” to “temp_ptr_old”.
- Give definition for the destructor.
- Declare a variable “next”.
- Do till the queue is empty.
- Remove the items using “remove ()” method.
- Give definition for “empty ()” to check if the queue is empty or not.
- Return “back == NULL”.
- Give definition for the method “add ()”.
- Check if the queue is empty.
- Create a new node.
- Assign the item to the data field.
- Make the front node as null.
- Assign front as the back.
- Else,
- Create a new pointer.
- Create a new node.
- Assign the item to “temp_ptr->data”.
- Assign “NULL” to “temp_ptr->link”.
- Assign temporary pointer to the link.
- Assign temporary pointer to the back.
- Check if the queue is empty.
- Give definition for the method “remove ()”.
- Check if the queue is empty.
- Print the message.
- Store the value into the variable “result”.
- Create an object “discard” for the pointer “QueueNodePtr”.
- Assign “front” to “discard”.
- Assign the link of front to “front”.
- Check if the front is null.
- Assign null to the back.
- Delete the object “discard”.
- Return “result”.
- Check if the queue is empty.
PriorityQueue.h:
- Include required header files.
- Create a namespace named “queuesavitch”.
- Declare a class “PriorityQueue”.
- Inside “public” access specifier,
- Declare the constructor and destructor.
- Declare the virtual function.
- Inside “public” access specifier,
- Declare a class “PriorityQueue”.
PriorityQueue.cpp:
- Include required header files.
- Create a namespace named “queuesavitch”.
- Declare the constructor and destructor.
- Give function to remove items.
- Check if the queue is empty.
- Print the messge.
- Assing “front->data” to “smallest”.
- Assign “NULL” to “nodeBeforeSmallest”.
- Assign “front” to “previousPtr”.
- Assign the link of front to “current”.
- Using while condition “current != NULL”,
- Check if the data is smaller.
- Assing “current->data” to “smallest”.
- Assign “previousPtr” to “nodeBeforeSmallest”.
- Assign “current” to “previousPtr”.
- Assign “current->link” to “current”.
- Check if the data is smaller.
- Create an object “discard”.
- Check if the node is null.
- Assign “front” to “discard”.
- Assign the link of front to “front”.
- Check if the link is equal to back.
- Assign “back” to “discard”.
- Assign “nodeBeforeSmallest” to “back”.
- Assign “NULL” to “back->link”.
- Else,
- Assign “nodeBeforeSmallest->link” to “discard”.
- Assign “discard->link” to “nodeBeforeSmallest->link”.
- Check if front is equal to null.
- Assign “NULL” to “back”.
- Delete the object “discard”.
- Return the smallest item.
- Check if the queue is empty.
main.cpp:
- Include required header files.
- Inside the “main ()” function,
- Create an object for “PriorityQueue”.
- Add the integers to the queue using “add ()” method.
- While “(!que.empty())”,
- Call the function “que.remove()”.
- Declare a character variable.
- Get a character.
- Return the statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem Statement
You are working as a Devops Administrator.
Y
ou’ve been
t
asked to deploy a multi
-
tier application on Kubernetes Cluster. The application is a NodeJS application
available on Docker Hub with the following name:
d
evopsedu/emp
loyee
This Node
JS application works with a mongo database. MongoDB
image
is available
on
D
ockerHub with the following name:
m
ongo
You are required to deploy this application on Kubernetes:
•
NodeJS is available on port 8888 in the container
and will be reaching out to por
t
27017 for mongo database connection
•
MongoDB will be accepting connections on
port 27017
You must deploy this application using the CL
I
.
Once your application is up and running, ensure you can add an employee from the
NodeJS application and verify by
going to Get Employee page and retrieving your input.
Hint:
Name the Mongo DB Service and deployment, specifically as “mongo”.
I need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergent
I need help in my server client in C language
Chapter 15 Solutions
Problem Solving with C++ (9th Edition)
Ch. 15.1 - Is the following program legal (assuming...Ch. 15.1 - Prob. 2STECh. 15.1 - Is the following a legal definition of the member...Ch. 15.1 - The class SalariedEmployee inherits both of the...Ch. 15.1 - Give a definition for a class TitledEmployee that...Ch. 15.1 - Give the definitions of the constructors for the...Ch. 15.2 - You know that an overloaded assignment operator...Ch. 15.2 - Suppose Child is a class derived from the class...Ch. 15.2 - Give the definitions for the member function...Ch. 15.2 - Define a class called PartFilledArrayWMax that is...
Ch. 15.3 - Prob. 11STECh. 15.3 - Why cant we assign a base class object to a...Ch. 15.3 - What is the problem with the (legal) assignment of...Ch. 15.3 - Suppose the base class and the derived class each...Ch. 15 - Write a program that uses the class...Ch. 15 - Listed below are definitions of two classes that...Ch. 15 - Solution to Programming Project 15.1 Give the...Ch. 15 - Create a base class called Vehicle that has the...Ch. 15 - Define a Car class that is derived from the...Ch. 15 - Prob. 4PPCh. 15 - Consider a graphics system that has classes for...Ch. 15 - Flesh out Programming Project 5. Give new...Ch. 15 - Banks have many different types of accounts, often...Ch. 15 - Radio Frequency IDentification (RFID) chips are...Ch. 15 - The goal for this Programming Project is to create...Ch. 15 - Solution to Programming Project 15.10 Listed below...Ch. 15 - The computer player in Programming Project 10 does...Ch. 15 - Prob. 12PP
Knowledge Booster
Similar questions
- Exercise docID document text docID document text 1 hot chocolate cocoa beans 7 sweet sugar 2345 9 cocoa ghana africa 8 sugar cane brazil beans harvest ghana 9 sweet sugar beet cocoa butter butter truffles sweet chocolate 10 sweet cake icing 11 cake black forest Clustering by k-means, with preprocessing tokenization, term weighting TFIDF. Manhattan Distance. Number of cluster is 2. Centroid docID 2 and docID 9.arrow_forwardChange the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position public class Labyrinth { private final int size; private final Cell[][] grid; public Labyrinth(int size) { this.size = size; this.grid = new Cell[size][size]; generateLabyrinth(); } private void generateLabyrinth() { Random rand = new Random(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // Randomly create walls and paths grid[i][j] = new Cell(rand.nextBoolean()); } } // Ensure start and end are…arrow_forwardChange the following code so that it checks the following 3 conditions: 1. there is no space between each cells (imgs) 2. even if it is resized, the components wouldn't disappear 3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game. Main(): Labyrinth labyrinth = new Labyrinth(10); Player player = new Player(9, 0); Dragon dragon = new Dragon(9, 9); JFrame frame = new JFrame("Labyrinth Game"); GameGUI gui = new GameGUI(labyrinth, player, dragon); frame.add(gui); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; //labyrinth, player, dragon are just public classes private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…arrow_forward
- Make the following game user friendly with GUI, with some simple graphics. The GUI should be in another seperate class, with some ImageIcon, and Game class should be added into the pane. The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return…arrow_forwardDiscuss the negative and positive impacts or information technology in the context of your society. Provide two references along with with your answerarrow_forwardA cylinder of diameter 10 cm rotates concentrically inside another hollow cylinder of inner diameter 10.1 cm. Both cylinders are 20 cm long and stand with their axis vertical. The annular space is filled with oil. If a torque of 100 kg cm is required to rotate the inner cylinder at 100 rpm, determine the viscosity of oil. Ans. μ= 29.82poisearrow_forward
- Make the following game user friendly with GUI, with some simple graphics The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() {…arrow_forwardPlease original work What are four of the goals of information lifecycle management think they are most important to data warehousing, Why do you feel this way, how dashboards can be used in the process, and provide a real life example for each. Please cite in text references and add weblinksarrow_forwardThe following is code for a disc golf program written in C++: // player.h #ifndef PLAYER_H #define PLAYER_H #include <string> #include <iostream> class Player { private: std::string courses[20]; // Array of course names int scores[20]; // Array of scores int gameCount; // Number of games played public: Player(); // Constructor void CheckGame(int playerId, const std::string& courseName, int gameScore); void ReportPlayer(int playerId) const; }; #endif // PLAYER_H // player.cpp #include "player.h" #include <iomanip> Player::Player() : gameCount(0) {} void Player::CheckGame(int playerId, const std::string& courseName, int gameScore) { for (int i = 0; i < gameCount; ++i) { if (courses[i] == courseName) { // If course has been played, then check for minimum score if (gameScore < scores[i]) { scores[i] = gameScore; // Update to new minimum…arrow_forward
- In this assignment, you will implement a multi-threaded program (using C/C++) that will check for Prime Numbers and Palindrome Numbers in a range of numbers. Palindrome numbers are numbers that their decimal representation can be read from left to right and from right to left (e.g. 12321, 5995, 1234321). The program will create T worker threads to check for prime and palindrome numbers in the given range (T will be passed to the program with the Linux command line). Each of the threads works on a part of the numbers within the range. Your program should have some global shared variables: • numOfPrimes: which will track the total number of prime numbers found by all threads. numOfPalindroms: which will track the total number of palindrome numbers found by all threads. numOfPalindromic Primes: which will count the numbers that are BOTH prime and palindrome found by all threads. TotalNums: which will count all the processed numbers in the range. In addition, you need to have arrays…arrow_forwardHow do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.arrow_forwardYou are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning