Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ class dfa for deterministic finite automata. The states are numbered 0,1,...0,1,..., and state 0 is always the start state. All states has
Write a C++ class dfa for deterministic finite automata. The states are numbered 0,1,...0,1,..., and state 0 is always the start state. All states has two transitions for characters 0 and 1. The following member functions must be supported:
- typedef std::size_t State;
- typedef std::unordered_set
StateSet; - constructor dfa(std::size_t n = 1, const StateSet &F = StateSet()): returns a new dfa with n1n1 states and accepting state set FF. All transitions go to state 0.
- std::size_t size() const: returns the number of states of this dfa;
- StateSet F() const: returns the accepting state set.
- State delta(State s, char x) const: returns (s,x)(s,x)
- void add_transition(State source, char symbol, State dest): changes transition in state source on input symbol to state dest;
- State eval(const string & w) const: returns the final state of this dfa after reading input string w starting in state 0;
- bool accept(const string & w) const: returns true iff this dfa accepts input string w starting in state 0.
Also overload the input and output operators to allow reading and writing dfas. Use the following format for reading/writing dfas:
n k // number of states and number of accepting states a1 ... ak // accepting states s_1 0 d1 // transitions for each state s_1 1 d2 ... s_n 0 d_{2n+1} s_n 1 d_{2n+2}
We use M to refer to the above description of a dfa M.
Report the output of this main program with input files input1.txt, input2.txt, input3.txt, and input4.txt.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started