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

In c++ The project must be done using classes and the classes must use default c

ID: 3873009 • Letter: I

Question

In c++

The project must be done using classes and the classes must use default constructors, big three, operators, etc. Please comment. Let me know if you need anymore info and ill will update. Ill rate and thumbs up if it runs properly and everything i provided .Thanks

One problem with dynamic arrays is that once the array is created using die new operator, the size cannot be changed. For example, you might want to add or delete entries from the array as you can with a vector. This project asks you to create functions that use dynamic arrays to emulate the behavior of a vector First, write a program that creates a dynamic array of five strings. Store five names of your choice into the dynamic array. Next, complete the following two functions string* addEntry (string -dynamicArray, int &size;, string newEntry); This function should create a new dynamic array one element larger than dynamic Array, copy all elements from dynamic Array into the new array, add the new entry onto the end of the new array, increment size, delete dynamic Array, and return the new dynamic array string* deleteEntry(string -dynamic Array, int &size;, string entry ToDelete) This function should search dynamicArray for entryToDelete. If not found, the request should be ignored and die unmodified dynamicArray returned. If found, create a new dynamic array one element smaller than dynamicArray. Copy all elements except entry ToDelete into the new array, delete dynamicArray, decrement size, and return the new dynamic array Test your functions by adding and deleting several names to the array while outputting the contents of the array. You will have to assign the array returned by addEntry or deleteEntry back to the dynamic array variable in your main function

Explanation / Answer

#include<iostream>
#include<string>


using namespace std;

string *addEntry(string *array,int &size, string newEntry){
      string *p;
      p = new string[size+1];
      for (int i = 0; i <size; i++){
          p[i] = array[i];
      }
      p[size] = newEntry;
      size = size + 1;
      cout << "Added :" << newEntry << endl;
      return p;
   
}


string *deleteEntry(string *array,int &size , string newEntry){
      string *p;
      p = new string[size-1];
      int j = 0;
      for (int i = 0; i <size; i++){
         if (array[i] != newEntry){
            p[j] = array[i];
            j++;
         }
      }
      size = size - 1;
      cout << "Deleted :" << newEntry << endl;
      return p;
   
}

void disp(string *arr, int size){

for (int i = 0; i<size; i++){
     cout << arr[i] << endl;
}
cout << endl;
cout << endl;
}


int main(){

string *dynamicarray;
int size = 0;;

dynamicarray = new string[5];
dynamicarray[0] = "name1";

dynamicarray[1] = "name2";
dynamicarray[2] = "name3";
dynamicarray[3] = "name4";
dynamicarray[4] = "name5";
size = 5;
disp(dynamicarray,size);
dynamicarray = addEntry(dynamicarray,size, "name6");
dynamicarray = addEntry(dynamicarray,size, "name7");
dynamicarray = addEntry(dynamicarray,size, "name8");
disp(dynamicarray,size);

dynamicarray = deleteEntry(dynamicarray,size, "name7");
dynamicarray = deleteEntry(dynamicarray,size, "name8");
disp(dynamicarray,size);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote