creating a vector .h

I have been instructed to make a header file with some criteria:

1. A default constructor that creates an vector with a default capacity of 2
2. A parameterized constructor that creates a vector of capacity n
3. A destructor that deletes any dynamically allocated storage. The destructor has the same name as the class, but begins with a ~. The destructor has no return type and takes no parameters, for example ~MyVector( )
Note that you program should not have any memory leaks.
4. A function, size( ), that returns the size of your vector.
5. A function, capacity( ), that returns the capacity of the vector.
6. A function, clear( ), that deletes all of the elements from the vector and resets its size to zero and its capacity to two.
7. A function push_back(int n) that adds the integer value n to the end of the vector. If the vector is not large enough to hold this additional value, you must make the vector grow. Your grow algorithm should double the current capacity of the vector. Don't forget to consider the case where the initial capacity of the vector is zero.
8. A function at(int n) that returns the value of the element at position i in the vector. If the index i is greater than the size( ) of the vector, this function should throw an exception.

This is what I have so far, I am confused on creating the constructor vectors. Any help with this would be greatly appreciated.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>

using namespace std;

class vectorClass
{

private:
	int size;
	int capacity;
	int clear;
	int push_back;
	int at;

public:
	vectorClass(vector <int>);
	int size( ) const;
	int capacity( ) const;
	int clear( )const;
	int push_back(int n) const;
	int at(int n) const;
};
I have solved this one.
Topic archived. No new replies allowed.