Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use maxSize as a const int maxSize = 1000; and use pointer. Thanks Use vi

ID: 3883881 • Letter: P

Question

Please use maxSize as a const int maxSize = 1000; and use pointer. Thanks

Use visual studio to create a new C++ project. Your required in this task to impalement your own vector class. Your class is named custom_Vector. The class includes at least following member functions: 1. 2. 3. 4. 5. 6. 7. A default constructor that initialize your custom vector objects A destructor to release the memory to the heap. push back(string item) function that appends elements to the end of the vector. pop() function that removes the last element of your vector and returns it. disp() function that displays the elements of the vector. size() function that returns the number of elements in the vector. at(int index) function that returns the element at the position index (assume that the first element in your vector at position 1.) Implement a main function to test your method. Your class accepts only string values. Therefore, you do not need to use templates For example, when I use the following main function int main ) Custom_vector vector1; vector1.push_back("apples"); vector1. push_back ( "bananas"); vector1.push_back("pineapples"); vector1.disp); cout

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

#define maxSize 1000

class Custom_vector{
   private:
      int count;
      string *data;
   public:
      Custom_vector(){
         data = new string[maxSize];
        
         count = 0;
      }
      string pop(){
          int a = count-1;
          count = count -1;
          return data[a];
         
      }
      void push_back(string a){
          if (count < maxSize){
            
             data[count] = a;
             count = count+1;
          }         
      }
      int size(){
          return count;
      }
      void disp(){
         for(int i = 0; i<count; i++)
             cout << data[i] << endl;
      }
      string at(int a){
          if (a < count)
             return data[a-1];
          else{
             cout << "The index (" << a << ") is out of range ! ";
             cout << "The vector includes only " << count << " elements ";
             return "";
           }
      }


};

int main(){

   Custom_vector vector1;
   vector1.push_back("apples");
  
   vector1.push_back("bananas");
   vector1.push_back("pineapples");

   vector1.disp();
   cout << "The vector size = " << vector1.size() << endl;
   cout << vector1.at(10) << endl;
   cout << vector1.at(2) << endl;
   cout << "Pop => " << vector1.pop() << endl;
   cout << "The vector size = " << vector1.size() << endl;
  
   return 0;
}