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, ok1, ok2, ok3, fa1, fa2, fa3
} 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 one-dimensional array.Two dimensional arrays are NOT permitted. "pair.h"
#ifndef PAIR_H
#define PAIR_H
// more or less from STL library
// found in and
template class T1, class T2>
class Pair
{
public:
T1 first;
T2 second;
// default constructor
Pair(): first( T1()), second( T2())
{}
// constructor that initializes first and second
Pair( const T1 v1, const T2 v2):
first(v1), second(v2)
{}
//copy constructor
template typename U1, typename U2>
Pair ( const Pair& X)
: first( X.first ), second( X.second )
{}
// overload =
template typename U1, typename U2>
Pair& operator=( const Pair& init )
{
return *this = Pair(init);
}
// overload
friend bool operator( const Pair& lhs, const Pair& rhs )
{
return lhs.first rhs.first ||!( rhs.first lhs.first && lhs.second rhs.second );
}
// overload ==
friend bool operator==( const Pair& lhs, const Pair& rhs )
{
return lhs.first == rhs.first && lhs.second == rhs.second ;
}
};
template class T1, class T2>
Pair makePair( const T1& v1, const T2& v2)
{
return Pair T1, T2>(v1,v2);
}
#endif
"table.h"
#ifndef TABLE_H
#define TABLE_H
#include
#include "pair.h"// Pair class
// implements a table containing key/value 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 key_type;
// for convenience
private:
// table implemented using a one dimensional array of key-value pairs
int tableSize;
Pair key_type, T >*the_table;
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 key/value 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 >&
operator=(const Table Key, T > &initTable );
};
#include "table.t"
#endif
Action_table.t and Transition_table.t Below

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!