Concept explainers
In class, we developed pseudocode for a DFA evaluator:
string alpha = "a b c";
int state_cnt = 4;
int start = 1;
bool final[] = {F,T,F.T,F};
int cur = start;
char *s = "abaab";
//This is used somewhere in code
if(final[cur]);
int trans[state.cnt +1][alpha.length()] = { {0,0,0}, {2,0,2}, {0,3,2},{1,0,4},{3,1,3}}
while(*s != '10' && cur != 0}{
cur = trans[cur][alpha.find(*s)];
s++;
}
Write a C++ program to read a DFA's details from a file provided as a command line argument (not a prompt where the user is asked to type a filename) and determine whether each provided string is in its language.
The DFA file is formatted as a number of lines:
-
Line 1: number of states (eg, 7 indicates states 1-7 along w/ state 0, the "no-transition" state)
-
Line 2: initial state
-
Line 3: the final states as a space separated list
-
Line 4: alphabet string (each character is a member of the alphabet)
-
Line 5 begins the transition table, one line for each state starting with state 1. Each line is a list of space separated integers indicating to which state to transition on a character from the alphabet
-
Afterward, each line is a non-empty string of characters from the alphabet to validate against the DFA. If the line is blank, assume that means the empty string. Please note that "blank" lines still have a newline character sequence at the end… just don't want you to mistake a newline at the end of a file as a blank line.
For example, the file on the right details the DFA from the table on the left…
7 1 3 7 ab 3 4 2 5 0 0 5 7 1 2 4 3 1 0 abaa a baab bbbbaaaa aba baabb |
The output of the program should be one line for each of the test strings in the DFA file. Each line should begin with "good" or "bad " indicating the string is or is not, respectively, accepted by the DFA. After this is an additional space followed by the test string.
The exact output for the example DFA file above is…
bad abaa good a bad baab bad <empty> bad bbbbaaaa bad aba good baabb |
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- #include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if…arrow_forwardIn C++ Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switch (exchange) the values of the first and last elements of the array.arrow_forwardIN C++ Write code that: creates 3 integer values - one can be set to 0, the other two should NOT multiples of one another (for example 3 and 6, or 2 and 8) take you largest value and perform a modulus operation using the smaller (non zero) value as the divisor print out the result. create an alias for the string type call the alias "name" then create an instance of the "name" class and assign it a value using an appropriate cout statement - print out the value Please screenshot your input and output, as the format tends to get messed up. Thank you!arrow_forward
- Given the following declaration : char msg[100] = "Department of Computer Science"; What is printed by: strcpy_s(msg, "University"); int len = strlen(msg); for (int i = len-3; i >0; i--) { msg[i] = 'x'; } cout << msg;arrow_forward#include <stdio.h>#include <limits.h> int findMissingUtil(int arr[], int low, int high, int diff){ if (high <= low)return INT_MAX; int mid = low + (high - low)/2; if (arr[mid+1] - arr[mid] != diff)return (arr[mid] + diff); if (mid > 0 && arr[mid] - arr[mid-1] != diff)return (arr[mid-1] + diff); if (arr[mid] == arr[0] + mid*diff)return findMissingUtil(arr, mid+1, high, diff); return findMissingUtil(arr, low, mid-1, diff);} int findMissing(int arr[], int n){int diff = (arr[n-1] - arr[0])/n; return findMissingUtil(arr, 0, n-1,diff);} int main(){int arr[] = {120001, 120013, 120025, 120037, 120049, 120061,120085,120097,120109,120121};int n = sizeof(arr)/sizeof(arr[0]);printf("The missing element is %d", findMissing(arr, n));return 0;} ______________________________________________________________________________ Convert the code above into Pseudocodearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education