Write a program using structures and posters to implement the finite state machi
ID: 3819003 • Letter: W
Question
Write a program using structures and posters to implement the finite state machine described in the table below. The program should repeatedly display the current state ID number, current output value, then ask for a new input value. Follow a similar procedure to the lab 12 assignment Start at state ID 0. Example output (highlighted text indicates example input): Current state ID: 0 Current output z: 4 Enter input value: 2 Current state ID: 2 Current output z: 15 Enter input value: Write a program that will ask the user to enter their name. The program should then create a string with the text: "Hello , have a great day!", replacing with the entered name. (Also make sure to keep the spaces). The program should then print the string. Use functions from the library.Explanation / Answer
1.PART 1
typedef struct {
int currState;
int output;
int input;
int nextState;
static stateTransMatrixRow_t stateTransMatrix[] =
/*current_state_id output_state input next_state_id*/
{0, 4, 0,0},
{0, 4, 1,1},
{0, 4, 2,2},
{1, 8, 0,1},
{1, 8, 1,2},
{1, 8, 2,0},
{2, 15, 0,2},
{2, 15, 1,3},
{2, 15, 2,3},
{3, 16, 0,3},
{3, 16, 1,0},
{3, 16, 2,1}
};
#define ENTRY_STATE 0 //to start at state id 0
int main(int argc, char *argv[]) {
int userInput ;
for(int i = 0; i < sizeof(stateTransMatrix)/sizeof(stateTransMatrix[0]); i++) {
printf("Current State ID %d ", stateTransMatrix[i].currState);
printf("Current Output z %d ", stateTransMatrix[i].output);
scanf("Enter input value %d",userInput);
stateTransMatrix[i].nextState = userInput;
}
}
2.PART 2 (using string handling functions)
1.PART 1
typedef struct {
int currState;
int output;
int input;
int nextState;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.