Question
In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozitfollowed by between zero or more Whatzits.
In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozitfollowed by between zero or more Whatzits. A Whoozit is the character 'x' followed by between one or more 'y's. A Whatzit is a 'q' followed by either a 'z' or a 'd', followed by a Whoozit.
You need to design and implement two programs, one in a non-declarative language (C or C++)and the other in a declarative language (Scheme or Prolog). Both the programs should have the following features:
1. The program should ask the user to Enter an alien word:, read the input as a string, and check whether or not it is a valid word(Blurb). If it is valid, it prints "The word is fine.", otherwise it prints "The word is a mess!".
2.The program should loop and ask the user for new input until they enter a valid blurb.
Sample Output:
Enter an alien word: qxxyyyy The word is a mess!
Enter an alien word :xyyyyqzqd The word is a mess!
Enter an alien word:xyyyyyqzxyyyThe word is fine.
Hint:
1.Start by trying to generate Whoozits,Whatzits, and Blurbs by hand and on paper. Be sure to follow that order. Once you have a feeling for thestructure of the language, then start to think about how you might program it.
2.Once you have the program, test forWhoozits first, followed by Whatzits, and then Blurbs. For each method, test it by running it on known valid strings as well as some invalid ones.
3.For Scheme, it is suggested that you review the input_and_output.rkt sample program from the first module on functional programming. This program shows how to perform a loop that reads in data and processes it. You may find the following forms useful:
a.(read) to read a string.
b.(string->list) to convert the string into a list of characters,
c. (displayHello)to write Hello to the screen.
d.(begin) to help with displaying an output while not breaking out of the running procedure.
4.For Prolog, you can use the built-ins like
a.read(S) to read a string into S,
b.string_chars(S, L) to convert the string into a list of characters,
c.write(Hello) to write Hello to the screen.
d.append(L1, L2, L) to break the list L into all possible sublists L1 & L2.
e.repeat, cut (!), and fail to implement a loop until a condition is met.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started