Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Using C Design Lower Level Functions Heavy Lifting Moving Data Around Forget Write Copylis Q35548533

USING C++ ONLY!!!!

  • Design lower level functions to do the “heavy lifting” ofmoving data around,
  • Do not forget to write a CopyList and a Search function alongwith an Allocate, Initialize, and print functions for yourlist.
  • I do not want to see a bunch of for loops in your AddEntry,DeleteEntry or in main()
  • IMPORTANT:

    • Rather than adding one to the capacity of the list,double the capacity when you run out of room. This is a much morerealistic method. On remove_entry, reallocate half the space whenthe size reaches 1/4 of the capacity.
  • IMPORTANT:

    • Set your capacity to 3. Have a debug boolean flag allowprinting of a clear message that more space is being allocatedwhenever you are about to exceed the capacity. A message shouldalso display when you allocate a smaller space for your list. Youroutput MUST allow me to see when memory management is takingplace.

Function Prototypes:

T* add_entry(T* list, const T& new_entry, int& size, int& capacity);T* remove_entry(T* list, const T& delete_me, int& size, int& capacity);T* allocate(int capacity);void copy_list(T *dest, T* src, int many_to_copy);T* search_entry(T* list, const T& find_me, int size);void print_list(T* list, int size);void test_string();void test_string(){ int capacity = 3; int size = 0; T* list = allocate(capacity); list = add_entry(list, “Erika”, size, capacity); print_list(list, size); list = add_entry(list, “Red”, size, capacity); print_list(list, size); list = add_entry(list, “Bo”, size, capacity); print_list(list, size); list = add_entry(list, “Pierson”, size, capacity); print_list(list, size); list = add_entry(list, “Maher”, size, capacity); print_list(list, size); list = add_entry(list, “Mac”, size, capacity); print_list(list, size); list = add_entry(list, “Paula”, size, capacity); print_list(list, size); cout<<“Deleting Erika”<<endl; list = remove_entry(list, “Erika”, size, capacity); print_list(list, size); cout<<“Deleting Bo”<<endl; list = remove_entry(list, “Bo”, size, capacity); print_list(list, size); cout<<“Deleting Maher”<<endl; list = remove_entry(list, “Maher”, size, capacity); print_list(list, size); cout<<“Deleting Pierson”<<endl; list = remove_entry(list, “Pierson”, size, capacity); print_list(list, size); cout<<“Deleting Red”<<endl; list = remove_entry(list, “Red”, size, capacity); print_list(list, size);}

The allocate function:

Very simple, but just to keep the confusion level down:

T* allocate(int capacity){ const bool debug = false; if (debug) cout<<“allocate: capacity: “<<capacity<<endl; return new T[capacity];}

Leave a Reply

Your email address will not be published. Required fields are marked *