Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C++ code that reads lower case letters of the alphabet (assume they are co

ID: 3760727 • Letter: W

Question

Write C++ code that reads lower case letters of the alphabet (assume they are coming from the input stream, e.g. y x v o ...), one character at a time. If the character is a vowel, i.e. one of {a,e,i,o,u}, is pushed onto a stack, otherwise it is ignored. When there is no more input, print out the characters on the stack so that they are output in the reverse order in which they appeared inthe input. In all cases, you must use loops, as opposed to having repeated statements, to process the letters.

Explanation / Answer

#include<iostream>

#include<stack>

using namespace std;

int main()

{

int temp;

char c;

stack<char> characters;

  

while (true) {

cout << "Input a lowercase character or press any digit to exit: ";

cin >> c;

temp = c;

if(temp>=97 && temp<=122)

{

if(c=='a' || c == 'e' || c == 'i' || c == 'o' || c=='u')

characters.push(c);

}

else if(temp>=48 && temp<=57)

{

cout << "Exitting the program. ";

break;

}

else

cout << "Please input a lowercase character. ";

}

  

cout << "Printing stack contents : ";

  

while(!characters.empty())

{

c = characters.top();

cout << c << " ";

characters.pop();

}

  

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote