Question: 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
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
(Backwards words are the statement being closed, e.g if statements with a fi)
The stack must be implemented using a fixed size array of words and an index integer for indicating the top of the stack.
Thank you in advance for your help!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
