Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART 1 Write And Test An Array Class [DynamicArray.h and DynamicArray.TestDriver.cpp] Write and test a data structures template. The resulting template can be used in

image text in transcribedimage text in transcribed

PART 1 Write And Test An Array Class [DynamicArray.h and DynamicArray.TestDriver.cpp] Write and test a data structures template. The resulting template can be used in any program in place of a C++ array. Requirements. Develop DynamicArray.h as you write DynamicArray.TestDriver.cpp with class DynamicArray, defined and fully tested. Write the public interface exactly as specified below -- do not add to, or change the public interface as specified. 1. Write the template for an array of capacity =2 (default constructor) of unspecified type. 2. Include a public square bracket getter and setter pair, both with index range-checking, returning whatever value you wish if out of range. But apply capacity auto-adjusting for the setter if out of range high. 3. Include a public getter named DynamicArray::capacity() to return the data structure's now-variable capacity 4. Include a public setter named DynamicArray::capacity(int) to change the capacity. 5. Do tests with int, double, or char . Also do tests with an object, like string . Note that there is no good reason to copy the "dummy" value in the dynamic memory management functions, so don't include it in your testing of const object copy or object assignment. DynamicArray template class public interface: template class DynamicArray \{ T* value; // T datatype CAP compasity int cap; T dummy ; public: DynamicArray (int=2); // constructor // default =2 DynamicArray (const DynamicArray T>&); // copy constructor DynamicArray () \{delete [ ] value; ; // destructor DynamicArray & operator =( const DynamicArray T>&);// assignment operator int capacity() const \{return cap; void capacity(int); // setter T operator[ ] (int) const; // getter T\& operator[ ] (int); // setter \} ; Write An Array Application [MyDynamicArray.cpp] Write MyDynamicArray.cpp using your DynamicArray template. Use your already-tested and verified H file from part 1. Exactly as in Assignment 3's MyStaticArray.cpp, this app lets its user enter as many values as they like, and when that process is completed, lets the user look up values by index. In a loop, the app should prompting the user to enter a pair of numbers on the same line: a whole number index and its corresponding floating point value. Do not validate index input in the app. Quit the loop when an uppercase or lowercase Q is entered for either the index or the value. Indexes can be entered in any order -- they don't have to start with zero an by one thereafter. It's whatever the user enters. Your app should keep track of which indexes got entered. Use a bool DynamicArray for that. After all data entry is complete, the app should: 1. output how many (unique) indexes got entered, 2. output the list of all used indexes and their values, per the example below, and 3. implement an event-controlled loop that prompts for an index value and outputs whether the index is in use or not, and if in use, what is the value stored for that index the user elects to stop by entering uppercase or lowercase Q. Here's a sample of how this should work (user input in blue): Input an index and a value [Q to quit]: 331.2 Input an index and a value [Q to quit] 44100 Input an index and a value [Q to quit] 5300 Input an index and a value [Q to quit] 51.7 Input an index and a value [Q to quit] 33120 Input an index and a value [Q to quit] 33 -1 23.4 Input an index and a value [Q to quit] 2000999.9 Input an index and a value [Q to quit] 4 You stored this many values: 5 The index-value pairs are: 01.7 4100 5 5300 33120 2000999.9 Input an index for me to look up [Q to quit]: 33 Found it -- the value stored at index 33 is 120 Input an index for me to look up [Q to quit]: 0 Found it -- the value stored at index 0 is 1.7 Input an index for me to look up [Q to quit]: 10 Sorry, but there is no value stored at index 10 Input an index for me to look up [Q to quit]: 38 Sorry, but there is no value stored at index 38 Input an index for me to look up [Q to quit]: 10000 Sorry, but there is no value stored at index 10000 Input an index for me to look up [Q to quit]: 2000 Found it the value stored at index 2000 is 999.9 Input an index for me to look up [Q to quit]: a

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

More Books

Students also viewed these Databases questions