Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the program should be written in C++. Here some documentation about the question : The Turing Machine is an abstract machine originally described by the

the program should be written in C++.

Here some documentation about the question :

The Turing Machine is an abstract machine originally described by the computer scientist and mathematician Alan Turing (Links to an external site.)in 1936 (years before the first actual computers were built). The Turing Machine is described as follows (I have stolen this description from Wikipedia):

In his 1948 essay, "Intelligent Machinery", Turing wrote that his machine consisted of:

...an unlimited memory capacity obtained in the form of an infinite tape marked out into squares, on each of which a symbol could be printed. At any moment there is one symbol in the machine; it is called the scanned symbol. The machine can alter the scanned symbol, and its behavior is in part determined by that symbol, but the symbols on the tape elsewhere do not affect the behavior of the machine. However, the tape can be moved back and forth through the machine, this being one of the elementary operations of the machine.

An implementation of a Turing Machine is available here. (Links to an external site.) This implementation works as follows:

  • The tape is represented by the row of boxes at the top of the screen. Each tape square can hold one of two marks: either a 0, or a 1.
  • The square the machine has currently selected on is highlighted in purple.
  • Below the tape is a table of "states." These describe the next action the machine will take, based on the mark in the square currently selected. If the mark is 0, the machine will perform the action given on the left-hand column. If the mark is 1, the machine will perform the action given on the right-hand column.
  • Actions are defined as follows:
    1. The first character is either a 0 or a 1. This indicates the mark that the machine wants to leave in the square after it takes the action.
    2. The second character is either an L or an R. This character indicates whether the machine will next select the square to the left or the right of the currently selected square.
    3. The third character is a number from 0 to the number of states defined in the machine. This indicates which state the machine will be in after the current action. This determines which action the machine will take on subsequent moves.
    4. If the machine ever changes to a state that's not defined (0, for example) the machine will halt.

the question :

Here is what you have to implement:

  • A class called TuringMachine that stores a vector that indicates which squares on the tape are marked with a 1. Note: you should not store the entire tape, but simply a vector that gives the indexes at which you can find squares marked with 1. Count the initial square as 0, the squares to the left of it as -1, -2, -3..., and the squares to the right of it as 1, 2, 3...
  • Your TuringMachine class should also contain an instance variable indicating the currently selected square.
  • This class should contain public member functions defined as follows
    1. void moveLeft(). This function selects the square to the left of the currently selected square
    2. void moveRight(). This function selects the square to the right of the currently selected square.
    3. void makeMark(bool mark). This function changes the currently selected square to either 0 or 1, based on whether the bool passed in as a parameter is false (0) or true (1)
    4. bool readSquare(). This function returns a bool indicating the state of the current square. If it is a 0, return false, if it is a 1, return true.
    5. void printMachineInfo(). This function prints out information related to the current condition of the tape. The information consists of a list of the squares that are currently marked with a 1, and the square that is currently selected. Follow this format exactly.
       Tape: [-3, -2, -1, 0, 1, 2] Current square: -1
    6. A constructor that takes no arguments, and creates a new TuringMachine which has no squares marked with 1 and with the square at position 0 currently selected.
    7. You should write a main function that tests the various member functions of your TuringMachine.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions