please write C++ program to simulate any two of the followingautomatonSimulation+SW Exercise: Write three C++ programs to simulate each of the following automaton a,b Show transcribed image text Simulation+SW Exercise: Write three C++ programs to simulate each of the following automaton a,b
Answer
//C++ program
#include<iostream>
using namespace std;
bool automata1(string str){
int state=0;
for(int i=0;i<str.length();i++){
char ch = str[i];
if(state==0 &&ch==’a’)state = 1;
else if(state==0 &&ch==’b’)state = 0;
else if(state==1 &&ch==’a’)state = 0;
else if(state==1 &&ch==’b’)state = 1;
}
if(state==0)return true;
OR
OR