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
In class Recursion problems bool anyNegative(int al , int size) This function returns true if there...
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...
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 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...
Add a public member function to the BST class below that returns the size of the tree—the number of the nodes in the tree. For simplicity, the class contains only the key and not a value. You may add any helper functions you find necessary. (Hint: think recursion) template <typename T> struct Node { T key; Node<T>* left; Node<T>* parent; Node<T>* right; }; template <typename T> class BST { private: Node<T>* root; public: BST():...
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 = 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...
(a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....
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: ...
-Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (malloc format) (function prototype : void output(int *arrayPtr, int size); -Create a function check() in C that takes the pointer to the array and a number and checks if the number is in the array. If the number is in the array, returns the index of the element of the array holding the number. Otherwise, returns -1.
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 <<...