fork download
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <iterator>
  4. #include <fstream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. const int N = 100; // Line amount
  9. const int n = 5; // Rule amount
  10.  
  11. int rule = 0, length = 0;
  12.  
  13. void reader(int &head, string &tape, string a[N][n]);
  14.  
  15. int main()
  16. {
  17. int head, position;
  18. string tape;
  19. string p, d = "0";
  20. string a[N][n] = { "" };
  21. reader(head, tape, a);
  22. position = head - 1; // variable position
  23. p = tape[position]; // variable in the line
  24. while (d != "X")
  25. {
  26. for (int y = 0; y < length; y++)
  27. if ((d == a[y][0]) && (p == a[y][1]))
  28. {
  29. tape[position] = a[y][2][0];
  30. if (a[y][3] == "L") // if string equals L (or R) it switches/moves
  31. position--;
  32. else
  33. position++;
  34. p = tape[position];
  35. d = a[y][4];
  36. y = length;
  37. }
  38. for (int j = 0; j < rule; j++)
  39. {
  40. cout << tape[j];
  41. //Sleep(1);
  42. }
  43. cout << endl;
  44. }
  45. system("PAUSE");
  46. return 0;
  47. }
  48. void reader(int &head, string &tape, string a[N][n])
  49. {
  50. string filename;
  51. cout << "which file do you want to open?" << endl;
  52. cin >> filename;
  53.  
  54. ifstream df(filename.c_str());
  55. df >> head;
  56. //cout << head << endl;
  57. df >> tape;
  58. rule = tape.size(); // how many symbols we have in our line
  59. //cout << tape << endl;
  60. for (int i = 0; i < N; i++)
  61. if (df >> a[i][0])
  62. {
  63. //cout << a[i][0] << ' ';
  64. for (int j = 1; j < n; j++)
  65. {
  66. df >> a[i][j];
  67. //cout << a[i][j] << ' ';
  68. }
  69. //cout << endl;
  70. }
  71. else
  72. {
  73. length = i; //how many lines of rules we have
  74. i = N;
  75. }
  76. //cout << rule << endl;
  77. //cout << length << endl;
  78. //cout << tape[23] << endl;
  79. df.close();
  80. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty