Question: I need to write a program in C++ to implement Finite State Automaton SIMILAR TO THE ONE BELOW, it is just an example. A1_number is

I need to write a program in C++ to implement Finite State Automaton SIMILAR TO THE ONE BELOW, it is just an example.

A1_number is the A1 automaton in Finite State Automaton A1, presentation. Return the true if string is accepted. I need to use Automaton A1 in the class examples States: q0, q1; q0 is start state Input alphabet, symbols: 0, 1,.....8, 9, + Final States: q0 (good), q1 (bad) Mapping Function: Returns a state, first parameter is present state and the char on the tape. Automaton Tape the is input_string

This an example of what I need. I need to write a program in C++ to implement Finite State Automaton

bool A1_number(string input_string); int main (void){ cout << " -------------------------------------------------- "; string input_str = "123165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; bool ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl; cout << " -------------------------------------------------- "; input_str = "+123165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl; cout << " -------------------------------------------------- "; input_str = "-123165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; //ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl; cout << " -------------------------------------------------- "; input_str = "-123 165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl; cout << " -------------------------------------------------- "; input_str = "123 165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl;
cout << " -------------------------------------------------- "; input_str = "123+165"; cout << " input_str, same as the A1 Tape: " << input_str << endl; ret_val = A1_number(input_str); cout << " Return value: " << ret_val << " input_str is: " << input_str << endl; system ("PAUSE"); return 0; } // A1_number is the A1 automaton (in our Finite State Automaton A1, presentation. // Return the true if string is accepted. bool A1_number(string input_string) { // Use Automaton A1 in the class examples // States: q0, q1; q0 is start state // Input alphabet, symbols: 0, 1,.....8, 9, + // Final States: q0 (g0od), q1 (bad) // Mapping Function: // returns a state, first parameter is present state and the char on the tape. string A1_map(string state, char symbol); // Automaton Tape: is input_string string state = "q0"; string final_state = "q0"; for (int i=0; i < input_string.length(); i++) { cout << input_string[i]; // use A1_map() to calculate the next state state = A1_map(state, input_string[i]); if ((state == "")) break; //gets out of the loop } if (state == final_state) return true; else return false; } string A1_map(string state, char symbol) { if (state == "q0" && symbol == '0') return "q0"; else if (state == "q0" && symbol == '1') return "q0"; else if (state == "q0" && symbol == '2') return "q0"; else if (state == "q0" && symbol == '3') return "q0"; else if (state == "q0" && symbol == '4') return "q0";

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!