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

You are given a library, container.o and the following .h file signatures: void

ID: 3801795 • Letter: Y

Question

You are given a library, container.o and the following .h file signatures: void add (int n, container* c);/* adds n to c */int get (int n container* c);/* returns 1 if n is in c, 0 otherwise */int remove (int n, container* c);/* returns 1 if n was in c; after return n is not in c!*/container* newContainer();/* returns a new container if memory avail */void removeAll (int n container* c);/* removes all instances of the number n from c*/. int size container* c) return the number of elements in c*/write a unit test that verifies that removeAll properly deletes all copies of a number that appears more than once in the container c

Explanation / Answer

// Create new container with empty list
Container* container = Container.newContainer();
//add nmber 1,2,3,2,2,4,2 in sequence
container.add(&contaier,1);
container.add(&contaier,2);
container.add(&contaier,3);
container.add(&contaier,2);
container.add(&contaier,2);
container.add(&contaier,4);
container.add(&contaier,2);

method 1:
//print the container size before the removeAll function call
print container.size(); // should be equal to 7
container.removeAll(2,&container);
//print the container size after the removeAll function call
print container.size(); // should be equal to 3 since 2 occurs four times in the container

method 2:
//use get function to decide whether number exists in the container
print container.get(2, &container); // should be equal to 1(since 2 exists in the container)
container.removeAll(2, &container); //removes all occurences of 2
print container.get(2, &container); // should be equal to 0 (since 2 does exists in the container)

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