Data Structures in C++ A simple \"register machine\", a kind of minimal computer
ID: 3790425 • Letter: D
Question
Data Structures in C++
A simple "register machine", a kind of minimal computer that only supports storing a fixed number of values
make whole program please(by using class command : public ~~{... } and vector.)
You may assume that command names and arguments are always separated by at least one space character.
You should bear in mind that we might want to add new commands later on, so think about how to make your program easily extensible in that way (e.g., a huge if-else chain is not very extensible).
In this assignment youre going to build a simple "register machine. a kind of minimal computer that only supports storing a fixed number of values (ie.. no randomly-accessible "main memory") Your machine will consist of an input loop that reads lines of input from the user and then executes them. stopping when the user quits (by executing the stop command). Each line of input consists of a command followed by 1 to 3 arguments Arguments can be either: Immediate integer values (positive or negative) Register names a through d (ie.. this machine only supports four registers For some commands, a register name may be required in certain argument positions. Heres a sample transcript from the official solution implementation (lines starting with are user input: everything else is output printed by the program) store 1 a store 2 b print a print b add a b c print. c comp a b d No command with that name exists cmp a b d print, d stop Command Description store X r Store x into register r(a. b. c.or d) print r Print the value in register r add x y d Add xand yand store the result in d (xand ymay be either. but dmust be a register) sub x y d Subtract y from xand store the result in d mul x y d Multiply xand yand store the result in d Compare xand y and store into d cmp X y d O if they are equal, -1 if a b. orlif a b You may assume that command names and arguments are always separated by at least one space character. You should bear in mind that we might want to add new commands later on. so think about how to make your program easily extensible in that way (e.g.. a huge if-else chain is not very extensible)Explanation / Answer
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
void store(int arr[], char reg, int val){ arr[reg - 'a'] = val; }
void print(int arr[], char reg)
void sum(int,int);
void sub(int,int);
void show(int,int);
void mul(int,int);
void cmp(int,int);
int main()
{
vector <int> v1;
vector<int> v2;
vector<int> v3;
int i=0;
cout<<"sum of numbers ";
sum(v1,v2);
cout<<"subtraction of numbers ";
sum(v1,v2);
cout<<"multiplication of numbers ";
sum(v1,v2);
cout<<"comparison of numbers ";
cmp(v1,v2);
}
void sum(int v1,sum v2)
{
}
void sub(int v1,sum v2)
{
}
void mul(int v1,sum v2)
{
}
void cmp(int v1,sum v2)
{
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.