Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the class LittlePersonComputer shown below. Write a .h and a .cpp with the appropriate parts of your C++code. You should submit files called LittlePersonComputer.h

Implement the class LittlePersonComputer shown below. Write a .h and a .cpp with the appropriate parts of your C++code. You should submit files called LittlePersonComputer.h and LittlePersonComputer.cpp. The UML diagram below shows exactly what you are implementing.

image text in transcribed

Here are what the various methods should do: LittlePersonComputer() : initializes accumulator (ACC), program counter (PC) and all memory slots to 0. Hint: There is NO magic way to initialize all elements of an array to 0 with one statement inside the constructor.

LittlePersonComputer(int instructions[], int numberOfInstructions) : initializes accumulator, program counter to 0. The instruction from the array provided should be copied into the LPCs memory array and any extra slots of memory initialized to 0. (Do not have to worry about getting more than 20 instructions see the appendix for how to add an assertion if you want to make sure you don't work with bad data.)

int getProgramCounter() : return the current value of program counter

int getAccumulator() : return the current value of accumulator

int getCurrentInstruction() : return the next instruction to be run (the memory location indicated by the program counter)

int getMemoryAt(int location) : return the value in memory at the indicated location

void loadProgram(int instructions[], int numberOfInstructions) : the instruction array provided should be copied into the memory array starting at index 0. All memory past the end of the instructions should be set to 0.

void printState() : print the current state of the computer as something like: Accumulator : 20 Program Counter : 2

Memory: 0 1 2 3 4 5 19

504 104 902 0 10 0 0

bool isHalted() : return true if the current instruction is 0, otherwise false

void step() : run the next instruction according to the list of machine codes shown to the right. A couple of hints about how things should work: ? The 100's digit always indicates the basic operation ? The next two digits specify a memory address (xx) or, for 9XX instructions, the IO mode(input/output) ? input/output should read into or print the accumulator's value to/from the console ? store puts the accumulator value into a memory address specified by XX, load copies the value at the memory location XX to the ACC ? add / subtract take the value at a memory address and add to/subtract from the ACC. "104" says add the value at memory address 4 to the ACC, NOT add 4 to the ACC. ? branches (other than 6xx) check the accumulator to make their decision. They either change the PC to xx (if condition is true) OR advance the PC by 1 (if condition is false). ? After running any instruction except a branch, advance the program counter.

LittlePersonComputer memory: int20 accumulator: int programCounter: int LittlePersonComputer0 LittlePersonComputer(instructions, int, numberOfinstructions: int) +getProgramCounter0: int +getAccumulator0: int getCurrentinstruction0: int +getMemoryAt(location int) int +loadProgram(instructions: inti]. numberOfinstructions: int) printState0 step0 +?sHaltedo : bool LittlePersonComputer memory: int20 accumulator: int programCounter: int LittlePersonComputer0 LittlePersonComputer(instructions, int, numberOfinstructions: int) +getProgramCounter0: int +getAccumulator0: int getCurrentinstruction0: int +getMemoryAt(location int) int +loadProgram(instructions: inti]. numberOfinstructions: int) printState0 step0 +?sHaltedo : bool

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

To understand the impact of technology on service process design

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago

Question

e. What difficulties did they encounter?

Answered: 1 week ago