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

  Problem related to permutation

Write a recursively function that generates all the permutations of a set of numbers. Use the STL set class for all set operations and the STL linked list class to store and manipulate each individual permutation. When creating a set containing li..

  Lab11

ltbrgt

  Computer program the requirements are attached please see

the requirements are attached. please see them. the program should be done in c or c. also i need read me file to tell

  Write cpp pthreads program to discover shortest path in maze

The objective of this assignment is to apply the concepts of threading by developing a simple C++ Pthreads program to discover the surroundings and the shortest path in a 2D maze.

  Program that displays the ball at a random

Write a C++ program that displays the ball at a random location and then makes the ball move down to the bottom of the screen. When the ball reaches the bottom of the screen, it should start these actions over again, appear-ing at another random l..

  Compose a c++ program that print the given output

Compose a C++ program that will contain -Calculate the output of the three car positions for a two lap race and three lap race, using user input for all three cars lap times, and using variables for storing the data for each car.

  Method celsius return celsius equivalent of fahrenheit

Method Celsius return the Celsius equivalent of a Fahrenheit temperature,using the calculation Celsius = 5.0/9.0*(Fahrenheit -32); method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation  Fahrenheit = 9.0/5..

  Write a class dataset

Write a class DataSet that computes the largest and smallest values in a sequence of numbers.

  Supposed to swap numbers

The program is supposed to swap numbers, but I am stuck something is wrong! It does not swap them it repeats the second number, please help to fix! Thanks, this is in C++.

  Create a program that outputs the result of the formula

Create a program that outputs the result of the formula f = (a - b)(x - y) using the printf() functions.

  Your main function will still prompt the user

Your main function will still prompt the user for the account number and service code. Based on the service code, main will ask for the correct number of minutes, then call your functions above as needed to finish the job. In addition you must.

  Explain function which builds the multi-dimensional vector

A separate function which outputs the multi-dimensional vector to the screen.

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