Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please include comments and explain Write a C++ program to implement a stack and a queue . Implement both the stack and Queue using fixed

Please include comments and explain

Write a C++ program to implement a stack and a queue . Implement both the stack and Queue using fixed arrays ( declare your stack arrays size 25 and your queue array size 15 . Implement it so that it is easy to change and recompile).

Design your program to read in a file of text called text.txt. The file will contain sentences the consist of words, punctuation marks, and numbers.

  • Extract each word from the input file push it each word onto the stack (ignore numbers and punctuation marks) until the stack becomes full. Stop pushing words onto the stack when it fills up.
  • Then pop each word from the stack one word at and time and enqueue each word into the queue. If the queue fills up before all the words are popped from the stack start dequeuing the words from the queue and write each word to the output file until the queue is empty then resuming the enqueue (until all words are popped from the stack) and added to the queue . Repeat this process until all words are read from the input file and written to the output file. Flush all remaining words from the stack and then the queue when the last word is read from the input file (.e.g, the stack may not be full when last word is encountered). Upon dequeueing each word from the queue print it to a file called "text_out.txt. Print no more than 10 words per line of output to the output file, compute and print the average word length and the total word count to the screen.

Average word length : 99

Total Word count : 99

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions