Simulating automata

cliftonite

Diamond Member
Jul 15, 2001
6,899
63
91
Working on a project which requires me to simulate two deterministic automata and then find the union of them both.

I have a somewhat working code just to create the dfa and then check the input to see if the input is valid. However it doesnt seem to be working as it is supposed to. Can someone take a look at it and tell me what I am doing wrong?

Also how can I put this in a function so that I can call on it in the main to create 2 dfas? something like Dfa x = new dfa(). Is it possible to do that? Thanks.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
Try the below:
Change line 40 cin>>transition[0][y]; to: cin>>transition[y][1];
Change line 51 curr_state=transition[0][curr_state]; to: curr_state=transition[curr_state][0];
Change line 53 curr_state=transition[curr_state][0]; to : curr_state=transition[curr_state][1];
 

cliftonite

Diamond Member
Jul 15, 2001
6,899
63
91
Originally posted by: singh
Try the below:
Change line 40 cin>>transition[0][y]; to: cin>>transition[y][1];
Change line 51 curr_state=transition[0][curr_state]; to: curr_state=transition[curr_state][0];
Change line 53 curr_state=transition[curr_state][0]; to : curr_state=transition[curr_state][1];



Thanks singh, that seems to have fixed it Now how can I make this a function so that I can call it as many times as i need to create multiple machines?
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
I wouldn't advise putting it into a function because it will be very messy. Instead, create a DFA class to represent a DFA "object". Create a couple of functions inside the class to do what you're doing in main(). For instance, one function can get input from the user to describe the DFA. The second function will "test" a given string and return true/false and tell you if the string was accepted or not. Then, from your main, create as many DFA instances as you need, and call their input functions to build the DFA. Then, get input from the user in main() and call the DFA's test function and it will tell you if the string was accepted or not.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |