Question: B) Write a generator in C++ for L = {x | x is a binary number}.[20 pts] My generator.cpp must be used. main: It should
B) Write a generator in C++ for L = {x | x is a binary number}.[20 pts]
My generator.cpp must be used.
main: It should create each string over E = {0,1,2} systematically
(short to long) and pass each string to the recognizer function
created in Part a) above.
Only those strings for which the recognizer returned TRUE
should be displayed.
i.e.
create 0 --> returns TRUE ---> display 0
create 1 --> returns TRUE ---> display 1
create 2 --> returns FALSE
create 00 --> returns TRUE ---> display 00
create 01 --> returns TRUE ---> display 01
create 02 --> returns FALSE
[The challenge here is to figure out how to create
all strings using 0, 1 and 2 systematically, with no repeated
strings. Hint CS311 HW1 using a queue.]
recognizer function: the same one from part a. (copy and use)
Testing: The user must interactively terminate
the execution of the program after at least 20 binary strings
have been displayed although your program should be able to keep on going until the queue overflows. Use the given code:
#include
//---------------------------------------------- // Write a generator in C++ for L = {x | x is a binary number}. //----------------------------------------------
// Copy the recognizer function here from the other file. **
// main: It should create each string over E = {0,1,2} systematically // (short to long) and pass each string to the recognizer function // created in Part a). Hint: use a queue to generate strings // Only those strings for which the recognizer returned TRUE // should be displayed. // Keeps on going until the queue overflows but the user can // terminate the program with control-C // after about 20 strings have been displayed. int main() { **
while(true) { ** }// end of while
}// end of main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
