Tomki

Laba1_1 c++

Feb 28th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. // Laba11.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <stdio.h>
  8. #include <conio.h>
  9.  
  10. using namespace std;
  11.  
  12. class FSM
  13. {
  14. private:
  15.     int numStates = 5;
  16.     int begState = 1;
  17.     int alphabet[2] = { 0, 1 };
  18.     int numEndStates = 1;
  19.     int finState = 4;
  20.     int curState = begState;
  21.  
  22. public:
  23.     bool error;
  24.     FSM() {};
  25.  
  26.     void showState()
  27.     {
  28.         cout << "Current state is : " << getState() << endl;
  29.     }
  30.     int getState()
  31.     {
  32.         return FSM::curState;
  33.     }
  34.     void nextState(char c)
  35.     {
  36.         if (getState() == 1)
  37.         {
  38.             if (c == '0')
  39.                 curState = 2;
  40.             else
  41.                 if (c == '1')
  42.                     curState = 1;
  43.         }
  44.         else if (getState() == 2)
  45.         {
  46.             if (c == '0')
  47.                 curState = 5;
  48.             else
  49.                 if (c == '1')
  50.                     curState = 3;
  51.         }
  52.         else if (getState() == 3)
  53.         {
  54.             if (c == '0')
  55.                 curState = 4;
  56.             else
  57.                 if (c == '1')
  58.                     curState = 2;
  59.         }
  60.         else if (getState() == 4)
  61.         {
  62.             if (c == '0')
  63.                 curState = 2;
  64.             else
  65.                 if (c == '1')
  66.                     curState = 3;
  67.         }
  68.         else if (getState() == 5)
  69.         {
  70.             if (c == '0')
  71.                 curState = 5;
  72.             else
  73.                 if (c == '1')
  74.                     curState = 5;
  75.         }
  76.     }
  77.     bool theEnd()
  78.     {
  79.         if (getState() == finState)
  80.             return true;
  81.         else
  82.             return false;
  83.     }
  84. };
  85.  
  86.  
  87. int main()
  88. {
  89.     char *txt = new char [255];
  90.  
  91.     int i = 0;
  92.     while (cin >> txt[i])
  93.         i++;
  94.     txt[i] = '\0';
  95.  
  96.     i = 0;
  97.     while (txt[i] != '\0')
  98.     {
  99.         if (txt[i] != '0')
  100.             txt[i] = '1';
  101.         cout << txt[i];
  102.         i++;
  103.     }
  104.  
  105.     cout << endl;
  106.  
  107.     FSM avt;
  108.    
  109.     int j = 0;
  110.     while (txt[j] != '\0')
  111.     {
  112.         avt.nextState(txt[j]);
  113.         avt.showState();
  114.         j++;
  115.     }
  116.  
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment