Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We assume the existence of some Alien Language. In this language, the words are created in specific way, following some rules . You do not

We assume the existence of some "Alien Language". In this language, the words are created in specific way, following some rules. You do not need to understand what these words mean. You are just required to write a program which takes as input a string, parses it (i.e., analyzes it), and outputs whether this string is a correct "Alien" word or an incorrect one, obeying the rules we outline below.

RULES

Every word in the "Alien Language" obeys the rules below:

  1. The only characters used in the alien language are lowercase alphabets 'a' to 'z', and three more symbols'@', '#', '|'
  2. A string that contains only one of the lowercase alphabets ('a' to 'z') is a correct word: 'a' to 'z'
  3. If string s is a correct word, then so are s@ and >#
  4. If s and t are correct words, then so are st|
  5. Rules 1 to 4 are the only rules that define a correct word. If a word cannot be verified using these rules, then the word is incorrect.

EXAMPLES

List of correct words

q (from Rule 2)
w (from Rule 2)
q@ (q is correct from Rule 2, q@ is correct from Rule 3)
w# (w is correct from Rule 2, w# is correct from Rule 3)
q@# (q@ is correct from above, q@# is correct from Rule 3)
w#@ (w# is correct from above, w#@ is correct from Rule 3)
q@w#@| (s=q@ and t=w#@ are correct from above, st| is correct from Rule 4)
q@#q@w#@|| (s=q@# and t=q@w#@| are correct from above, st| is correct from Rule 4)
q@#q@w#@||@# (s=q@#q@w#@|| correct from above, then s@# is correct from Rule 2)

List of incorrect words

xyz xyz| xyz$@ @x @@||

There above words are incorrect because they cannot be generated using the 5 rules we listed above.

PROGRAM FLOW

Input

The input consists of a string that is ended by a new-line character. Assume that the input has at most 255 characters and at least 1 character.

Output

The output is a message stating whether the word is CORRECT or INCORRECT.

Termination

After each parsing the program asks the user if he/she wishes to enter a new word. If the answer is 'Y' or 'y' the program continues, otherwise it terminates.

#include  #include  using namespace std; const int MAX_LEN = 256; /* ADD THE RETURN TYPE HERE */ correct_word(/* ADD FORMAL PARAMETER LIST HERE */) { /* ADD YOUR CODE HERE */ /* THIS MUST BE A RECURSIVE FUNCTION */ } int main() { char word[MAX_LEN]; char c; do{ cout > word; if (correct_word(word, 0, strlen(word) - 1)) cout > c; } while (c == 'Y' || c=='y'); return 0; }

Please fill in the code given below and this function must be recursive.

This is the sample output

image text in transcribed

Enter a word: aa The word is CORRECT! Do you want to enter a new word ( 'Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: ab#@#! The word is CORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: xyz The word is INCORRECT! Do you want to enter a new word ('Y','y' for Yes, 'N'/'n' for No)? y Enter a word: a@bb The word is INCORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word : ab#0c#Ild#0e#0f#011###I The word is CORRECT! Do you want to enter a new word ( 'Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: a#@b#@c#! ### The word is INCORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? n Enter a word: aa The word is CORRECT! Do you want to enter a new word ( 'Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: ab#@#! The word is CORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: xyz The word is INCORRECT! Do you want to enter a new word ('Y','y' for Yes, 'N'/'n' for No)? y Enter a word: a@bb The word is INCORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word : ab#0c#Ild#0e#0f#011###I The word is CORRECT! Do you want to enter a new word ( 'Y'/'y' for Yes, 'N'/'n' for No)? y Enter a word: a#@b#@c#! ### The word is INCORRECT! Do you want to enter a new word ('Y'/'y' for Yes, 'N'/'n' for No)? n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions