Question
I am filling out a program where the method definitions will be written underneath the .h file in the .h file the attributes are When
I am filling out a program where the method definitions will be written underneath the .h file
in the .h file the attributes are
When I run the program I get this error
When I change void vector
I get this error message Is there anyway to fix these issues?
the program
--main cpp--
vector.h
#include
using namespace std;
int main() { /* Type your test code here. You will not be submitting this code. It's only for testing. */ return 0; }
// vector class template
#ifndef Vector_Vector_h #define Vector_Vector_h
#include
template
// increase capacity void increaseCapacity(unsigned long);
public: // Default constructor vector();
// Constructor declaration vector(unsigned long);
// Resize the vector - changes the size attribute void resize(unsigned long n);
// Resizes the vector and initializes the unused locations - updates the size attribute void resize(unsigned long n, const T &val);
// Copy constructor declaration vector(const vector &);
// Destructor declaration ~vector();
// Accessor to return the array size unsigned long size() const;
// Accessor to return the array capacity unsigned long capacity() const;
// Accessor to test empty status bool empty() const;
// Accessor to return a specific element T &at(unsigned long position);
// Overloaded [] operator declaration T &operator[](const unsigned long &);
// back element of the vector T &back();
// front element of the vector T &front();
void push_back(T); // New push_back member T pop_back(); // New pop_back member
// insert element at position int insert(unsigned long, const T &);
// erase a range of values void erase(unsigned long, unsigned long);
// erase one element at a position void erase(unsigned long); };
/* This is where your method definitions will be written. This default constructor * the first method you need to complete. To compile the program, you should create * empty stubs for each of the declared methods. */
template
} #endif
my code
vector.h
// vector class template
#ifndef Vector_Vector_h #define Vector_Vector_h
#include
template
// increase capacity void increaseCapacity(unsigned long);
public: // Default constructor vector();
// Constructor declaration vector(unsigned long);
// Resize the vector - changes the size attribute void resize(unsigned long n);
// Resizes the vector and initializes the unused locations - updates the size attribute void resize(unsigned long n, const T &val);
// Copy constructor declaration vector(const vector &);
// Destructor declaration ~vector();
// Accessor to return the array size unsigned long size() const;
// Accessor to return the array capacity unsigned long capacity() const;
// Accessor to test empty status bool empty() const;
// Accessor to return a specific element T &at(int position);
// Overloaded [] operator declaration T &operator[](const int &);
// back element of the vector T &back();
// front element of the vector T &front();
void push_back(T); // New push_back member T pop_back(); // New pop_back member
// insert element at position int insert(unsigned long, const T &);
// erase a range of values void erase(unsigned long, unsigned long);
// erase one element at a position void erase(unsigned long); };
/* This is where your method definitions will be written. This default constructor * the first method you need to complete. To compile the program, you should create * empty stubs for each of the declared methods. */
template
template
}
template
arraySize = n; }
template
for (unsigned long i = arraySize; i
arraySize = n; } catch(std::bad_alloc & exception){ std::cerr
template template template template } template } template template template } template template aptr[arraySize] = val; arraySize++; } template template if (position arraySize) { std::cout if (arraySize == arrayCapacity) { increaseCapacity(arrayCapacity * 2); } for (unsigned long i = arraySize; i > position; i--) { aptr[i] = aptr[i-1]; } aptr[position] = val; arraySize++; return 0; } template if (start >= end || start >= arraySize) { return; } end = (end >= arraySize) ? arraySize - 1 : end; const unsigned long rangeSize = end - start + 1; for (unsigned long i = end + 1; i arraySize -= rangeSize; } template if (position = arraySize) { std::cout for (unsigned long i = position; i arraySize--; } template T *tempArray = new T[newCapacity]; for (unsigned long i = 0; i delete [] aptr; aptr = tempArray; arrayCapacity = newCapacity; } catch (std::bad_alloc & exception) { std::cerr } } #endif
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