Question

In: Computer Science

what should this program do? Write a program (Lab8.cpp) that will ask the user for two...

what should this program do?

Write a program (Lab8.cpp) that will ask the user for two file names. You will read the characters from each file and put them in separate queues. Then, you will read each character from each queue and compare it. If every character from both queues is the same, you will print “The files are identical.” Otherwise, you will print “The files are not identical.”

Step-by-Step Instructions

  1. Create a character queue (named queue1) using the Standard Template Library Queue class.
  2. Create a second character queue (named queue2) using the Standard Template Library Queue class.
  3. Ask user for first file name & read into a c-string.
  4. Ask user for second file name & read into a c-string
  5. Open first file for input.
  6. Open second file for input.
  7. Use a loop to read each character (one-at-a-time) from the file and push each character in queue1.
  8. Use a loop to read each character (one-at-a-time) from the file and push each character in queue2.
  9. Close the files.
  10. While the two queues are not empty:
    1. Compare the front character from each of the two queues
    2. Remove (pop) a node from both queues.
  11. If all of the characters were the same from both queues, print “The files are identical.”
  12. Otherwise, print “The files are not identical.”

Test Your Program

I provided text files (fileA1, fileA2, fileB1, fileB2) for your operating system (Go down)

First, run your program using fileA1.txt & fileA2.txt as your input. Your program should report “The files are identical.”

Second, run your program using fileB1.txt & fileB2.txt as your input. Your program should report “These files are not identical.”

What to turn in

  • Lab8.cpp
  • fileA1.txt
  • fileA2.txt
  • fileB1.txt
  • fileB2.txt

Text files:

1- fileA1.txt

One day, a boy was digging in his garden, when he saw a big toe sticking out of the ground. He tried to pick it up, but it was stuck. It wouldn’t budge, so he pulled as hard as he could and it came off in his hand. Then he heard something groan and scamper away.

The boy took the big toe into the kitchen and showed it to his mom.

“That looks nice piece of meat,” she said. “I’ll put it in the soup, and we’ll have it for dinner.”

That night, at the dinner table, the boy’s father scooped the big toe out of the soup and chopped it up into three pieces. The father, the mother and the boy each ate a piece. Then they did the dishes, and when it got dark they went to bed.

The boy fell asleep almost at once. But in the middle of the night, he was rudely awakened by a strange sound. He listened closely. It sounded like there was a voice coming from outside his window and it was calling to him.

“Where is my big toe?” it groaned.

When the boy heard that, he got very scared. But he thought, “It doesn’t know where I am. It never will find me.”

Then he heard the voice once more. Only now it was closer.

“Where is my big toe?” it groaned.

The boy pulled the blankets over his head and closed his eyes. “I’ll go to sleep,” he thought. “When I wake up it will be gone.”

But soon he heard the back door open, and again he heard the voice.

“Where is my big toe?” it groaned.

Then the boy heard footsteps move through the kitchen into the dining room, into the living room, into the front hall. They slowly climbed the stairs. Closer and closer they came. Soon they were in the upstairs hall. Now they were outside his door.

“Where is my toe?” the voice groaned.

The boy watched in horror as his bedroom door opened. Shaking with fear, he threw his bedclothes over his head and listened as the footsteps slowly moved through the dark towards his bed.

Then they stopped.

“Where is my toe?” the voice groaned. “YOU’VE GOT IT!”

Alternate ending
The boy hears the voice calling for its toe, he finds a strange looking creature up inside the chimney. The boy is so frightened he can’t move. He just stands there and stares at it.

Finally, he asks: “W-w-w-what you got such big eyes for?”

The creature answers: “To look you thro-o-o-ugh and thro-o-o-ugh!”

“W-w-w-what you got such big claws for?”

2- fileA2.txt

One day, a boy was digging in his garden, when he saw a big toe sticking out of the ground. He tried to pick it up, but it was stuck. It wouldn’t budge, so he pulled as hard as he could and it came off in his hand. Then he heard something groan and scamper away.

The boy took the big toe into the kitchen and showed it to his mom.

“That looks nice piece of meat,” she said. “I’ll put it in the soup, and we’ll have it for dinner.”

That night, at the dinner table, the boy’s father scooped the big toe out of the soup and chopped it up into three pieces. The father, the mother and the boy each ate a piece. Then they did the dishes, and when it got dark they went to bed.

The boy fell asleep almost at once. But in the middle of the night, he was rudely awakened by a strange sound. He listened closely. It sounded like there was a voice coming from outside his window and it was calling to him.

“Where is my big toe?” it groaned.

When the boy heard that, he got very scared. But he thought, “It doesn’t know where I am. It never will find me.”

Then he heard the voice once more. Only now it was closer.

“Where is my big toe?” it groaned.

