Question
I'd like to output capacity for test drivers, but somehow it's compile error. And the instructor says: Include a public getter named DynamicArray: :capacity ()
I'd like to output capacity for test drivers, but somehow it's compile error.
And the instructor says:
Include a public getter named DynamicArray::capacity() to return the data structure's now-variable capacity.
Include a public setter named DynamicArray::capacity(int) to change the capacity.
I don't even know if I have these function already.
==============================================
#ifndef DynamicArray_h #define DynamicArray_h
template
template template template template template template #endif ============================================== #include #include using namespace std; #include #include "DynamicArray.h" #include "DynamicArray.h" // test int main() { cout << "Programmer's name: Seita Fujiwara "; cout << "Programmer's ID: 1741873 "; cout << "file: " << __FILE__ << " "; // 1 Test all public functions cout << "============================================ "; DynamicArray a(100); cout << "Int DynamicArray Test: "; cout << "============================================ "; cout << "Testing DynamicArray::DynamicArray "; // constractor test for(int i=0; i<100; i++) assert(a[i]==0); cout << "Pass! "; cout << "Testing DynamicArray::capacity "; cout << "Expected: 100 "; /* cout << "ACTUAL: " << a.capacity(); assert(a.capacity()==100);*/ //StaticArray::operator[]setter cout << " Testing the DynamicArray::operator[]setter "; a[10]=1; cout << "Expected: 1 for a[10] "; cout << "ACTUAL: " << a[10] << endl; assert(a[10]==1); a[-1000]=666; cout << " Expected: 666 for a[-1000] (dummy) "; cout << "ACTUAL: " << a[-100] << endl; assert(a[-100]==666); a[300]=10; cout << "Expected: the new capacity for a is 200*2 "; /* cout << "ACTUAL: " << iArray.capacity() << endl; */ cout << " Testing the DynamicArray::operator[]getter "; DynamicArray a2 = a; for(int i=0; i<100; i++) assert(a[i]==a2[i]); cout << "Pass! "; // 2 Const object test // 3 Object copy test /* cout << " Object copy test "; DynamicArray iArray2=iArray; assert(iArray.capacity()==iArray2.capacity()); for(int i=0; i assert(iArray[i]==iArray2[i]); for(int i=0; i { iArray[i]++; assert(iArray[i]!=iArray2[i]); }*/ // Object assignment test return 0; }
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