In: Computer Science
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website if you do knot know C++. This is a free online tutorial for learning C++.
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; a screen shot illustrating that your code compiled correctly with timestamp.
#include <iostream>
#include <time.h>
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;
}