Question: PROBLEM STATEMENT: Given a five button character combination lock; write a program which will simulate the behavior of the lock when five characters are entered.
PROBLEM STATEMENT:
Given a five button character combination lock; write a program which will simulate the behavior of the lock when five characters are entered. The actions are unlock if correct sequence entered and an alarm if the incorrect sequence is entered A table ADT must be used to store the transition table and action table of the finite state machine FSM which models the behavior of the lock. The correct combination will be given in a file. You should define the following
typedef enum STATE
nke, ok ok ok fa fa fa
aState ;
typedef enum EVENT
A B C D E F
anEvent;
Thus your mapping function would look like
int mapping const Pair p;
and your transition table would be declared as
Table Pair STATE, EVENT STATE transitionTable sizeOfTable, transitionMap ;
Similarly for the action table.
Your Table class implementation must have the backing storage of a onedimensional array.Two dimensional arrays are NOT permitted. "pair.h
#ifndef PAIRH
#define PAIRH
more or less from STL library
found in and
template class T class T
class Pair
public:
T first;
T second;
default constructor
Pair: first T second T
constructor that initializes first and second
Pair const T v const T v:
firstv secondv
copy constructor
template typename U typename U
Pair const Pair& X
: first Xfirst second Xsecond
overload
template typename U typename U
Pair& operator const Pair& init
return this Pairinit;
overload
friend bool operator const Pair& lhs const Pair& rhs
return lhsfirst rhsfirst rhsfirst lhsfirst && lhssecond rhssecond ;
overload
friend bool operator const Pair& lhs const Pair& rhs
return lhsfirst rhsfirst && lhssecond rhssecond ;
;
template class T class T
Pair makePair const T& v const T& v
return Pair T Tvv;
#endif
"table.h
#ifndef TABLEH
#define TABLEH
#include
#include "pair.h Pair class
implements a table containing keyvalue pairs.
a table does not contain multiple copies of the same item.
types T and Key must have a default constructor
template class Key, typename T
class Table
public:
typedef Key keytype;
for convenience
private:
table implemented using a one dimensional array of keyvalue pairs
int tableSize;
Pair keytype, T thetable;
int Mapping Key k;
Mapping is a function which maps keys to
an array index; ie a key to address mapping
the idea is that Mapping will act on a given key
in such a way as to return the relative postion
in the sequence at which we expect to find the key
Mapping will be used in the remove, add, lookup.
member functions and copy constructor
public:
only for debugging
void print;
Table int n int map Key k;
map is a function to map key to address
in the implementation
set the function ie have the code line
Mapping map;
populates table with default values
for the class Key and T
bool insert Pair Key, T kvpair ;
return true if item could be added to the
table; false if item was not added.
bool remove const Key aKey ;
erase the keyvalue pair with the specified key
from the table and return if successful
removed item is replaced with default
values for Key and T
T lookUp const Key aKey ;
what if key not in table??
need copy constructor
Table const Table Key, T &initTable ;
need destructor
~Table;
need assignment operator
Table Key, T &
operatorconst Table Key, T &initTable ;
;
#include "table.t
#endif
Actiontable.t and Transitiontable.t Below
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
