Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Laba11.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <cstdio>
- #include <stdio.h>
- #include <conio.h>
- using namespace std;
- class FSM
- {
- private:
- int numStates = 5;
- int begState = 1;
- int alphabet[2] = { 0, 1 };
- int numEndStates = 1;
- int finState = 4;
- int curState = begState;
- public:
- bool error;
- FSM() {};
- void showState()
- {
- cout << "Current state is : " << getState() << endl;
- }
- int getState()
- {
- return FSM::curState;
- }
- void nextState(char c)
- {
- if (getState() == 1)
- {
- if (c == '0')
- curState = 2;
- else
- if (c == '1')
- curState = 1;
- }
- else if (getState() == 2)
- {
- if (c == '0')
- curState = 5;
- else
- if (c == '1')
- curState = 3;
- }
- else if (getState() == 3)
- {
- if (c == '0')
- curState = 4;
- else
- if (c == '1')
- curState = 2;
- }
- else if (getState() == 4)
- {
- if (c == '0')
- curState = 2;
- else
- if (c == '1')
- curState = 3;
- }
- else if (getState() == 5)
- {
- if (c == '0')
- curState = 5;
- else
- if (c == '1')
- curState = 5;
- }
- }
- bool theEnd()
- {
- if (getState() == finState)
- return true;
- else
- return false;
- }
- };
- int main()
- {
- char *txt = new char [255];
- int i = 0;
- while (cin >> txt[i])
- i++;
- txt[i] = '\0';
- i = 0;
- while (txt[i] != '\0')
- {
- if (txt[i] != '0')
- txt[i] = '1';
- cout << txt[i];
- i++;
- }
- cout << endl;
- FSM avt;
- int j = 0;
- while (txt[j] != '\0')
- {
- avt.nextState(txt[j]);
- avt.showState();
- j++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment