Purchase Solution

A simple C++ CARDIAC simulator

Not what you're looking for?

Ask Custom Question

Write the worst CARDIAC simulator of all time (in C++) that tells the user how to execute only a single instruction typed as a 3 digit number by the user.

The user should be prompted to type in a 3 digit number. Then print to the screen whatever the CARDIAC Instruction Decoder box would show had that been the instruction. Below are 2 example runs of such a program.

Enter a 3 digit CARDIAC instruction: 493
Shift accumulator left 9 digits, then right 3 digits

Enter a 3 digit CARDIAC instruction: 265
Add the contents of cell 65 to the accumulator

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.

Code must use if statements. Do not use loops and arrays.

Purchase this Solution

Solution Summary

This solutions shows how to implement a very simple CARDIAC machine simulator. It demonstrates the basic principles of using integer arithmetic to parse an integer command which is common in machine simulators.

Solution Preview

The key to this solution is splitting up the instruction that the user entered into the various parts. This is done using the / and % operators. The / operator does integer division. That is, it divides the two numbers and then throws the remainder away. So the result of 3/2 is 1. We can use this feature ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

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

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.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

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.