Overview:- The purpose of this assignment is to implement a simple finite state
ID: 3013653 • Letter: O
Question
Overview:- The purpose of this assignment is to implement a simple finite state machine (more correctly, a finite state automation) using high level programming language.
Description:- Write a C++ program to implement a finite state machine which accepts a series of input strings typed in by user and determines whether or not each input contains the substring "1101".
Note the input alphabet for this assignment is I={0,1}. You must make a decision in the design of your program how to handle characters entered by a
user that do not belong in the input alphabet. Document your decision using comments in your source code.
As an example, test your machine on the string "11a01b"
The following items must be submitted
1. A finite state machine for your program
2. A listing of your source code.
3. A sample execution output screen with enough test strings to exhibit the functionality of your program
Explanation / Answer
#include<stdio.h>
int main()
{
char line[150];
int i, j;
printf("Enter a string: ");
gets(line);
for(i = 0; line[i] != ''; ++i)
{
while (!(line[i] >= '0' && line[i] <= '1'))
{
for(j = i; line[j] != ''; ++j)
{
line[j] = line[j+1];
}
line[j] = '';
}
}
printf("Output String: ");
puts(line);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.