QuestionQuestion

3. Requirements
The requirements to complete the lab are summarized below.
1. Draw a diagram of your state machine.
2. Create an executable program simState (based on C source code) that is able to respond to the commands described below.
3. Your program will be presented with zero or more commands from stdin (each on a line by itself) and must respond precisely as specified for each command as listed below.

No Commands:
Before any commands are issued to your program, it should print out the starting state.
One/Zero Commands:
These commands (a `0' or a `1' on a line by itself) must print to stdout the name of the next state given the supplied input, and update the current state.
Change command:
The change command is invoked by the letter `c' followed by a `1' or a `0' followed by the name of a state (i.e. a single letter in the range A–H). This command modifies the state machine such that the `0' (or `1') command applied to the current state will cause the machine to change to the named state and that this change is the state machine configuration will continue. This command should produce no output.
Print command:
The print command is invoked with the single letter `p'. It should print to stdout the state machine configuration as currently specified (i.e. including changes that may have been made with change commands) in the same format that your state machine was specified with.
Garbage Identify command:
This command is invoked with the single letter `g'. It should identify all states that are reachable or unreachable from the current state. It always produces output to stdout.
If all states are reachable, it should output No garbage. Otherwise, it should output
Garbage: <unreachable states> where <unreachable states> is the list of the state names that are no longer reachable.
Delete command:
This command is invoked with `d', optionally followed by the name of a state to delete.
When the ‘d’ command is invoked without the optional argument, it should delete (i.e. mark as “deleted”) all un-deleted states that are unreachable. If there are no such unreachable un-deleted states, it should print:
No states deleted.
Otherwise, it should print the message:
Deleted: <list of deleted states>
If the ‘d’ command is followed by an argument that it the valid name of a state, it should print out either the message:
Deleted.
if the state is not reachable or already deleted. Otherwise, it should print out the message
Not Deleted
If the state is successfully deleted, it should no longer appear in the list of states produced by the Print command and it should be disallowed as a final argument to the Change command.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>

#define TRUE 1
#define FALSE 0

/**
* a state
*/
struct State {
    int allowed; // allow to connect
    int connection; // number of connection to this state
    // don't count the connection to itself
    char name; // name of the state
    struct State * to0; // pointer to a connected state with value 0
    struct State * to1; // pointer to a connected state with value 1
};
typedef struct State State;

/**
* a node in the linked list
*/
struct Node {
    State * state;
    struct Node * next; // pointer to next node
};
typedef struct Node Node;

/**
* the linked list
*/
struct List {
    Node * head;
};
typedef struct List List;

/**
* data in the program
*/
struct Data {
    List * list;
    char start; // name of the starting state
};
typedef struct Data Data;

/**
* create a new state
* @param name
* @return
*/
State * newState(char name);

/**
* create a new node
* @param state
* @return
*/
Node * newNode(State * state);

/**
* create a new list
* @return
*/
List * newList();

/**
* find a node from the list
* @param list
* @param name
* @return
*/
Node * findNode(List * list, char name);

/**
* find a node from the list
* crate a new one if the node cannot be found
* @param list
* @param name
* @return
*/
Node * getNode(List * list, char name);


/**
* set up a state
* @param nfr
* @param nt0
* @param nt1
*/
void setupState(Node * nfr, Node * nt0, Node * nt1);

/**
* add node to the list
* @param n
* @param ll
*/
void addToList(Node * n, List * ll);

/**
* rad data from file
* @param file
* @return
*/
Data readData(FILE * file);

/**
* print the state
* @param data
*/
void printStates(Data data);

/**
* print the welcome message
* @param data
*/
void printFirstMessage(Data data);

/**
* reconnect a state to another state
* @param nf
* @param nt
* @param direction
*/
void redirect(Node * nf, Node * nt, char direction);

/**
* show garbage
* @param data
*/
void garbage(Data data);

/**
* delete unreachable state
* @param data
*/
void deleteUnreachedState...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$37.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats