In: Computer Science
Description of the problem:
1. Construct the recursive diagram of the Remove function that
invokes the function
recursive getIndexOf using the main program described in your
module.
2. Construct the recursive diagram of the getFrequencyOf function
that invokes the function
recursive countFrequency using the main program described in your
module.
C++ Code of getIndex and getFrequency
template void ArrayBag::display() const{ cout int ArrayBag::getFrequencyOf(const ItemType& anEntry) const { return countFrequency(anEntry, 0); } // end getFrequencyOf template int ArrayBag::countFrequency(const ItemType& target,int sear chIndex) const { if (searchIndex < itemCount) { if (items[searchIndex] == target) { return 1 + countFrequency(target, searchIndex + 1); } else { return countFrequency(target, searchIndex + 1); } // end if } else return 0; // Base case } // end countFrequency • getIndexOf(): Retorna el indice donde se encuentra el elemento dentro del arreglo, en caso contrario retorna -1. template int ArrayBag::getIndexOf(const ItemType& target, int searchI ndex) const { int result = -1; if (searchIndex < itemCount) { if (items[searchIndex] == target) { result = searchIndex; } else { result = getIndexOf(target, searchIndex + 1); } // end if } // end if return result; } // end getIndexO .
C++ Main Program
#include<iostream>
using namespace::std;
#include"ArrayBag.h"
int main(){
ArrayBag<int> myArrayInteger;
myArrayInteger.add(5);
myArrayInteger.add(3);
myArrayInteger.add(5);
myArrayInteger.add(10);
myArrayInteger.display();
myArrayInteger.remove(5);
myArrayInteger.display();
myArrayInteger.add(3);
myArrayInteger.add(3);
cout << "El nuemo 3 esta "
<<myArrayInteger.getFrequencyOf(3)
<< "veces repetido en el arreglo\n";
if (myArrayInteger.contains(7)){
cout <"El numero 7 esta dentro del arreglo\n";
}
else{
cout<<"El numero 7 no esta dentro del arreglo\n";
}
system("pause");
return 0;
}//end main
1. The first image provided is the recursive function getIndexOf as mentioned in the first part of the question.
*It is a diagrametic representation of the recursive function call executed by the program.
2. The above image is the digrametic representation of the recursive function countFrequency as per executed by the function.
->> a. The oval symbol represents the START and END of the function.
b. The rectangular symbol represents the CODE to EXECUTE in the particular step.
c. The diamond shape represents the CONDITIONAL statement the particuar function.
d. The arrow direction represnts the execution SEQUENCE of the function accordingly.