Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the following exercise you will use the Stash class , but with two modifications: 1) you will have a new integer member to store

In the following exercise you will use the Stash class, but with two modifications:

1) you will have a new integer member to store the desired increment to be used during re-allocation (and not a fixed 100 value as in the book);

2) you will have another integer member variable to count the number of re-allocations (calls to the inflate method) the Stash class needed during its use.

You will now write a variation of the run-length encoder you wrote in the previous lab using the Stash class with each entry being one character. First of all you will read as input an integer that will tell how much the Stash should use as increment. Then you will read a sequence of pairs, each pair containing a character and a number. For each pair (C,N), add to a Stash object the character C, N times without spaces.

If a pair has a negative N number, add the character C, |N| times and then add a newline character (' ').

If a pair (&,99) is read then stop reading values, print the elements in the Stash in the order received, and then print two numbers: the number of calls that were made to inflate() inside your Stash object, and the total size in bytes that was allocated by the Stash object at the end (the value of the quantity variable).

Example 1:

Input: 1 k -1 e 2 r -3 & 99

Output:

k eerrr 8 8 freeing storage

Example 2:

Input: 8 k -1 e 2 r -3 & 99

Output: k eerrr 1 8 freeing storage

Example 3:

Input: 7 k -1 e 2 r -3 & 99

Output: k eerrr 2 14 freeing storage

Example 4: Input: 1 h 1 i 1 & 99

Output: hi 2 2 freeing storage

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago