{"id":6472,"date":"2022-09-03T11:45:00","date_gmt":"2022-09-03T06:15:00","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/"},"modified":"2022-09-03T11:45:00","modified_gmt":"2022-09-03T06:15:00","slug":"solved-turing-machine-simulator-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/","title":{"rendered":"[Solved] Turing Machine Simulator [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-10503750\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"10503750\" data-parentid=\"10503377\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Try something like this:<\/p>\n<pre><code>#include &lt;iostream&gt;\n#include &lt;string.h&gt;\n#include &lt;vector&gt;\n#include &lt;fstream&gt;\n#include &lt;cstdlib&gt;\n#include &lt;stdio.h&gt;\n#include \"tm.h\"\n\nusing namespace std;\n\ntm::tm(char *fn)\n{\n    current = \"\";\n    readFile(fn);\n}\n\nvoid tm::readFile(char *fn)\n{\n    char temp;\n    string word = \"\";\n    ifstream indata;\n    bool blank = false;\n    indata.open(fn); \/\/opens the file\n    if(!indata) \/\/error message if the file is unable to be opened\n    {   \n        cout &lt;&lt; \"Could not open the specified file \\\"\" &lt;&lt; fn &lt;&lt; \"\\\"\" &lt;&lt; endl;\n        exit(1);\n    }\n    indata &gt;&gt; temp;\n    while (!indata.eof())\n    {\n        if (temp == 'Q')\n        {\n            \/\/cout &lt;&lt; \"Q\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n            while (temp != 'A')\n            {\n                if (temp != ',') word += temp;\n                else\n                {\n                    QQ.push_back(word);\n                    word = \"\";\n                }\n                indata &gt;&gt; temp;\n            }\n            QQ.push_back(word);\n            word = \"\";\n        }\n        else if (temp == 'A')\n        {\n            \/\/cout &lt;&lt; \"A\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n            while (temp != 'Z')\n            {\n                if (temp != ',') word += temp;\n                else\n                {\n                    AA.push_back(word);\n                    word = \"\";\n                }\n                indata &gt;&gt; temp;\n            }\n            AA.push_back(word);\n            word = \"\";\n        }\n        else if (temp == 'Z')\n        {\n            \/\/cout &lt;&lt; \"Z\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n            while (temp != 'T')\n            {\n                if (temp != ',') word += temp;\n                else\n                {\n                    ZZ.push_back(word);\n                    word = \"\";\n                }\n                indata &gt;&gt; temp;\n            }\n            ZZ.push_back(word);\n            word = \"\";\n            for (int i = 0; i &lt; (int)ZZ.size(); i++)\n                if (ZZ[i].compare(\" \") == 0)\n                    blank = true;\n            if (blank == false) \/\/no blanks were found in the tape alphabet\n                ZZ.push_back(\" \");\n        }\n        else if (temp == 'T')\n        {\n            \/\/cout &lt;&lt; \"T\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n            bool wasComma = false;\n            vector&lt;string&gt; row;\n            while (temp != 'T' &amp;&amp; temp != 'S')\n            {\n                if (wasComma &amp;&amp; temp == ',') \/\/the last one was a comma\n                {\n                    row.push_back(\" \");\n                    wasComma = false;\n                }\n                else if (temp != ',')\n                {\n                    word += temp;\n                    wasComma = false;\n                }\n                else\n                {\n                    row.push_back(word);\n                    word = \"\";\n                    wasComma = true;\n                }\n                indata &gt;&gt; temp;\n            }\n            row.push_back(word);\n            TT.push_back(row);\n            word = \"\";\n        }\n        else if (temp == 'S')\n        {\n            \/\/cout &lt;&lt; \"S\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n        while (temp != 'F')\n            {\n                if (temp != ',') word += temp;\n                else\n                {\n                    SS = word;\n                    word = \"\";\n                }\n                indata &gt;&gt; temp;\n            }\n            SS = word;\n            word = \"\";\n        }\n        else if (temp == 'F')\n        {\n            \/\/cout &lt;&lt; \"F\" &lt;&lt; endl;\n            indata &gt;&gt; temp;\n            indata &gt;&gt; temp; \/\/skip the :\n            while (!indata.eof())\n            {\n                if (temp != ',')\n                    word += temp;\n                else\n                {\n                    FF.push_back(word);\n                    word = \"\";\n                }\n                indata &gt;&gt; temp;\n            }\n            FF.push_back(word);\n            word = \"\";\n        }\n    }   \n    indata.close();\n    readInput();\n    runAll();\n    return;\n}\n\nvoid tm::readInput()\n{\n    int num, k;\n    cin &gt;&gt; num;\n\n    string temp;\n    getline(cin,temp);\n    getline(cin,temp);\n    for (int i = 0; i &lt; num; i++) \/\/num is the number of rows of input to the machine\n{\n        vector&lt;string&gt; row;\n        string word = \"\";\n        for(k = 0; k &lt; (int)temp.size(); k++)\n        {\n            if (temp[k] != ',')\n                word += temp[k];\n            else if ((int)word.size() &gt; 0)\n            {\n                row.push_back(word);\n                word = \"\";\n            }\n            if (k == (int)temp.size() -1 &amp;&amp; (int)word.size() &gt; 0)\n            {\n                row.push_back(word);\n                word = \"\";\n            }\n    }\n        if (k &gt; 0)\n            input.push_back(row);\n        else \/\/if there is an empty row of input to the machine\n        {\n            vector&lt;string&gt; row;\n            row.push_back(\"e\");\n            input.push_back(row);\n        }\n        getline(cin,temp);\n    }\n\n    return;\n}\n\nvoid tm::runAll()\n{\n    checkForAlphabetBlanks();\n    checkTransitions();\n    checkStart();\n    checkFinal();\n    checkDeterministic();\n    checkAcceptReject();\n    checkInput();\n\n    int currentPosition;\n    string currentState, currentSymbol;\n    bool found, first = true;\n    for (int i = 0; i &lt; (int)input.size(); i++) \/\/for each row of the input\n    {\n        if (first != true)\n            cout &lt;&lt; endl;\n        first = false;\n        currentPosition = 0;\n        currentState = SS;\n        for (int k = 0; k &lt; 1000; k++) \/\/for each character of input, then up to 1000\n        {\n            if (k == 0) \/\/the first time\n            {\n                if (0 &lt; (int)input[i].size()) \/\/we are not past the right of the tape\n                    currentSymbol = input[i][0];\n                else\n                    currentSymbol = \" \";\n                cout &lt;&lt; \"()\" &lt;&lt; SS &lt;&lt; \"(\";\n                for (int g = 0; g &lt; (int)input[i].size(); g++)\n                {\n                    cout &lt;&lt; input[i][g];\n                    if (g != (int)input[i].size() - 1) \/\/it is not the last input\n                        cout &lt;&lt; \",\";\n                    else\n                        cout &lt;&lt; \")\" &lt;&lt; endl;\n                }\n            }\n            if (currentState.compare(FF[0]) == 0) \/\/check if we are accept\n            {\n                cout &lt;&lt; \"ACCEPT\" &lt;&lt; endl;\n                break;\n            }\n            else if (currentState.compare(FF[1]) == 0) \/\/check if we are reject\n            {\n                cout &lt;&lt; \"REJECT\" &lt;&lt; endl;\n                break;\n            }\n            found = false;\n            for (int g = 0; g &lt; (int)TT.size(); g++)\n            {\n                if (TT[g][0].compare(currentState) == 0 &amp;&amp; TT[g][1].compare(currentSymbol) == 0) \/\/same state and symbol as the transition line\n                {\n                    found = true;\n                    currentState = TT[g][2];\n                    input[i][currentPosition] = TT[g][3];\n                    if (TT[g][4].compare(\"R\") == 0) currentPosition++;\n                    else currentPosition--;\n                    \/\/check for out of bounds to the left\n                    if (currentPosition &lt; 0) currentPosition = 0;\n                    cout &lt;&lt; \"(\";\n                    for (int t = 0; t &lt; currentPosition; t++)\n                    {\n                        cout &lt;&lt; input[i][t];\n                        if (t != currentPosition - 1) cout &lt;&lt; \",\"; \/\/not the last one\n                    }\n                    cout &lt;&lt; \")\" &lt;&lt; currentState &lt;&lt; \"(\";\n                    for (int t = currentPosition; t &lt; (int)input[i].size(); t++)\n                    {\n                        cout &lt;&lt; input[i][t];\n                        if (t != (int)input[i].size() - 1) cout &lt;&lt; \",\"; \/\/not the last one\n                    }\n                    cout &lt;&lt; \")\" &lt;&lt; endl;\n                    if (currentPosition &lt; (int)input[i].size()) currentSymbol = input[i][currentPosition]; \/\/not past the right side of the tape\n                    else\n                    {\n                        currentSymbol = \" \";\n                        input[i].push_back(\" \");\n                    }\n                    break;\n                }\n            }\n            if (found == true) \/\/a transition was found\n            {\n                if (currentState.compare(FF[0]) == 0) \/\/check if accept\n                {\n                    cout &lt;&lt; \"ACCEPT\" &lt;&lt; endl;\n                    break;\n                }\n                else if (currentState.compare(FF[1]) == 0) \/\/check if reject\n                {\n                    cout &lt;&lt; \"REJECT\" &lt;&lt; endl;\n                    break;\n                }\n            }\n            else\n            {\n                currentPosition++;\n                cout &lt;&lt; \"(\";\n                for (int t = 0; t &lt; currentPosition; t++)\n                {\n                    cout &lt;&lt; input[i][t];\n                    if (t != currentPosition - 1) cout &lt;&lt; \",\"; \/\/not the last one\n                }\n                cout &lt;&lt; \")\" &lt;&lt; FF[1] &lt;&lt; \"(\";\n                for (int t = currentPosition; t &lt; (int)input[i].size(); t++)\n                {\n                    cout &lt;&lt; input[i][t];\n                    if (t != (int)input[i].size() - 1) cout &lt;&lt; \",\"; \/\/not the last one\n                }\n                cout &lt;&lt; \")\" &lt;&lt; endl;\n                cout &lt;&lt; \"REJECT\" &lt;&lt; endl;\n                break;\n            }\n            if (k == 999)\n                cout &lt;&lt; \"DID NOT HALT\" &lt;&lt; endl;\n        }\n    }\n\n    return;\n}\n\nvoid tm::checkForAlphabetBlanks()\n{\n    for (int i = 0; i &lt; (int)AA.size(); i++)\n    {\n        if (AA[i].compare(\" \") == 0)\n        {\n            cout &lt;&lt; \"The alphabet has a blank space.\" &lt;&lt; endl;\n            exit(1);\n        }\n    }\n    return;\n}\n\nvoid tm::checkTransitions()\n{\n    bool state1, state2, character1, character2;\n\n    for (int i = 0; i &lt; (int)TT.size(); i++)\n    {\n    \/\/check the direction\n        if (TT[i][4].compare(\"R\") != 0 &amp;&amp; TT[i][4].compare(\"L\") != 0)\n        {\n            cout &lt;&lt; \"The only valid directions are R and L.\" &lt;&lt; endl;\n            exit(1);\n        }\n        \/\/check the states\n        state1 = false; state2 = false;\n        for (int k = 0; k &lt; (int)QQ.size(); k++)\n        {\n            if (TT[i][0].compare(QQ[k]) == 0) state1 = true;\n            if (TT[i][2].compare(QQ[k]) == 0) state2 = true;\n        }\n        if (state1 == false)\n        {\n            cout &lt;&lt; \"The state \" &lt;&lt; TT[i][0] &lt;&lt; \" in transition function number \" &lt;&lt; i &lt;&lt; \" is not in the list of states.\" &lt;&lt; endl;\n            exit(1);\n        }\n        if (state2 == false)\n        {\n            cout &lt;&lt; \"The state \" &lt;&lt; TT[i][2] &lt;&lt; \" in transition function number \" &lt;&lt; i &lt;&lt; \" is not in the list of states.\" &lt;&lt; endl;\n            exit(1);\n        }\n        \/\/check the characters\n        character1 = false; character2 = false;\n        for (int k = 0; k &lt; (int)ZZ.size(); k++)\n        {\n            if (TT[i][1].compare(ZZ[k]) == 0) character1 = true;\n            if (TT[i][3].compare(ZZ[k]) == 0) character2 = true;\n        }\n        if (character1 == false)\n        {\n            cout &lt;&lt; \"The character '\" &lt;&lt; TT[i][1] &lt;&lt; \"' in transition function number \" &lt;&lt; i &lt;&lt; \" is not in the tape alphabet.\" &lt;&lt; endl;\n            exit(1);\n        }\n        if (character2 == false)\n        {\n            cout &lt;&lt; \"The character '\" &lt;&lt; TT[i][3] &lt;&lt; \"' in transition function number \" &lt;&lt; i &lt;&lt; \" is not in the tape alphabet.\" &lt;&lt; endl;\n            exit(1);\n        }\n}\n    return;\n}\n\nvoid tm::checkStart()\n{\n    bool in = false;\n    for (int i = 0; i &lt; (int)QQ.size(); i++)\n    {\n        if (SS.compare(QQ[i]) == 0) in = true;\n    }\n    if (in == false)\n    {\n        cout &lt;&lt; \"The start state \" &lt;&lt; SS &lt;&lt; \" is not in the list of states.\" &lt;&lt; endl;\n        exit(1);\n    }\n}\n\nvoid tm::checkFinal()\n{\n    if (FF[0].compare(FF[1]) == 0)\n    {\n        cout &lt;&lt; \"The accept and reject states cannot be the same.\" &lt;&lt; endl;\n        exit(1);\n    }\n    bool accept = false, reject = false;\n    for (int i = 0; i &lt; (int)QQ.size(); i++)\n    {\n        if (FF[0].compare(QQ[i]) == 0) accept = true;\n        if (FF[1].compare(QQ[i]) == 0) reject = true;\n        }\n        if (accept == false)\n        {\n        cout &lt;&lt; \"The accept state \" &lt;&lt; FF[0] &lt;&lt; \" is not in the list of states.\" &lt;&lt; endl;\n        exit(1);\n    }\n    if (reject == false)\n    {\n        cout &lt;&lt; \"The reject state \" &lt;&lt; FF[1] &lt;&lt; \" is not in the list of states.\" &lt;&lt; endl;\n        exit(1);\n    }\n}\n\nvoid tm::checkDeterministic()\n{\n    for (int i = 0; i &lt; (int)TT.size(); i++)\n        for (int k = i+1; k &lt; (int)TT.size(); k++)\n            if (TT[i][0].compare(TT[k][0]) == 0 &amp;&amp; TT[i][1].compare(TT[k][1]) == 0)\n            {\n            cout &lt;&lt; \"The machine cannot proceed deterministically, transitions \" &lt;&lt; i &lt;&lt; \" and \" &lt;&lt; k &lt;&lt; \" are the same.\" &lt;&lt; endl;\n            exit(1);\n        }\n}\n\nvoid tm::checkAcceptReject()\n{\n    for (int i = 0; i &lt; (int)TT.size(); i++)\n    {\n        if (TT[i][0].compare(FF[0]) == 0 || TT[i][0].compare(FF[1]) == 0)\n        {\n            cout &lt;&lt; \"The machine cannot transitions from the accept or reject states.\" &lt;&lt; endl;\n        }\n    }\n}\n\nvoid tm::checkInput()\n{\n    bool exists;\n    for (int i = 0; i &lt; (int)input.size(); i++)\n    {\n        for (int k = 0; k &lt; (int)input[i].size(); k++)\n        {\n            exists = false;\n            for (int g = 0; g &lt; (int)AA.size(); g++)\n            {\n                if (input[i][k].compare(AA[g]) == 0) exists = true;\n            }\n            if (exists == false)\n            {\n                if (input[i][0].compare(\"e\") != 0) \/\/it is not 'e'\n                {\n                    cout &lt;&lt; \"The input character \" &lt;&lt; input[i][k] &lt;&lt; \" is not in the input alphabet.\" &lt;&lt; endl;\n                    exit(1);\n                }\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Turing Machine Simulator [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Try something like this: #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;fstream&gt; #include &lt;cstdlib&gt; #include &lt;stdio.h&gt; #include &#8220;tm.h&#8221; using namespace std; tm::tm(char *fn) { current = &#8220;&#8221;; readFile(fn); } void tm::readFile(char *fn) { char temp; string word = &#8220;&#8221;; ifstream indata; bool blank = false; indata.open(fn); \/\/opens the file if(!indata) \/\/error message if the &#8230; <a title=\"[Solved] Turing Machine Simulator [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\" aria-label=\"More on [Solved] Turing Machine Simulator [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,1795,1794],"class_list":["post-6472","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-computation-theory","tag-turing-machines"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Turing Machine Simulator [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Turing Machine Simulator [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Try something like this: #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;fstream&gt; #include &lt;cstdlib&gt; #include &lt;stdio.h&gt; #include &quot;tm.h&quot; using namespace std; tm::tm(char *fn) { current = &quot;&quot;; readFile(fn); } void tm::readFile(char *fn) { char temp; string word = &quot;&quot;; ifstream indata; bool blank = false; indata.open(fn); \/\/opens the file if(!indata) \/\/error message if the ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-03T06:15:00+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Turing Machine Simulator [closed]\",\"datePublished\":\"2022-09-03T06:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\"},\"wordCount\":16,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"computation-theory\",\"turing-machines\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\",\"name\":\"[Solved] Turing Machine Simulator [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-03T06:15:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Turing Machine Simulator [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Turing Machine Simulator [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Turing Machine Simulator [closed] - JassWeb","og_description":"[ad_1] Try something like this: #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;fstream&gt; #include &lt;cstdlib&gt; #include &lt;stdio.h&gt; #include \"tm.h\" using namespace std; tm::tm(char *fn) { current = \"\"; readFile(fn); } void tm::readFile(char *fn) { char temp; string word = \"\"; ifstream indata; bool blank = false; indata.open(fn); \/\/opens the file if(!indata) \/\/error message if the ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/","og_site_name":"JassWeb","article_published_time":"2022-09-03T06:15:00+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Turing Machine Simulator [closed]","datePublished":"2022-09-03T06:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/"},"wordCount":16,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","computation-theory","turing-machines"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/","name":"[Solved] Turing Machine Simulator [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-03T06:15:00+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-turing-machine-simulator-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Turing Machine Simulator [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=6472"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6472\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=6472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=6472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=6472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}