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

Description of program: I need code that will ask a user to input a string (usin

ID: 3622239 • Letter: D

Question

Description of program:

I need code that will ask a user to input a string (using letters only from my alphabet) than process the string to see if the string is accepted by this machine or is a sting in the language defined by the FA.

When i am done I must display my alphabet letters and the transistion table.

Please Help!

This is what I have so far...

#include <iostream>

#include<stdio.h>

#include<string>

#include <ctype.h>

using namespace std;

int main()

{

char letter, state;

string alpha;

int count;

      cout<<"Input a string: "<<endl;

      cin>>alpha;

      cout<<"THE ALPHABET INPUT ARE: "<< alpha << endl;

      count = alpha.length();

      state = 'x';

      for (letter = 0; letter < count; letter++)

      {

            switch (state)

            {

            case 'x':

                  switch(alpha[letter])

                           {

                              case 'a':

                              state = 'y';

                              cout << "state x for a" << " next state: " << state <<endl;

                              break;

                              case 'b':

                              state = 'z';

                              cout << "STATE X FOR b" << " NEXT STATE: " << state <<endl;

                              break;

default: if (letter != 'a' || letter != 'b')

{

      cout << "Incorrect input. Please re-enter the string: " <<endl;}

      cin >> letter;

                          

}

            break;

            case 'y':

                  switch(alpha[letter])

                              {

                                    case 'a':

                                    state = 'x';

                                    cout << "STATE y FOR a" << " NEXT STATE: " << state <<endl;

                                  break;

                                    case 'b':

                                  state = 'z';

                                  cout << "STATE y FOR b" << " NEXT STATE: " << state <<endl;

                              break;

                                    //default:

                                    //cout << "INCORRECT STRING, PLEASE re enter the string" <<endl;

                         }   

                      break;

                                    case 'z':

                  switch(alpha[letter])

                              {

                                    case 'a':

                                    state = 'z';

                                    cout << "STATE z FOR a" << " NEXT STATE: " << state <<endl;

                                  break;

                                    case 'b':

                                  state = 'z';

                                  cout << "STATE z FOR b" << " NEXT STATE: " << state <<endl;

                              break;

                                    //default:

                                    // cout << "INCORRECT STRING! Please re-enter the string" <<endl;

                                   

                         }

                       break;

             }

       }

      cout << "THE FINAL STATE IS: "<<state<<endl;

      cout << " ";

      switch(state)

      {

      case 'z':

            cout << "THE STRING IS ACCEPTED"<<endl;

            break;

      case 'x':

            cout << "THE STRING IS DENIED"<<endl;

            break;

      case 'y':

            cout << "THE STRING IS DENIED"<<endl;

            break;

      }

}

Explanation / Answer

Dear, 1. First declare require inputs "states" and "letters" [states are: x, y and z & letters are a or b] 2. Take input from user interms of a and b 3. calculate the length of string and stored in count, it checked the string upto string closed 4. Initiate the state to x, as x is a initial state 5. Check with string length is it ends, if ends go to step 10 6. Write the switch case for states x,y and z 7. If the case is 'x': check the letters 'a' or 'b'. 7.1.if the letter is 'a' then check and update the next state i.e., y 7.2 If the letter is 'b' then check and update the next state i.e.,z 8. If the case is 'y': check the letters 'a' or 'b' 8.1 if the letter is 'a' then check and update the next state i.e., x 8.2 If the letter is 'b' then check and update the next state i.e.,z 9.If the case is 'z': check the letters 'a' or 'b' 9.1 if the letter is 'a' then check and update the next state i.e.,z 9.2 If the letter is 'b' then check and update the next state i.e.,z 10. Now check the states in second switch case is it final state or not 10.1 If the case is 'x' state then the string denied 10.2 If the case is 'y' then the string denied 10.3 If the string is 'z' then the string accepts 11. End Need to implement the program in switch cases, first switch case to read strings for going each state to next state of alphabest 'a' or 'b' second switch case for check the final state This program repeates until all letters read using string length Program #include #include #include #include using namespace std; int main() { char letter, state; //need to use letters a or b, and state x, y, and z string alpha; // input string taken from user int count; // count taken for length of string cout