Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website...

Free

70.2K

Verified Solution

Question

Programming

Write a DFA simulator using the C++ programming language. Pleaserefer to the following UDACITY website if you do knot know C++.This is a free online tutorial for learning C++.

  1. Read your DFA from a textfile. First line contains a list ofthe final states (as integers), separated by a space. Rest of filecontains the transitions in form: startstate, blank, symbol read,blank, tostate
  2. Prompt user for name of file.
  3. From there, program prompts the user for strings to test foracceptance on DFa.
  4. Show the trace of the transitions through the machine alongwith whether the string is accepted or rejected.
  5. Continue reading strings until user enters \"quit.

Example input file... (ab)*

0

0a1

ob2

1a2

1b0

2a2

2b2

Total of five (5) files: c++ file; output file (text file);input file (textile containing the DFa); a diagram of the DFA; ascreen shot illustrating that your code compiled correctly withtimestamp.

Answer & Explanation Solved by verified expert
3.6 Ratings (525 Votes)

#include

#include

using namespace std;

int main()

{

    srand(time(0));

    int max = 1 + rand() % 15;

    int i = 0;

    while (i < max) {

        char c = 'a' + rand() % 2;

        cout << c << \" \";

        i++;

        if (c == 'a'){

            if (i == max)

                cout << \"YES\n\";

while (i < max) {

                c = 'a' + rand() % 2;

                cout << c << \" \";

                i++;

                if (c == 'a' && i == max) {

                    cout << \"\nYES\n\";

}

                else if (i == max) {

                    cout << \"\nNO\n\";

                }

            }

        }

        else {

            while (i < max) {

                c = 'a' + rand() % 2;

                cout << c << \" \";

                i++;

            }

            cout << \"\nNO\n\";

        }

    }

return 0;

}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students