//Simpletron code
#include <iostream>
using namespace std;
//SML OPERATION CODES. I\'m not sure if these are needed but I\'ll include them for now.
const int read{10};
const int write{11};
const int load{20}; //load a word from a specific location in memory into the accumulator.
const int store{21}; //store a word from the accumulator to a specific location in memory.
const int add{30};
const int subtract{31};
const int divide{32};
const int multiply{33};
const int branch{40}; //branch to a specific location in memory.
const int branchneg{41}; //branch to a specific location in memory if the accumulator is negative.
const int branchzero{42}; //branch to a specific location in memory is zero.
const int halt{43}; //stop the program; task completed.
//variables for section a
int a{};
int b{};
int loca{0}; //memory location a
int locb{loca + 1}; //memory lcoation c
int locc{locb + 1};
int calculateA{};
int calculateB{};
int locresult{};
int c{};
//variables for section b
int avg{};
int num[7];
int* numPtr; //hopefully will point to the numbers inputted into sectionB but we will see
int loci{};
int storei{};
int storeavg{};
int locd{};
int loce{};
int locf{};
int locg{};
void intro() {
//intro message fro 8.16 whoops
cout << "*** Welcome to Simpletron! ***\\n"
<< "\\n*** Please enter your program one instruction ***"
<< "\\n*** (or data word) at a time. I will type the ***"
<< "\\n*** location number and a question mark (?). ***"
<< "\\n*** You then type the word for the location. ***"
<< "\\n*** Type the sentinel -99999 to stop entering ***"
<< "\\n*** your program. ***" << endl;
}
void sectionA() {
do { //while the inputs are not negative numbers
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
if (a < 0 || b < 0) {
cout << "input terminated." << endl;
} else {
calculateA = (read * 100) + loca;
cout << "Reading a. . . +" << calculateA << endl;
calculateB = (read * 100) + locb;
cout << "Reading b. . . +" << calculateB << endl;
calculateA = (load * 100) + loca;
cout << "Loading a. . . +" << calculateA << endl;
calculateB = (add * 100) + locb;
c = a + b;
cout << "Adding b. . . +" << calculateB << endl;
locresult = (store * 100) + locc;
cout << "Storing c. . . +" << locresult << endl;
cout << "Finished! c = " << c << endl;
loca += 3;
locb += 3;
locc += 3;
}
} while (a > 0 && b > 0);
}
void sectionB() {
loci = (read * 100) + (locc + 1);
for (int i{1}; i < 8; i += 1) {
cout << "Number " << i << ": ";
cin >> a;
storei = (store * 100) + (loci - 1000);
numPtr = &num[i];
cout << "Reading number " << i << ". . . +" << loci << endl;
cout << "Storing number " << i << ". . . +" << storei << endl;
avg += a;
loci += 1;
storei += 1;
}
cout << "\\nLoading numbers . . . +" << *(numPtr + 1) << endl;
cout << "Adding numbers . . . +0000" << endl;
cout << "\\nGot it! Average . . . " << (avg / 7) << endl;
cout << "\\nStoring Average . . . " << storeavg << endl;
cout << "Section A halted . . . +" << 4300 + (storeavg - 2100);
}
void sectionC() {
int x{};
int max{};
cout << "Enter a series of numbers (+ or -), type -1 when series is complete." << endl;
while (x != -1) {
if (x == -1) {
cout << "Finished! Largest number is " ;
} else {
cout << "+";
cin >> x;
cout << "Loading numbers . . . +" << (load * 100);
}
}
}
int main() {
//sectionA();
sectionB();
//sectionC();
}
/*
a) Use a sentinel controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered.
b) Use a counter controlled loop to read seven numbers, some positive and some negative, and compute and display their average.
c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many number should be processed.
*/