Question: Starter Code: #include Alphatron.h #include int main ( int argc, char * argv [ ] ) { Alphatron a; a . read _ program
Starter Code:
#include "Alphatron.h
#include
int mainint argc, char argv
Alphatron a;
areadprogram;
arunprogram;
return ;
TASK
Your task is to implement a simulation of the Alphatron The simulated computer will read a program from cin, and will execute it when the special word RUN is entered. This means that you can interactively type in a Alphatron program to your simulation program, and enter RUN to run the program you have entered.
All Alphatron programs consist of a series of digit numbers, one number per line, and have the file extension alp. A few example programs have been provided see below
You will complete the task by implementing Alphatron.cpp following the specification given in Alphatron.hThe implementation of the readprogram method has already been provided. To test your program, run the main method in main.cpp and enter a program, followed by RUN.
You should not modify main.cpp for this task. You may need to add methods to Alphatron.h and Alphatron.cpp
You are also given an implementation of the method memorydump which prints out a dump of the current values in memory. You are not required to use this method, but it may be useful for you for debugging purposes.
NOTE: Because of a small design error, and also in order to facilitate programming by human programmers, the Alphatron cannot access a program statement located at memory location and cannot store data there either. Hence, all Alphatron machine code programs start running at the instruction stored in the nd location in memory, ie at memory location
Of course, it's tedious to type in a whole program line by line every time you test. A more convenient way is to store your program in a text file. Then you can either copy and paste the program from the file into the Alphatron as input, or you can redirect the input into your Alphatron program to get cin from the file instead of the keyboard, as we've done in previous programming tasks. You can even, if you really want to automate everything, add the word RUN to the end of the file, as well as any input values!
The following example programs have been provided:
The program counttoalp prints the value of the accumulator, then repeatedly increments the accumulator and prints it out, times in succession. The result is that it prints
The program inputplusalp inputs a number from the keyboard into the accumulator, increments it twice in the accumulator and then prints it out. The result is that it prints out the input number
The program sum.alp reads in two numbers from the keyboard, and prints out their sum.
The program maxofalp reads in two numbers from the keyboard. If the first one is larger, it prints ; if the second one is larger, it prints and if they are equal, it prints
Level
For levels and your task is to write programs in the Alphatron machine language. Your submissions will be two alp programs, called loop.alp and prime.alp. Your files should NOT contain the word RUN, or any inputs!!!
Write the Alphatron program loop.alp, a program which reads in two numbers X and Y The program needs to loop X times, printing Y each time.
I.e if the input is
then the output is
Level
Write the Alphatron program prime.alp. This program reads in a number X and prints out all of the prime numbers, in order, that are smaller or equal to X
For Level you may research online into algorithms to find primes. The simplest one is something like:
for i to X
for j to i
if i is divisible by j break and continue with the i loop
else continue and increment j
if you have finished the j loop, then i is prime, so print it out, then continue with the i loop
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
