STARTING OUT WITH C++ REVEL >IA<
STARTING OUT WITH C++ REVEL >IA<
9th Edition
ISBN: 9780135853115
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 9PC
Program Plan Intro

File Reverser

Program Plan:

Main.cpp:

  • Include required header files.
  • Inside “main ()” function,
    • Create an object “file1” for input file stream.
    • Create an object “file2” for output file stream.
    • Declare a class template
    • Declare character variables named “popChar”, and “ch”.
    • Till the end of file,
      • Push each character into the stack using the function “push ()”.
    • Close “file1”.
    • Until the stack gets empty,
      • Pop the character stack and write it on “file2” using the function “pop ()”.
    • Close “file2”.
    • Open “file2”.
    • Till the end of file,
      • Get a character and print it on the console screen.

DynStack.h:

  • Include required header files.
  • Create a template.
  • Declare a class named “DynStack”. Inside the class
    • Inside the “private” access specifier,
      • Give structure declaration for the stack
        • Create an object for the template
        • Create a stack pointer name “next”.
      • Create a stack pointer name “top”
    • Inside the “public” access specifier,
      • Give a declaration for a constructor.
        • Assign null to the top node.
      • Give function declaration for “push ()”, “pop ()”,and “isEmpty ()”.
  • Give the class template.
  • Give function definition for “push ()”.
    • Assign null to the new node.
    • Dynamically allocate memory for new node
    • Assign “num” to the value of new node.
    • Check if the stack is empty using the function “isEmpty ()”
      • If the condition is true then assign new node as the top and make the next node as null.
      • If the condition is not true then, assign top node to the next of new node and assign new node as the top.
  • Give the class template.
  • Give function definition for “pop ()”.
    • Assign null to the temp node.
    • Check if the stack is empty using the function “is_Empty ()”
      • If the condition is true then print “The stack is empty”.
      • If the condition is not true then,
        • Assign top value to the variable “num”.
        • Link top of next node to temp node.
        • Delete the top node and make temp as the top node.
  • Give function definition for “isEmpty ()”.
    • Assign Boolean value to the variable
    • Check if the top node is null
      • Assign true to “status”.
    • Return the status

Blurred answer
Students have asked these similar questions
In this assignment you are going to create an application that reverses a text file and saves it. This application is a single file application so you do not need to think about additional classes; you will simply have a main.cpp file. Your application should accomplish:   In main, create a stack. Then, open a text file and read its contents into a stack of characters.. The program should then pop the characters from the stack and save them in another text file.  As this is a stack, (LIFO, so last item you put into the stack gets the first one to come out), the new file will be the reverse of the other. So if the text file at first said KHAS, the new file must have SAHK.
File Encryption and DecryptionWrite a program that uses a dictionary to assign “codes” to each letter of the alphabet. Forexample:codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .}Using this example, the letter A would be assigned the symbol %, the letter a would beassigned the number 9, the letter B would be assigned the symbol @, and so forth.The program should open a specified text file, read its contents, then use the dictionaryto write an encrypted version of the file’s contents to a second file. Each character in thesecond file should contain the code for the corresponding character in the first file.Write a second program that opens an encrypted file and displays its decrypted contentson the screen. in phyton
Create class Test in a file named Test.java. This class contains a main program that performs the following actions: Instantiate a doubly linked list. Insert strings “a”, “b”, and “c” at the head of the list using three Insert() operations. The state of the list is now [“c”, “b”, “a”]. Set the current element to the second-to-last element with a call to Tail() followed by a call to Previous()Then insert string “d”. The state of the list is now [“c”, “d”, “b”, “a”]. Set the current element to past-the-end with a call to Tail() followed by a call to Next(). Then insert string “e”. The state of the list is now [“c”, “d”, “b”, “a”, “e”] . Print the list with a call to Print() and verify that the state of the list is correct.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning