Question
The purpose of this lab is to help reinforce container class concepts in C++. Specifically, you will be repeating the lab from last week except
The purpose of this lab is to help reinforce container class concepts in C++. Specifically, you will be repeating the lab from last week except you will be using a dynamic array for the sequence class. Note that there is no upper bound on the size of the sequence. You need to use the author's files sequence2.h and sequence_exam2.cpp. sequence2.h can be found here: http://www.cs.colorado.edu/~main/projects/sequence2.h
sequence_exam2.cpp can be found here:
http://www.cs.colorado.edu/~main/projects/sequence_exam2.cxx
Your sequence class for this assignment will differ from the your previous sequence in the following ways:
- The number of items which may be stored in the sequence should only be limited by the amount of memory available on the heap. When new items are added to a sequence which is at capacity, the size of the data array in which items are stored should be automatically enlarged.
- Because you are dynamically allocation memory within your sequence class, you will need to define a copy constructor, an assignment operator, and a destructor.
- The constructor should have a default argument which allows the user to set the initial capacity of the sequence.
- There should be a resize function that allows the user to explicitly set the the capacity of the sequence.
Start by declaring the new sequence's private member variables in sequence2.h. This should include the dynamic array (which is declared as a pointer to an Item). You will also need two size_t variables to keep track of the number of items in the sequence and the total size of the dyamic array. After you've declared your member variables, write an invariant for the top of sequence2.cxx.
Once again, do your work in small pieces. For example, my first version of the sequence had only a constructor, start, insert, advance, and current. My other member functions started out as stubs.
Use the interactive test program and the debugger to track down errors in your implementation. If you have an error, do not start making changes until you have identified the cause of the error.
When a member functions needs to increase the size of the dynamic array, it is a good idea to increase that size by at least 10% (rather than by just one item)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started