The boy pulled the blankets over his head and closed his eyes. “I’ll go to sleep,” he thought. “When I wake up it will be gone.”

But soon he heard the back door open, and again he heard the voice.

“Where is my big toe?” it groaned.

Then the boy heard footsteps move through the kitchen into the dining room, into the living room, into the front hall. They slowly climbed the stairs. Closer and closer they came. Soon they were in the upstairs hall. Now they were outside his door.

“Where is my toe?” the voice groaned.

The boy watched in horror as his bedroom door opened. Shaking with fear, he threw his bedclothes over his head and listened as the footsteps slowly moved through the dark towards his bed.

Then they stopped.

“Where is my toe?” the voice groaned. “YOU’VE GOT IT!”

Alternate ending
The boy hears the voice calling for its toe, he finds a strange looking creature up inside the chimney. The boy is so frightened he can’t move. He just stands there and stares at it.

Finally, he asks: “W-w-w-what you got such big eyes for?”

The creature answers: “To look you thro-o-o-ugh and thro-o-o-ugh!”

“W-w-w-what you got such big claws for?”

“To scra-a-a-tch up your gra-a-a-a-ve!”

“W-w-w-what you got such a big mouth for?”

“To swallow you who-o=o-le!”

“W-w-w-what you got such sharp teeth for?”

“TO CHOMP YOUR BONES!

3- fileB1.txt

Dont ever laugh
As a Hearse goes by
For you may be the next to die
They wrap you up
In a big white sheet
From your head down to your feet
They put you in a big black box
And cover you up with dirt and rocks
And all goes well
For about a week
And then your coffin begins to leak
And the worms crawl in, the worms crawl out
The worms play pinochle on your snout
They eat your eyes, they eat your noes
They eat the jelly between your toes
A big green worm with rolling eyes
Crawls in your stomach and out your eyes
Your stomach turns a slimy green
And puss comes out like whipping cream
You spread it on a slice of bread
And thats what you eat when your dead
And the worms crawl out and the worms crawl in
The worms that crawl in are lean and thin
The ones that crawl out are fat and stout
Your eyes fall in and your hair falls out
Your brain comes tumbling down your snout
And the worms crawl in, the worms crawl out
They crawl all over your dirty snout
Your chest caves in and your eyes pop out
Your brain turns to saurkraut
They invite their friends, and their friends too
They all come down to chew on you
And this is what it is to die, i hope you had a nice goodbye
Did you ever think as a Hearse goes by
That you might be the next to die
And your eyes fall out and your teeth decay
And that is the end of a perfect... day

4-fileB2.txt

Dance 'til you're dead
Heads will roll
Heads will roll
Heads will roll
On the floor
Glitter on the west streets
Silver over everything
The rivers all wet
You're all chrome
Dripping with alchemy
Shiver stop shivering
The glitter's all wet
You're all chrome
The men cry out the girls cry out
The men cry out the girls cry out
The men cry out, oh no
The men cry out the girls cry out
The men cry out the girls cry out
The men cry out, oh no
Off, off with your head
Dance, dance 'til you're dead
Heads will roll
Heads will roll
Heads will roll
On the floor
You came last
Take the past
Shut your eyes
Realize
You came last
Take the past
Shut your eyes
Realize
Glitter on the west streets
Silver over everything
The glitter's all wet
You're all chrome
You're all chrome

Solutions

Expert Solution

#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

int main(){
  ifstream file1, file2;
  string filename1, filename2;
  char file_char, i, j, c;
  queue <char> queue1;
  queue <char> queue2;
  bool no_match = false;
  cout << "\n Please enter the first file name\n";
  cin >> filename1;
  cout << "\n Please enter the second file name\n";
  cin >> filename2;
  file1.open(filename1, ios::in);
  file2.open(filename2, ios::in);
  while (!file1.eof()){
    file1.get(file_char);
    queue1.push(file_char);
  }
  file1.close();
  while (!file2.eof()){
    file2.get(file_char);
    queue2.push(file_char);
  }
  file2.close();
  while (!queue1.empty() && !queue2.empty()){
    i = queue1.front();
    j = queue2.front();
    if(i != j){
      no_match = true;
      break;
    }
    queue1.pop();
    queue2.pop();
  }
  if(no_match){
    cout << "\n The files are not identical.";
  }else {
    cout << "\n The files are identical";
  }
}

including ss of code snippet too.


Related Solutions

Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a program that ask the user for three integers. Use two functions to determine the...
Write a program that ask the user for three integers. Use two functions to determine the largest and smallest number of the three. One function will determine the largest number, and the other function will determine the smallest number. (6 points) In c++ using functions.
Write a Python program to: ask the user to enter two integers: int1 and int2. The...
Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative number,...
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Write a Java program to do the following: Ask the user to enter 10 first names...
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard. 1) Display the list of names one per line on the Console. 2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT