Question

In class Recursion problems bool anyNegative(int al , int size) This function returns true if there are any negative numbers in the array, grity false otherwise. int firstNegative(int al I, int size) This function returns the position of the first negative number in the array & EAO If there are no negative numbers it returns int countNegative(int al I, int size) This function returns the number of negative numbers in the array a. 12 bst Stringsint indexO bout Strings nt indexOfMin(int al l. int size) This function returns the index of minimum value in the array M Chapter Iszs
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi Student,

I had written code in Java if you wanted in other language then use the implementation of method provided in code

public class Chapter_8_3026Chegg {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
  
//Test implemented methods
  
int[] arr={3,6,8,9,-1,6,3,-12};
System.out.println("Array Contains negative number ? "+anyNegative(arr,arr.length));
System.out.println("Array Contains first negative number at index :"+firstNegative(arr,arr.length));
System.out.println("Array negative number Count :"+countNegative(arr,arr.length));
System.out.println("Array Contains the minimal number at index :"+indexOfMin(arr,arr.length));
}
//Method to check if array contains any negative number
public static boolean anyNegative(int a[],int size){
for(int a1:a){
//If any negative number found method returns true
if(a1<0)
return true;
}
//Otherwise returns false
return false;
}
//Method to find index of first negative number
public static int firstNegative(int a[],int size){
int index=0;
for(int a1:a){
//If any negative number found method returns index of that number
if(a1<0)
return index;
index++;
}
//Otherwise returns -1
return -1;
}
//Method to find total countof negative number
public static int countNegative(int a[],int size){
int count=0;
for(int a1:a){
//If any negative number found increment the count
if(a1<0)
count++;
  
}
//Return total count of negative number
return count;
}
  
public static int indexOfMin(int a[],int size){
int min=0;
for(int i=1;i<size;i++){
//Find the index of minimum number
if(a[min]>a[i])
min=i;
}
return min;
}
}

Output:

Array Contains negative number ? true
Array Contains first negative number at index :4
Array negative number Count :2
Array Contains the minimal number at index :7

Add a comment
Know the answer?
Add Answer to:
In class Recursion problems bool anyNegative(int al , int size) This function returns true if there...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( )...

    TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( ) : int findMin ) int findScore (value: int): bool res(): int Write the constructor method. It fills the array with random number from 0-100. Find below the code to get your started 1. public TestScores () Random rand -new Random); for (int i-0 i<SIZE i+) socresi] -rand.nextInt (101); Finding the maximum value in an array. Write the method findMax. It returns the maximum value...

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

  • In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an...

    In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...

  • Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int)

    please do in c++Q4. Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int) that when passed a non-negative integer, returns the number of occurrences of the digit 7 in the number. So, for example: count7s(717) → 2 count75(7) →1 count7s(123) → 0 Q5. Write a C++ function of the form string mirrorEnds(string)that when given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...

  • What does this function do? int mystery(double employees[], double id, int size) { for (int i...

    What does this function do? int mystery(double employees[], double id, int size) { for (int i = 0; i < size; i++) { if (id == employees[i]) { return i; } } return -1; } A. This is a function that performs a search. If the id is found in the employees array, its index location is returned, otherwise -1 is returned. B. This is a function that sorts the employees array C. This is a function that returns all...

  • The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function...

    The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public:    ...

  • Given an array of strings, return true if each string's size is equal or greater than...

    Given an array of strings, return true if each string's size is equal or greater than the one before, otherwise return false. The array will be length 2 or more. Example 1: If the names array contains… “Edwin” “Satish” “Solomon” “Massoud” …then the function call stringsIncreasing (names, 4) returns true. Example 2: If the names array contains… “Janet” “Linda” “Jackie” “Marta” …then the function call stringsIncreasing (names, 4) returns false since string Jackie comes before Marta and has more letters...

  • C++ Need the step count for this function. int binarySearch(const int array[], int size, int value)...

    C++ Need the step count for this function. int binarySearch(const int array[], int size, int value) { int first = 0, last = size − 1, middle, position = −1; bool found = false; while (!found && first <= last) { middle = (first + last) / 2; if (array[middle] == value) { found = true; position = middle; } else if (array[middle] > value) last = middle − 1; else first = middle + 1; } return position; }

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT