In: Computer Science
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
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
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
#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.