2. If the user chooses to input a string, your program then reads in the string.
ID: 3563870 • Letter: 2
Question
2. If the user chooses to input a string, your program then reads in the string. After
reading in the string, your program prints it. Then your program processes the
entire string on the DFA, one character at a time, in the following manner.
Your program must begin in the start state of the DFA and print out the
name of that state (q1 or q0).
After each character from the string is processed on the DFA, your program
must print out the character and the name of the current state of the DFA.
Even if your DFA is in a trap state, your program must do this for each
character in the string until it reaches the end of the string.
To simplify your program, you should check the ASCII code of each character of
the string and process on the DFA accordingly.
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int state;
char choice;
char input[30];
cout << "Would you like to enter a string? Y=Yes, N=no ";
cin >> choice;
if (choice = 'Y'){
cout << "Please enter the string: ";
cin >> input;
cout << "You entered: " << input << endl;
switch (input){
case 'input[0]=='w'':
state = 2;
cout << state;
case 'input[1]=='.'
}
}
return 0;
}
I'm stuck on how to process one character at a time of the string? Should i use like a 100 if/else if statements?
Explanation / Answer
you can get length of string by stringname.len() function and then you can use loop for processing it
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.