Define the exception class memoryallocationexception

Assignment Help C/C++ Programming
Reference no: EM131085380

PART I

1) Define the exception class MemoryAllocationException and then revise the definition of the method push in the class LinkedStack so that it throws this exception if it cannot allocate a new node.

2) Improve the palindrome-recognition algorithm C++ source code (shown below in blue), by adding the first length / 2 characters to the queue and then pushing the remaining characters onto the stack.

//  Tests whether a given string is a palindrome.

 isPalindrome(someString: string): Boolean

// Create an empty queue and an empty stack

aQueue = a new empty queue

aStack = a new empty stack

// Add each character of the string to both the queue and the stack

length = length of someString

for (i = 1 through length)

{

nextChar = ith character of someString

aQueue.enqueue(nextChar)

aStack.push(nextChar)

}

// Compare the queue characters with the stack characters

charactersAreEqual = true

while (aQueue is not empty and charactersAreEqual)

{

queueFront = aQueue.peekFront()

stackTop = aStack.peek()

if (queueFront equals stackTop)

{

aQueue.dequeue()

aStack.pop()

}

else

charactersAreEqual = false

}

return charactersAreEqual

3) Revise the parameterized constructor (shown below) to call the base-class's constructor instead of MagicBox's constructor.

/** @file MagicBox.h */

#ifndef _MAGIC_BOX

#define _MAGIC_BOX

#include "PlainBox.h"

template<class ItemType>

 class MagicBox : public PlainBox<ItemType>

{

private:

bool firstItemStored;

public:

 MagicBox();

MagicBox(const ItemType& theItem);

void setItem(const ItemType& theItem);

}; // end MagicBox

#include "MagicBox.cpp"

 #endif

/** @file MagicBox.cpp */

template<class ItemType>

MagicBox<ItemType>::MagicBox()

{

PlainBox<ItemType>();

firstItemStored = false; // Box has no magic initially

} // end default constructor

template<class ItemType>

MagicBox<ItemType>::MagicBox(const ItemType& theItem)

{

firstItemStored = false; // Box has no magic initially

setItem(theItem); // Box has magic now

}              // end constructor

template<class ItemType>

void MagicBox<ItemType>::setItem(const ItemType& theItem)

{

if (!firstItemStored)

{

PlainBox<ItemType>::setItem(theItem);

firstItemStored = true; // Box now has magic

 } // end if

} // end setItem

Reference no: EM131085380

Questions Cloud

Calculating the longest possible wavelength : An otherwise free metal rod of length L = 48.0 cm is clamped at a point L/28 from one end. A standing wave is set up on the rod. What is its longest possible wavelength?
The expected year-end free cash flow : A corporation has a weighted avg cost of capital of 10.25% and its value of operation is $57.50 million. Free cash flow is expected to grow at a constant rate at 6.00% per year.
Camera a concave or a convex lens : Photography A 35-mm camera has a standard lens with focal length 50 mm and can focus on objects between 45 cm and infinity. (a) Is the lens for such a camera a concave or a convex lens?
The balance of power between stockholders and managers : In a firm,the balance of power between stockholders and managers is a function of factors-internal as well as external.Events can cause the power to shift towards managers or towards stockholders or leave the balance unchanged.Evaluate how the fol..
Define the exception class memoryallocationexception : Define the exception class MemoryAllocationException and then revise the definition of the method push in the class LinkedStack so that it throws this exception if it cannot allocate a new node.
Define length of stay and discharge days : 1.Define length of stay (LOS) and discharge days (DD). Why is calculating length of stay (LOS) important to our hospitals today? What role does discharge days (DD) play in the length of stay (LOS) ratio?
Unspent balance being placed in a bank deposit : A firm has a capital budget of $100 which must be spent on one of two projects, with any unspent balance being placed in a bank deposit earning 15%. Project A involves a present outlay of $100 and yields $321.76 after 5 years. Project B involves a..
What is the probability that at most one is being deceptive : A federal report find that a lie detector test given to truthful persons have a probability of 0.2 of suggesting that the person is deceptive. What is the probability that at most one is being deceptive
What do you think the advantages are of using android studio : Until recently, most Android developers used the Eclipse IDE. In 2013 Google introduced Android Studio as a new development tool. What do you think the advantages are of using Android Studio as the development tool?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that is called playing with numbers or

write a program that is called playing with numbers or letters. this program allows a user either to enter a collection

  Define an auxiliary procedure

How to use do to define (minimum lst) which returns the minimum of a list of numbers. You may want to define an auxiliary procedure (smaller x y), using if, which returns the smaller of the two numbers.

  Feature of object-oriented programming

Describe at least one (1) feature of object-oriented programming that Visual Logic lacks and Identify at least one (1) advantage to using event-driven programming, as compared to using purely procedural programming

  Create a bar chart showing the average monthly mean temperat

Write a ++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013. The point of the exercise is to compute the sie and location of the rectangles rather than explicitely hardcode that informat..

  Reduction polynomial on the computation

What is the influence of the choice of the reduction polynomial on the computation?

  Write a program that accepts as input a string variable

Write a program that accepts as input a string variable called strFirstName, then another string variable called strLastName, and an integer variable called intAge.

  Declare and define constructor

Declare and define constructors and Declare and define destructors - Describe what is an attribute or data member of a class

  Using which of the following techniques in c++

Using which of the following techniques in C++ is it possible to have different functions with the same name?select all that apply

  Program loops and if conditions write a program that

program loops and if conditions write a program that requests a password after the authorprogram information is

  Create a loops that reads from memory an array

Create a loops that reads from memory an array containing an arbitrary number of characters - The program should make a second character array which is identical to the first, except that the case of every alphabetical letter has been reversed

  Write a program that uses a loop to display projected rates

Write a program that will convert US dollar amounts to Canadian dollar (1 CND = 0.92 USD). Format your currency amounts in two decimal places and trailing zeros.

  Program that reads source file

For this assignment you will write a program that reads a source file, edits the file based on a second file containing commands, and then saves the resulting text to a third file. You will find my executable and test files in ~davis/40/p7.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd