Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)
Question
Book Icon
Chapter 18, Problem 11PC
Program Plan Intro

File Compare

Program Plan:

Main.cpp:

  • Include required header files
  • Inside “main ()” function,
    • Create an object “ifile” for input file stream
    • Create an object “ofile” for output file stream.
    • Create two class templates “q1” and “q2” to hold characters
    • Declare variables “char1” and “char2”
    • Till the end of file,
      • Enqueue a character from file1.
    • Till the end of file,
      • Enqueue a character from file2.
    • Close both the files.
    • Assign “true” to a Boolean variable “status”.
    • Do until both the queue becomes empty,
      • Dequeue a character from 1st queue “q1”.
      • Dequeue a character from 2nd queue “q2”.
      • Check if both the characters are not equal.
        • If the condition is true then, assign “false” to the Boolean variable.
    • Check if the status is true,
      • If the condition is true then, print “The files are identical”.
      • If the condition is not true then, print “The files are not identical”.

Dynqueue.h:

  • Include required header files.
  • Create template class
  • Declare a class named “Dynqueue”. Inside the class,
    • Inside the “private” access specifier,
      • Create a structure named “QueueNode”.
        • Create an object for the template
        • Create a pointer named “next”.
      • Create two pointers named “front” and “rear”.
      • Declare a variable.
    • Inside “public” access specifier,
      • Declare constructor and destructor.
      • Declare the functions “enqueue ()”, “dequeue ()”, “isEmpty ()”, “isFull ()”, and “clear ()”.
  • Declare template class.
  • Give definition for the constructor.
    • Assign the values.
  • Declare template class.
  • Give definition for the destructor.
    • Call the function “clear ()”.
  • Declare template class.
  • Give function definition for “enqueue ()”.
    • Make the pointer “newNode” as null.
    • Assign “num” to newNode->value.
    • Make newNode->next as null.
    • Check whether the queue is empty using “isEmpty ()” function.
      • If the condition is true then, assign newNode to “front” and “rear”.
      • If the condition is not true then,
        • Assign newNode to rear->next
        • Assign newNode to “rear”.
      • Increment the variable “numItems”.
  • Declare template class.
  • Give function definition for “dequeue ()”.
    • Assign temp pointer as null.
    • Check if the queue is empty using “isEmpty ()” function.
      • If the condition is true then print “The queue is empty”.
      • If the condition is not true then,
        • Assign the value of front to the variable “num”.
        • Make front->next as “temp”.
        • Delete the front value
        • Make temp as front.
        • Decrement the variable “numItems”.
  • Declare template class.
  • Give function definition for “isEmpty ()”.
    • Assign “true” to a Boolean variable
    • Check if “numItems” is true.
      • If the condition is true then assign “false” to the variable.
    • Return the Boolean variable.
  • Declare template class.
  • Give function definition for “clear ()”.
    • Create an object for template.
      • Dequeue values from queue till the queue becomes empty using “while” condition.

Blurred answer
Students have asked these similar questions
A queue and a deque data structure are related concepts. Deque is an acronym meaning "double-ended queue." With a deque, you may insert, remove, or view from either end of the queue, which distinguishes it from the other two. Use arrays to implement a deque
Elections Problem Description   Elections are going on, and there are two candidates A and B, contesting with each other. There is a queue of voters and in this queue some of them are supporters of A and some of them are supporters of B. Many of them are neutral. The fate of the election will be decided on which side the neutral voters vote. Supporters of A and supporters of B make attempt to win the votes of neutral voters. The way this can be done is explained below: 1. The voter queue is denoted by three characters, viz {-, A, B}. The - denotes neutral candidate, A denotes supporter of candidate A and B denotes supporter of candidate B. 2. Supporters of A can only move towards the left side of the queue. 3. Supporters of B can only move towards the right side of the queue. 4. Since time is critical, supporters of both A and B will move simultaneously. 5. They both will try and influence the neutral voters by moving in their direction in the queue. If supporter of A reaches the…
LINKED LIST IN PYTHON Create a program using Python for the different operations of a Linked List. Your program will ask the user to choose an operation. 1. Create a List -Ask the user how many nodes he/she wants. -Enter the element/s -Display the list -Back to menu 2. Add at beginning -Ask for the element to be inserted. -Display the list -Back to menu 3. Add after -Ask for the element to be inserted. -Ask for the position AFTER which the element is to be inserted -Display the list -Back to menu 4. Delete -Ask for the element (data) to be deleted -If found, delete the node with that data. -If multiple values, delete only the first element found -If not found, display that the element is not found -back to menu 5. Display -Display the list 6. Count -Display the number of elements 7. Reverse -Reverse the list and display it 8. Search -Ask the user for the element (data) to be searched -Display a message if the element is found or not 9. Quit -Exits the program

Chapter 18 Solutions

Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)

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