Purchase Solution

A C++ CARDIAC simulator with memory

Not what you're looking for?

Ask Custom Question

Implement a CARDIAC machine simulator in C++, that will:

- Keep track of CARDIAC memory cells in an array of 100 integers (0-99).
- Keep track of the bug location; which could be an index into the memory array. Watch out for cells 0 and 99; they are special.
- Read the input tape from a file that starts with a number telling you how many items are on the tape.
- Output to the screen.

Running instruction 9xx exits the program.

An example run of your application would look something like this.

input.txt (This is our first CARDIAC program with 946 instead of 900 and 002 instead of the blank.)
18
002
800
030
004
020
130
021
200
022
631
023
531
024
321
025
946
002
820

Acceptable screen output:
3
2
1
0

Operation codes are as follows:

Code Abbreviation Meaning
0 INP Copy input to memory.
1 CLA Copy memory to accumulator.
2 ADD Add memory to accumulator.
3 TAC Move bug if accumulator < 0.
4 SFT Shift accumulator left then right.
5 OUT Copy memory to output.
6 STO Copy accumulator to memory.
7 SUB Subtract memory from accumulator.
8 JMP Backup bug to 99 then move bug.
9 HRS move bug and stop computing.

Purchase this Solution

Solution Summary

This solution provides a CARDIAC simulator that uses an array for the machine memory. It is a good example of how to write a machine simulator.

Solution Preview

This program is slightly complicated. At a high level it does three things:

1) Setup and initialize the CARDIAC simulator.
2) Run the CARDIAC machine.
3) Output the state of the machine when everything is done.

Let us look at each of these three stages individually.

First, setting up the machine is not too complicated. We declare several variables that will be used in the operation of the machine, ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.