0

show_int_vector method RETURNS MEMORY LOCATION FOR EVERTHING EXCEPT FOR LAST VALUE.

main

```
#include "my_int_vector.h"
#include <iostream>
using namespace std;
int main()
{
my_int_vector b(0);
b.push_back(10);
//b.show_int_vector(b);
b.push_back(122);
b.show_int_vector(b);
//b.push_back(20000);
return 0;
}
```

Interface

```
class my_int_vector
{
public:
//constructor to create an array
my_int_vector(int intial);
//prints out the vector that contains the numbers
void show_int_vector(my_int_vector& b);
//returns value at arrayindex
int at(size_t arrayindex);
//returns value at arrayindex
int operator[](size_t array_index);
//add value to end of array
void push_back(size_t user_number);
//delete value from end of array
void pop_back();
//returns total number of elements that can be stored in the list
int capacity();
private:
//array to store numbers
int* numbers;
//array of temp values
int* temp;
//array of values which need to be printed which would be the valid ones
int* print;
//
size_t array_index;
};
```

Implementation

```
#include <iostream>
#include "my_int_vector.h"
using namespace std;
my_int_vector::my_int_vector(int intial)
{
if(intial==0)
{
array_index=intial;
numbers=NULL;
temp=NULL;
}
else if(intial>0)
{
array_index=intial;
numbers=NULL;
numbers=new int[array_index];
temp=NULL;
}
}
int my_int_vector::at(size_t arrayindex)
{
return numbers[arrayindex];
}
int my_int_vector::operator [](size_t array_index)
{
return numbers[array_index];
}
void my_int_vector::push_back(size_t user_number)
{
if(array_index==0)
{
array_index=array_index+1;
numbers=new int[array_index];
numbers[0]=user_number;
}
else
{
temp=new int[array_index];
for(size_t a=0; a<array_index; a++)
{
temp[a]=numbers[a];
}
delete[] numbers;
numbers=NULL;
array_index=array_index+1;
numbers=new int[array_index];
for(size_t b=0; b<array_index-2; b++)
{
numbers[b]=temp[b];
}
delete [] temp;
temp=NULL;
numbers[array_index-1]=user_number;
}
}
void my_int_vector::pop_back()
{
temp=new int[array_index];
for(size_t c=0; c<array_index; c++)
{
temp[c]=numbers[c];
}
array_index=array_index-1;
numbers=new int[array_index];
for(size_t h=0; h<array_index; h++)
{
numbers[h]=temp[h];
}
delete [] temp;
temp=NULL;
}
int my_int_vector::capacity()
{
return array_index;
}
void my_int_vector::show_int_vector(my_int_vector& b)
{
cout<<numbers[0]
<<numbers[1]<<"n";
}
```

*Edited
by lotrsimp12345*: n/a