Question

in c++ language, using quincy compiler Write a program that will read in 12 characters from...

in c++ language, using quincy compiler

Write a program that will read in 12 characters from the keyboard between a – z in lowercase. These letters will be inserted into a queue (imported from the Queue.h header file). When the 12th character has been entered, the queue will serve the characters one at a time to a character variable, which will push the values, one at a time, into a stack (using code imported from the Stack.h header file) and then popped off to the screen (using a standard output statement), thus reversing the order.

Bonus: 10% if the letters can be read into a vector that sorts the letters into reverse alphabetical order, printing them after the reversed list.

  • A .cpp file called Reverser.cpp that accomplishes the tasks outlined in the specifications above
  • The header files Queue.h and Stack.h
0 0
Add a comment Improve this question Transcribed image text
Answer #1

You did not provide code for Stack and Queue classes, so here I’m writing this code based on pure assumptions on those two classes. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please read the comments and do the necessary actions if needed, if still having troubles, provide your Stack and Queue files and I will update it as needed.

#include <iostream>

#include "Queue.h"

#include "Stack.h"

using namespace std;

int main() {

                //count of characters to read

                int count=12;

                char c;

                //asking for 12 characters

                cout<<"Enter "<<count<<" characters: ";

                //creating a Queue of characters

                Queue<char> que;

                //reading 12 values and enqueuing to the queue.

                //assuming your Queue class has a method called enqueue(), if it

                //is something else, replace 'enqueue' with your method name

                for(int i=0;i<count;i++){

                                cin>>c;

                                que.enqueue(c);

                }

                //now creating a Stack of characters

                Stack<char> stk;

                //looping and dequeing each character from queue, pushing to stack

                for(int i=0;i<count;i++){

                                //assuming queue has a method named dequeue(), if not, replace with

                                //your file name, if dequeue is not a value returning function, and you

                                //have a front() method, then assign que.front() value to c, and then

                                //call dequeue()

                                c=que.dequeue();

                                //pushing to stack

                                stk.push(c);

                }

                cout<<"Reversed: ";

                //now popping and displaying the characters from stack until it is empty

                while(!stk.is_empty()){

                                //if your pop method is not value returning and you have a top() method

                                //instead, then print the value of stk.top() to screen and then call stk.pop()

                                cout<<stk.pop()<<" ";

                }

                cout<<endl;

               

                return 0;

}

Add a comment
Know the answer?
Add Answer to:
in c++ language, using quincy compiler Write a program that will read in 12 characters from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • Write a C++ Program to do following: 1. Read every character from file char.txt using "get"...

    Write a C++ Program to do following: 1. Read every character from file char.txt using "get" and write it to a file char.bak using "put" 2. Read every second character from file char.txt using "get" and write it to a file charalternate.txt using "put" and "ignore" 3. Take input from user for offset and number of characters. For example if user enters 5 for offset and 10 for number of characters, then your program should copy 10 bytes from file...

  • Write a program in java to read a string object consisting 300 characters or more using...

    Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters.(Use String class methods). a, Determine the length of the string count the number of letters in the strings , count the number of numeric object d. Calculate the number of special character e. Compute the ratio of the numeric to the total f....

  • USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in...

    USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in a file of text and convert some of the letters to another letter using the following array: char key[27] = “efghijklmnopqrstuvwxyzabcd”; This means that if you encounter the letter ‘a’, then you will replace it with the letter ‘e’,etc. If you encounter any other characters in the input file (example: ‘A’ or space, etc, you will write them as is. You will write each...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • In C++ write a complete and correct x++ program that generates student email addresses and prints...

    In C++ write a complete and correct x++ program that generates student email addresses and prints them to the screen based upon the data found in an input file, called students . txt. Each line of the space, followed by the student’s last name. Every email address is to be of the form [email protected]. In general, each username has four parts in this order: (i) the student; last name in lowercase letters; (ii) a number between 10- 99 generated at...

  • Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...

    Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...

  • Write a C++ program that reads text from a file and encrypts the file by adding...

    Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT