Question
Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right!

(8 points) Create a class called resizeableArray. Include an int pointer arrayPtr variable that points to a dynamic array, a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//4
class resizeableArray
{
   int *arrayPtr;
   int capacity,currentSize;
   public:
   //default constructor
   resizeableArray()
   {
       capacity=16;
       currentSize=-1;
       arrayPtr = new int[16];
       //initializing all values with -1
       for(int i=0;i<16;i++)arrayPtr[i]=-1;  
   }
   //parameterized constructor
   resizeableArray(int n)
   {
           capacity=n;
       currentSize=-1;
       arrayPtr = new int[n];
       //initializing all values with -1
       for(int i=0;i<n;i++)arrayPtr[i]=-1;
      
   }
   //method to add element to array
   void addElement(int n)
   {
       if(currentSize+1 < capacity)
       {
               arrayPtr[currentSize+1]=n;
               currentSize++;
       }
       else
       {//if array is full
           resizeArrayup();//then resizing it
           addElement(n);   //then adding element
       }
   }
   void removeElement(int n)
   {
       //removes n from array
       int i=0;
       for(i=0;i<=currentSize;i++)
       {
           if(arrayPtr[i]==n)break;//if found  
       }  
       for(;i<=currentSize-1;i++)
       arrayPtr[i]=arrayPtr[i+1];
       arrayPtr[i]=-1;
       currentSize--;
       if(currentSize<capacity/4)
       resizeArraydown();
   }
   //method to resize array//increases size
   void resizeArrayup()
   {
           int *n = new int[capacity*2];
           for(int i=0;i<=currentSize;i++)
           n[i]=arrayPtr[i];
           for(int i=currentSize+1 ;i<capacity*2;i++)
           n[i]=-1;
           arrayPtr=n;
           capacity=capacity*2;
   }
   //decreases the size
   void resizeArraydown()
   {
           int *n = new int[capacity/2];
           for(int i=0;i<=currentSize;i++)
           n[i]=arrayPtr[i];
           for(int i=currentSize+1 ;i<capacity/2;i++)
           n[i]=-1;
           arrayPtr=n;
           capacity=capacity/2;
   }
};

Add a comment
Know the answer?
Add Answer to:
Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right...

    Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right! (26 points total) Write an inheritance hierarchy for classes of simple shapes. 1. Create a class Shape. Derive the class ThreeDimensionalShape from the Shape class. Derive the class Sphere from the ThreeDimensionalShape class Use abstract classes to define Shape and ThreeDimensionalShape classes, and then...

  • QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following...

    QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox: public class QueueBox<E> { private E[] elements = (ED))( new Object[5]); private int front_idx = 0; private int rear_idx = 0; private int count = 0; Hint: use the count variable to keep track of how many elements are in the queue (increment count when enqueing and decrement when dequeing). Makes it a lot easier to determine if the...

  • Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft ...

    Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft Visual Studio described here. As you work on the below project, demonstrate to the instructor the usage of this feature. Create a project titled Lab11_VarArrayTest. Implement the dynamically expanding and contracting array of doubles described in the previous lab as a class. You should use this class definition. The class attributes are a pointer to the dynamically allocated array dAarray and the array size size This...

  • Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project...

    Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project inside the ArraySetWithArray class. As shown in the UML diagram below ArraySetWithArray class does not utilize ResizableArrayBag object as its instance variable, it has setOfEntries defined as an array which should be dynamically resized if more room needed (double the size). displaySet method should check if the set is empty and display appropriate message; if the set is not empty should display the number...

  • JUnit5 JAVA. Need help to make a unit test of my GenericStack.java code below. Feel free...

    JUnit5 JAVA. Need help to make a unit test of my GenericStack.java code below. Feel free to change the code below to fit the task better. thanks :) Assigment Create a new version of GenericStack (Have started on the code below) that uses an array instead of an ArrayList (this version should also be generic). Be sure to check the size of the array before adding a new item; - if the array becomes full, double the size of the...

  • C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that...

    C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • c++ question i just need answer for this question Dont need to write all program.Thanks Use...

    c++ question i just need answer for this question Dont need to write all program.Thanks Use the following class declaration when answering this question: class Containers w public: void disconnect( const int container_id): private: int count; \\number of container cargo cells used int capacity; \\ total number of container cargo cells int *cargo; \\name of dynamic array }; Implement the function "disconnect with the given prototype in the class declaration above. The function will remove the item that matches the...

  • In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> {...

    In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> { /** Adds one element to the top of this stack. * @param element element to be pushed onto stack */ public void push (T element);    /** Removes and returns the top element from this stack. * @return T element removed from the top of the stack */ public T pop(); /** Returns without removing the top element of this stack. * @return T...

  • Game Development: Uno For this assignment you will be creating the game of Uno (See the...

    Game Development: Uno For this assignment you will be creating the game of Uno (See the accompanying pdf for the instructions of the game). Your version will adhere to all the rules except that only the next player can issue a challenge against the previous player in regards to penalties, and your games must have at least three (3) players and at most nine (9) players. To begin, you must create the class Card which contains: Private string field named...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT