document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Simpletron code
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. //SML OPERATION CODES. I\'m not sure if these are needed but I\'ll include them for now.
  7. const int read{10};
  8. const int write{11};
  9.  
  10. const int load{20};         //load a word from a specific location in memory into the accumulator.
  11. const int store{21};        //store a word from the accumulator to a specific location in memory.
  12.  
  13. const int add{30};
  14. const int subtract{31};
  15.  
  16. const int divide{32};
  17. const int multiply{33};
  18.  
  19. const int branch{40};       //branch to a specific location in memory.
  20. const int branchneg{41};    //branch to a specific location in memory if the accumulator is negative.
  21.  
  22. const int branchzero{42};   //branch to a specific location in memory is zero.
  23.  
  24. const int halt{43};         //stop the program; task completed.
  25.  
  26. //variables for section a
  27. int a{};
  28. int b{};
  29. int loca{0};                 //memory location a
  30. int locb{loca + 1};          //memory lcoation c
  31. int locc{locb + 1};
  32. int calculateA{};
  33. int calculateB{};
  34. int locresult{};
  35. int c{};
  36.  
  37. //variables for section b
  38. int avg{};
  39.  
  40. int num[7];
  41. int* numPtr;                  //hopefully will point to the numbers inputted into sectionB but we will see
  42.  
  43. int loci{};
  44. int storei{};
  45. int storeavg{};
  46.  
  47. int locd{};
  48. int loce{};
  49. int locf{};
  50. int locg{};
  51.  
  52. void intro() {
  53.     //intro message fro 8.16 whoops
  54.     cout << "*** Welcome to Simpletron! ***\\n"
  55.         << "\\n*** Please enter your program one instruction ***"
  56.         << "\\n*** (or data word) at a time. I will type the ***"
  57.         << "\\n*** location number and a question mark (?).  ***"
  58.         << "\\n*** You then type the word for the location.  ***"
  59.         << "\\n*** Type the sentinel -99999 to stop entering ***"
  60.         << "\\n*** your program. ***" << endl;
  61. }
  62.  
  63. void sectionA() {
  64.     do {    //while the inputs are not negative numbers
  65.         cout << "a: ";
  66.         cin >> a;
  67.  
  68.         cout << "b: ";
  69.         cin >> b;
  70.  
  71.         if (a < 0 || b < 0) {
  72.             cout << "input terminated." << endl;
  73.         }  else {
  74.             calculateA = (read * 100) + loca;
  75.             cout << "Reading a. . . +" << calculateA << endl;
  76.  
  77.             calculateB = (read * 100) + locb;
  78.             cout << "Reading b. . . +" << calculateB << endl;
  79.  
  80.             calculateA = (load * 100) + loca;
  81.             cout << "Loading a. . . +" << calculateA << endl;
  82.  
  83.             calculateB = (add * 100) + locb;
  84.             c = a + b;
  85.             cout << "Adding  b. . . +" << calculateB << endl;
  86.  
  87.             locresult = (store * 100) + locc;
  88.             cout << "Storing c. . . +" << locresult << endl;
  89.  
  90.             cout << "Finished! c = " << c << endl;
  91.  
  92.             loca += 3;
  93.             locb += 3;
  94.             locc += 3;
  95.         }
  96.     } while (a > 0 && b > 0);
  97. }
  98.  
  99. void sectionB() {
  100.     loci = (read * 100) + (locc + 1);
  101.  
  102.     for (int i{1}; i < 8; i += 1) {
  103.         cout << "Number " << i << ": ";
  104.         cin >> a;
  105.  
  106.         storei = (store * 100) + (loci - 1000);
  107.         numPtr = &num[i];
  108.  
  109.         cout << "Reading number " << i << ". . . +" << loci << endl;
  110.         cout << "Storing number " << i << ". . . +" << storei << endl;
  111.  
  112.         avg += a;
  113.         loci += 1;
  114.         storei += 1;
  115.     }
  116.     cout << "\\nLoading numbers . . . +" << *(numPtr + 1) << endl;
  117.     cout << "Adding  numbers . . . +0000" << endl;
  118.     cout << "\\nGot it! Average . . . " << (avg / 7) << endl;
  119.  
  120.     cout << "\\nStoring Average . . . " << storeavg << endl;
  121.     cout << "Section A halted  . . . +" << 4300 + (storeavg - 2100);
  122. }
  123.  
  124. void sectionC() {
  125.     int x{};
  126.     int max{};
  127.     cout << "Enter a series of numbers (+ or -), type -1 when series is complete." << endl;
  128.     while (x != -1) {
  129.         if (x == -1) {
  130.             cout << "Finished! Largest number is " ;
  131.         } else {
  132.             cout << "+";
  133.             cin >> x;
  134.  
  135.             cout << "Loading numbers . . . +" << (load * 100);
  136.         }
  137.     }
  138. }
  139.  
  140. int main() {
  141.     //sectionA();
  142.     sectionB();
  143.     //sectionC();
  144. }
  145.  
  146.  
  147. /*
  148.     a) Use a sentinel controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered.
  149.     b) Use a counter controlled loop to read seven numbers, some positive and some negative, and compute and display their average.
  150.     c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many number should be processed.
  151. */
');