I am having a hard time understanding why the 2nd function (reverser) is not wor
ID: 441110 • Letter: I
Question
I am having a hard time understanding why the 2nd function (reverser) is not working. Please help Here is my code: #include #include using namespace std; bool isMember(int [], int, int, int);// Function prototype void Reverser(char [],int ,int); const int SIZE = 10; // Array size char names[20]; int main() { int tests[SIZE] = {1993, 1996, 1999, 2000, 2002, 2004, 2006,// Define an array of vehicle years 2012, 2016, 2020}; int vehicYear;// To hold a vehicle year bool results;// hold the search results while(1) { char choice[2]; cout<<" ::Menu:: " <<"1. Member Function " <<"2. Reverser Function " <<"3. Exit Program " <<"Choice: "; cin>>choice; if (choice[0]=='1') { cout <<"Enter the vehicle year you are searching for: ";// Get an vehicle year to search for. cin >> vehicYear; results = isMember(tests, 0, SIZE - 1, vehicYear);// Search for the year in the array. if (results == false) cout << "That year does not exist in the file. ";//Show the results of the search. else { cout << "That year is found in the file "; } cout<<" "; system ("PAUSE"); } else if (choice[0]=='2') { cout<<"Enter string: "; gets(names); int len=strlen(names); Reverser(names,0,len-1);//Function call cout<<" "; system ("PAUSE"); } else if (choice[0]=='3') { return 0; } else if (choice[0]>'3' || choice[0]<'1') { cout<<"Invalid Input "; system ("PAUSE"); system ("CLS"); } else { cout<<"Invalid Input "; system ("PAUSE"); } } } bool isMember(int array[], int first, int last, int value)//Returns false if not found { int middle; // Mid point of search if (first > last)//base case return false; middle = (first + last)/2; if (array[middle]==value) return true; if (array[middle]<=size)//base case { cout<<array[size]; Reverser(array,pos,size-1); } }Explanation / Answer
#include #include
using namespace std;
bool isMember(int [], int, int, int);
// Function prototype
void Reverser(char [],int ,int); // i am not seeing where is this function has declaration
const int SIZE = 10;
// Array size
char names[20];
int main()
{ int tests[SIZE] = {1993, 1996, 1999, 2000, 2002, 2004, 2006,
// Define an array of vehicle years 2012, 2016, 2020};
int vehicYear;// To hold a vehicle year bool results;// hold the search results
while(1)
{
char choice[2];
cout<<" ::Menu:: " <<"1. Member Function " <<"2. Reverser Function " <<"3. Exit Program " <<"Choice: ";
cin>>choice;
if (choice[0]=='1')
{
cout <<"Enter the vehicle year you are searching for: ";// Get an vehicle year to search for.
cin >> vehicYear;
results = isMember(tests, 0, SIZE - 1, vehicYear);
// Search for the year in the array.
if (results == false) cout << "That year does not exist in the file. ";//Show the results of the search.
else {
cout << "That year is found in the file "
; }
cout<<" ";
system ("PAUSE");
}
else if (choice[0]=='2')
{
cout<<"Enter string: "; gets(names); int len=strlen(names); Reverser(names,0,len-1)
;//Function call cout<<" "; system ("PAUSE");
}
else if (choice[0]=='3')
{
return 0;
} else if (choice[0]>'3' || choice[0]<'1')
{
cout<<"Invalid Input "; system ("PAUSE"); system ("CLS");
}
else
{
cout<<"Invalid Input "; system ("PAUSE");
}
}
}
bool isMember(int array[], int first, int last, int value)//Returns false if not found
{
int middle;
// Mid point of search if (first > last)//base case return false;
middle = (first + last)/2;
if (array[middle]==value) return true;
if (array[middle]<=size)//base case
{
cout<Reverser(array,pos,size-1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.