Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 16, Problem 5PP
Program Plan Intro

  • Include required library files.
  • Define a class named “StackOverflowException”.
    • Inside the access specifier “public”,
      • Define a constructor to assign the message
      • Declare a parameterized constructor to assign “msg” to message.
      • Define a function “display” to return message.
    • Inside the access specifier “private”.
      • Declare a string variable “message”.
  • Define a class named “StackEmptyException”.
    • Inside the access specifier “public”,
      • Define a constructor to assign the message
      • Declare a parameterized constructor to assign “msg” to message.
      • Define a function “display” to return message.
    • Inside the access specifier “private”.
      • Declare a string variable “message”.
  • Define a class named “Stack”.
    • Declare an integer array and variable.
    • Inside the access specifier “public”,
      • Define a constructor to assign “-1” to “top”.
      • Define a “push()” function.
        • “try” block to check the top is equal to “3”.
          • The condition is true, throw exception.
          • Otherwise increment the top and the value is assigned to stack.
        • “catch” block to display the error message.
      •  Define a “pop()” function.
        • “try” block to check the top is equal to “-1”.
          • The condition is true, throw exception.
        • Otherwise decrement the top and return the value.
        • “catch” block to display the error message.
  • Define a “main()” function.
    • Create an object for class “Stack”.
    • Then check the “push()” and “pop()” function.

Blurred answer
Students have asked these similar questions
Change the following code so that when player wins the game, the game continues by creating new GameGUI with the same player. However the player's starting position is same, everything else should be reseted. public static void main(String[] args) {        Labyrinth labyrinth = new Labyrinth(10);        Player player = new Player(9, 0);        Random rand = new Random();        Dragon dragon = new Dragon(rand.nextInt(10), 9);        JFrame frame = new JFrame("Labyrinth Game");        GameGUI gui = new GameGUI(labyrinth, player, dragon);         frame.setLayout(new BorderLayout());        frame.setSize(600, 600);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.add(gui, BorderLayout.CENTER);        frame.pack();        frame.setResizable(false);        frame.setVisible(true);    } public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon;    private Timer timer;    private long…
Create a menu item which restarts the game. Also add a timer, which counts the elapsed time since the start of the game level. When the restart is pressed, the restarted game should ask the player' name  (in the GameGUI constructor) and set the score of player to 0 (player.setScore(0)), and the timer should restart again. And create a logic so that if the player loses his life (checkGame if the condition is false), then save this number together with his name into two variables. And display two buttons where one quits the game altogether (System.exit(0)) and the other restarts the game. public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon;     private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");    private final ImageIcon dragonIcon = new ImageIcon("data/images/dragon.png");    private final ImageIcon wallIcon = new ImageIcon("data/images/wall.png");    private final ImageIcon…
Please original work Analyze the complexity issues of processing big data What are five complexities and talk about the reasons they make the implementation complex. Please cite in text references and add weblinks
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning