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
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?
|