Description of program: I need code that will ask a user to input a string (usin
ID: 3622239 • Letter: D
Question
Description of program:
I need code that will ask a user to input a string (using letters only from my alphabet) than process the string to see if the string is accepted by this machine or is a sting in the language defined by the FA.
When i am done I must display my alphabet letters and the transistion table.
Please Help!
This is what I have so far...
#include <iostream>
#include<stdio.h>
#include<string>
#include <ctype.h>
using namespace std;
int main()
{
char letter, state;
string alpha;
int count;
cout<<"Input a string: "<<endl;
cin>>alpha;
cout<<"THE ALPHABET INPUT ARE: "<< alpha << endl;
count = alpha.length();
state = 'x';
for (letter = 0; letter < count; letter++)
{
switch (state)
{
case 'x':
switch(alpha[letter])
{
case 'a':
state = 'y';
cout << "state x for a" << " next state: " << state <<endl;
break;
case 'b':
state = 'z';
cout << "STATE X FOR b" << " NEXT STATE: " << state <<endl;
break;
default: if (letter != 'a' || letter != 'b')
{
cout << "Incorrect input. Please re-enter the string: " <<endl;}
cin >> letter;
}
break;
case 'y':
switch(alpha[letter])
{
case 'a':
state = 'x';
cout << "STATE y FOR a" << " NEXT STATE: " << state <<endl;
break;
case 'b':
state = 'z';
cout << "STATE y FOR b" << " NEXT STATE: " << state <<endl;
break;
//default:
//cout << "INCORRECT STRING, PLEASE re enter the string" <<endl;
}
break;
case 'z':
switch(alpha[letter])
{
case 'a':
state = 'z';
cout << "STATE z FOR a" << " NEXT STATE: " << state <<endl;
break;
case 'b':
state = 'z';
cout << "STATE z FOR b" << " NEXT STATE: " << state <<endl;
break;
//default:
// cout << "INCORRECT STRING! Please re-enter the string" <<endl;
}
break;
}
}
cout << "THE FINAL STATE IS: "<<state<<endl;
cout << " ";
switch(state)
{
case 'z':
cout << "THE STRING IS ACCEPTED"<<endl;
break;
case 'x':
cout << "THE STRING IS DENIED"<<endl;
break;
case 'y':
cout << "THE STRING IS DENIED"<<endl;
break;
}
}