EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
8th Edition
ISBN: 8220100794438
Author: GADDIS
Publisher: PEARSON
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
Program Description:in C language The project is a student management system which maintains student records in a simple text file. Your task is to write a program to save a list of students records in a FILE and then perform several operations on this FILE. Your program will ask user to choose the option from a menu. The 3 major function in menu are: ADD STUDENT FIND STUDENT PRINT LIST Exit How it Works The menu is handled by do while and switch statement. Sample output The Methods to be implemented are as follows: 1. ADDSTUDENT This method will add a new student to the file. It takes 3 parameters ( student name, id, and GPA). Your program must ask the user to enter the details of new students: Name, ID and GPA 2. FINDSTUDENT This method will search for a student with his/her id in the file. If the student is found it will print her/his record to the output. If the student is not found it will print “There is no record of this student in this system” 3. PRINTLIST This method will…
File System: It is highly useful in file system handling where for example the file allocation table contains a sequential list of locations where the files is split up and stored on a disk. Remember that overtime it is hard for an OS to find disk space to cover the entire file so it usually splits these up into chunks across the physical hard drive and stores a sequential list of links together as a linked list. Write an algorithm for the above problem and analyse the efficiency of the algorithm.
C Programming Language Task: Deviation Write a program that prompts the user to enter N numbers and calculates which of the numbers has the largest deviation from the average of all numbers. You program should first prompt the user to enter how many numbers that will specify. The program should then scan for each number, separated by a newline. You should calculate the average value and return the number from the list which is furthest away from this average (to 2dp). Try using dynamic memory functions to store the incoming array of numbers on the heap. Code to build from: + 1 #include 2 #include 3 4 int main(void) { 5 6} 7 Output Example: deviation.c How many numbers? 5 Enter them: 1.0 2.0 6.0 3.0 4.0 Average: 3.20 Largest deviation from average: 6.00
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage