Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MyDynamicArray {
- private:
- int capacity;
- int nums;
- int *array;
- int safe;
- public:
- MyDynamicArray(); //Default Constructor. The array should be of size 2.
- MyDynamicArray(int s);//For this constructor the array should be of size s.
- ~MyDynamicArray(); //Destructor for the class.
- int& operator[](int i); //Traditional [] operator. Should print a message if i is out of bounds and return a reference to a zero value.
- void add(int v); //increases the size of the array by 1 and stores v there.
- void del();// reduces the size of the array by 1.
- int length(); //returns the length of the array.
- int clear(); //Frees any space currently used and starts over with an array of size 2.
- };
- MyDynamicArray::MyDynamicArray()
- {
- array = new int[2];
- nums = 0;
- capacity = 2;
- cout << "constructor called." << endl;
- return;
- }
- MyDynamicArray::MyDynamicArray(int s)
- {
- array = new int[s];
- capacity = s;
- nums = s;
- cout << "Special constructor called." << endl;
- return;
- }
- MyDynamicArray::~MyDynamicArray()
- {
- cout << "Destructor called." << endl;
- delete array;
- }
- int& MyDynamicArray:: operator[](int i)
- {
- if(i> nums-1)
- {
- cout << "flag 1" <<endl;
- }
- return safe;
- /*
- if(i<= nums-1)
- {
- //In range
- return safe;
- }
- cout << "Out of bounds reference : " << i << endl;
- return safe;*/
- }
- void MyDynamicArray::add(int v)
- {
- }
- void MyDynamicArray::del()
- {
- }
- int MyDynamicArray::length()
- {
- }
- int MyDynamicArray::clear()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement