Assumptions:

R or r is used to denote a reset to initial state

‘.’ is produced as an output when there is no defined transition at the current state of the implemntation for the input that is given

‘.’ is produced whenever r or R is given as an input

#ifndef _IMPL_H_
#define _IMPL_H_

char implementation(char c);

#endif // _IMPL_H_
#include <iostream>
#include "impl.h"

using namespace std;

enum state_type { s0, s1, s2, s3, s4, s5, s6};

static state_type current_state = s0;


char implementation(char c)
{
 const char DOT = '.';
 state_type next_state;
 switch (c)
 {
    case 'R':
    case 'r': next_state = s0;
              current_state = next_state;
              return DOT;
 }
 char output;
 switch (current_state)
 {
     case s0: if (c == 'a')
               {
                  output = 'a';
                  next_state = s1;
               }
              else if (c == 'b')
                   {
                        output = 'b';
                        next_state = s2;
                   }
                   else
                   {
                       output = DOT;
                       next_state = current_state;
                   }
                current_state = next_state;
                return output;
       case s1: if (c == 'b')
               {
                  output = 'c';
                  next_state = s3;
               }
              else
               {
                       output = DOT;
                       next_state = current_state;
                }
                current_state = next_state;
                return output;
        case s2: if (c == 'a')
               {
                  output = 'b';
                  next_state = s3;
               }
              else if (c == 'b')
                   {
                        output = 'c';
                        next_state = s1;
                   }
                   else
                   {
                       output = DOT;
                       next_state = current_state;
                   }
                current_state = next_state;
                return output;

        case s3:  if ( c == 'b')
                  {
                      output = 'b';
                      next_state = s4;
                   }
                   else if (c == 'a')
                        {
                             output = 'c';
                             next_state = s5;
                        }
                        else
                        {
                               output = DOT;
                               next_state = current_state;
                        }
                   current_state = next_state;
                   return output;
        case s4: if (c == 'b')
                 {
                     output = 'c';
                     next_state = s6;
                 }
                 else
                 {
                     output = DOT;
                     next_state = current_state;
                 }
                 current_state = next_state;
                 return output;

        case s5: if (c == 'b')
                 {
                     output = 'b';
                     next_state = s6;
                 }
                 else
                 {
                     output = DOT;
                     next_state = current_state;
                 }
                 current_state = next_state;
                 return output;

        case s6: return DOT;
 }
   return DOT;
}