Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this exercise you are to write a program in C++ that reads a text file containing a number of words and displays the words

For this exercise you are to write a program in C++ that reads a text file containing a number of words and displays the words on the screen in reverse order using a stack. A pseudo?code outline for the program is given below:

-

Begin main

display a prompt for the file name

read in the file name

try to open the file

if (the file fails to open)

print an error message on the screen and exit

fi

do

read in a word from the file

if (the file read fails)

terminate (break) the loop

fi

Push the word onto the stack

od

close the file

while the stack is not empty

display the top stack word on the screen followed by a space

pop the top value from the stack

elihw

End main

-

(Statements are closed by their words backwards e.g if statement is closed by fi)

-

Do not implement the stack using a class or struct or with STL. The stack must be implemented using a fixed size array of words and an index integer for indicating the top of the stack. The stack array and index should be global variables. A word can be a string or a c?string (i.e. a character array). You can assume no word is more than 20 characters long. The stack functions (i.e. push(), top(), pop(), isEmpty() ) should be implemented below the main() and prototyped above the main().

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_2

Step: 3

blur-text-image_3

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago