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

Question 2 – 25 Points Write a function check_all_equal(int[ ] array) that: Take

ID: 3700627 • Letter: Q

Question

Question 2 – 25 Points

Write a function check_all_equal(int[ ] array)that:

Takes as input array of integers. The array can have any length.

If the array length is 0, the function returns Boolean value true.

If the array length is not 0:

The function returns trueif all values in the array are equal to each other.

The function returns falseotherwise.

For example:

If a1 = {20, 20, 20, 20, 20}, then check_all_equal(a1)returns true, since all values equal 20.

If a1 = {1, 1, 1, 2}, then check_all_equal(a1)returns false, since not all values are equal to each other.

If a1 = { }, then check_all_equal(a1)returns true, because the array is empty.

Question 3 – 25 Points

Write a function positions (int[ ] numbers, int N)that returns an arrayof integers, containing all positions in numberswhere the value stored is NOT equal to N.

If Nappears in all positions, or if numbersis an empty array, the function should return an empty array. Note: you can create an empty array by giving it a size of 0 when you declare it.

IMPORTANT: MAKE SURE THAT YOUR FUNCTION RETURNS AN ARRAY, NOT AN ARRAY LIST.

For Example:

If a1 = {5, 20, 20, 10, 40, 20}, then positions(a1, 20)returns array {0, 3, 4}, because value 20 does NOTappear at positions 0, 3 and 4 of a1.

If a1 = {2, 1, 2, 2}, then positions(a1, 2)returns array {1}, because value 2 does NOTappear at positions 1 of a1.

If a1 = {3, 3, 3, 3}, then positions(a1, 3)returns the empty array{ }, because value 3 appears in every position of a1.

If a1 = { }, then positions(a1, 2)returns the empty array { }, because a1 is empty.

Question 4 – 25 Points

Write a function select_strings(ArrayList<String> strings)that returns an ArrayListof strings, containing every string in stringsthat has at least one numerical digit in its characters. A numerical digit is any of the characters in string “0123456789”.

IMPORTANT: MAKE SURE THAT YOUR FUNCTION RETURNS AN ARRAY LIST, NOT AN ARRAY.

For example:

If a1 = [“hello”, “123”, “az7”, “az”], thenselect_strings(a1)returns array list [“123”, “az7”], because “123” and “az7” are the only strings in a1 that contain a numerical digit.

If a1 = [“{hello”, “az”], then select_strings(a1)returns the empty array list [ ], because none of the strings in a1contains a numerical digit.

BONUS QUESTION - 5 POINTS

Write a function most_frequent (int[] array), that returns the value in arraythat occurs the most times.

For Example:

If a1 = {5, 20, 10, 40, 20}, then most_frequent(a1)returns 20, because value 20 appears twice in a1, and no other value appears more than once.

If a1 = {2, 2, 1, 2, 1, 1, 1}, then most_frequent(a1)returns 1, because value 1 appears four times in a1, and no other value appears more than three times.

If there is a tie among multiple values for the highest number of occurrences, your function should return the last of those values that are tied.

For example: if a1 = {2, 2, 1, 7, 3, 7}, then most_frequent(a1)should return 7, since both 2 and 7 appear twice, but the last 7 occurs after the last 2.

Explanation / Answer

//answer for 2nd question:

#include<stdio.h>

int n;

void check_all_equal(int a1[])

{

int i,check=a1[0],flag=1;

for(i=1;i<n && flag!=0;i++)

{

if(a1[i]==check)

{

flag=1;

}

else

{

flag=0;

}

}

if(flag==1)

printf("true");

else

printf("false");

}

int main()

{

int a1[]= {20, 20, 20, 20, 20};

n=sizeof(a1)/sizeof(int);

if(n==0)

{

printf("true");

}

else

{

check_all_equal(a1);

}

return 0;

}

//answer for 3rd question.

#include<stdio.h>

int n;

void positions(int *a1,int N)

{

int i,check=0;

for(i=0;i<n;i++)

{

if(a1[i]!=N)

{

printf("%d ",i);

check=1;

}

}

if(check==0)

printf("array{}");

}

int main()

{

int a1[]= {5, 20, 20, 10, 40, 20};

n=sizeof(a1)/sizeof(int);

if(n==0)

{

printf("array{}");

}

else

{

positions(a1,20);

}

return 0;

}

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