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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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