Menu

[Solved]Need C Java Please Thank Currently Far Could Implement Header File Cpp File Program Conver Q37034830

Need This In C++ Not Java Please. Thank You!

This Is What I Currently Have So Far. How Could I Implement TheHeader FIle?

Cpp File:

// This program converts a RPN expression to Assembly Code

#include “Stack.h”

#include <string>

int main()

{

// Declaring Variables

string exp = “ABC*+DE-/”;

Stack <char> s(25);

char n = ‘1’;

int i = 0;

// While Loop

while (exp[i] != ”)

{

if (exp[i] == ‘+’ || exp[i] == ‘-‘ || exp[i] == ‘*’ || exp[i] ==’/’)

}

};

*****************************

*****************************

Header.h File:

#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;

// Stack template
template <class T>
class Stack
{
private:
T *stackArray;
int stackSize;
int top;

public:
//Constructor
Stack(int);

// Copy constructor
Stack(const Stack&);

// Destructor
~Stack();

// Stack operations
void push(T);
void pop(T &);
bool isFull();
bool isEmpty();
};

//***************************************************
// Constructor *
//***************************************************

template <class T>
Stack<T>::Stack(int size)
{
stackArray = new T[size];
stackSize = size;
top = -1;
}

//***************************************************
// Copy constructor *
//***************************************************

template <class T>
Stack<T>::Stack(const Stack &obj)
{
// Create the stack array.
if (obj.stackSize > 0)
stackArray = new T[obj.stackSize];
else
stackArray = nullptr;
  
// Copy the stackSize attribute.
stackSize = obj.stackSize;

// Copy the stack contents.
for (int count = 0; count < stackSize; count++)
stackArray[count] = obj.stackArray[count];
  
// Set the top of the stack.
top = obj.top;
}

//***************************************************
// Destructor *
//***************************************************

template <class T>
Stack<T>::~Stack()
{
if (stackSize > 0)
delete [] stackArray;
}

//*************************************************************
// Member function push pushes the argument onto *
// the stack. *
//*************************************************************

template <class T>
void Stack<T>::push(T item)
{
if (isFull())
{
cout << “The stack is full.n”;
}
else
{
top++;
stackArray[top] = item;
}
}

//*************************************************************
// Member function pop pops the value at the top *
// of the stack off, and copies it into the variable *
// passed as an argument. *
//*************************************************************

template <class T>
void Stack<T>::pop(T &item)
{
if (isEmpty())
{
cout << “The stack is empty.n”;
}
else
{
item = stackArray[top];
top–;
}
}

//*************************************************************
// Member function isFull returns true if the stack *
// is full, or false otherwise. *
//*************************************************************

template <class T>
bool Stack<T>::isFull()
{
bool status;

if (top == stackSize – 1)
status = true;
else
status = false;

return status;
}

//*************************************************************
// Member function isEmpty returns true if the stack *
// is empty, or false otherwise. *
//*************************************************************

template <class T>
bool Stack<T>::isEmpty()
{
bool status;

if (top == -1)
status = true;
else
status = false;

return status;
}
#endif

Program Using Stacks CISP 1020 Advanced C++ Assume that a machine has a single register and six instructions as follows LD A

Program Using Stacks CISP 1020 Advanced C++ Assume that a machine has a single register and six instructions as follows LD A ST A ADA SBA ML A DV A Places the operand A into the register Places the contents of the register into the variable A Adds the contents of the variable A to the register Subtracts the contents of the variable A from the register Multiplies the contents of the register by the variable A Divides the contents of the register by the variable A You are to write a program that accepts a postfix expression containing single letter operands and the operators +, -, *, / and prints a sequence of instructions to evaluate the expression and leave the result in the register. Use variables of the form TEMPn as temporary variables. For example, using the postfix expression ABC+DE-/ should print the following LD B ML C ST TEMP1 LD A AD TEMP1 ST TEMP2 LD D SB E ST TEMP3 LD TEMP2 DV TEMP3 ST TEMP4 Show transcribed image text Program Using Stacks CISP 1020 Advanced C++ Assume that a machine has a single register and six instructions as follows LD A ST A ADA SBA ML A DV A Places the operand A into the register Places the contents of the register into the variable A Adds the contents of the variable A to the register Subtracts the contents of the variable A from the register Multiplies the contents of the register by the variable A Divides the contents of the register by the variable A You are to write a program that accepts a postfix expression containing single letter operands and the operators +, -, *, / and prints a sequence of instructions to evaluate the expression and leave the result in the register. Use variables of the form TEMPn as temporary variables. For example, using the postfix expression ABC+DE-/ should print the following LD B ML C ST TEMP1 LD A AD TEMP1 ST TEMP2 LD D SB E ST TEMP3 LD TEMP2 DV TEMP3 ST TEMP4

Expert Answer


Answer to Need This In C++ Not Java Please. Thank You! This Is What I Currently Have So Far. How Could I Implement The Header FIle… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *