Question

Write two (2) overloaded functions that find a string in another string (first function) and find...

  1. Write two (2) overloaded functions that find a string in another string (first function) and find an integer in an integer array (second function). These should be value returning functions that return:
    1. For the string find, the string value if found, “not found” if the string is not found.
    2. For the integer file, the value if found or -1 if not found.
    3. The string function will pass in a string to find and the containing string, e.g. the request could be to find “i“ in string “string“ ; the second will pass in an int and an integer array.
    4. Write the functions only. This includes the function headers (prototypes not needed) and the function bodies. You do not need to write the function calls, or any include or using statements.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: here is the answer for your question :

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

java code:

import java.util.*;


public class Main
{
static String find_function(String main_string, String substring )
{
if(main_string.contains(substring))
{
return substring;
}
else
{
return "not -found";
}
}
static int find_function(int arr[], int value )
{
for(int i=0;i<arr.length;i++)
{
if(arr[i]==value)
return value;

}
return -1;
}
   public static void main(String[] args) {
   int arr[]={3,6,7,8,5,4,6};   
   System.out.println(find_function("carter","e"));
   System.out.println(find_function(arr,10));
  
  
   }
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

code snippet:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

code output:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

I hope this would help you out

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
Write two (2) overloaded functions that find a string in another string (first function) and find...
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
  • Write a program that compares the execution speed of two different sorting algorithms: bubble sort and...

    Write a program that compares the execution speed of two different sorting algorithms: bubble sort and selection sort. It should do this via functions you must write with the following prototypes: void setRandomValues(int[], int[], int length); This function sets two integer arrays with identical random values. The first two arguments are two integer arrays of the same length, and the third argument is the length of those arrays. The function then sets each element in the first and second argument...

  • Using the program segment below, write two short functions to complete the program. Use the test...

    Using the program segment below, write two short functions to complete the program. Use the test cases to ensure the program works properly. Prototypes: void int2bin(int, int[8]); The first function will convert an integer that is between 0 - 255 to its binary representation. You are to store the binary number in the array passed to the function. void printBinary(int[8]); The second function will print the binary number stored in the array passed to the function. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Test 1: 13...

  • Problem 2 (USE C++) Assume you are given two functions: a function that returns –in a...

    Problem 2 (USE C++) Assume you are given two functions: a function that returns –in a variable passed by reference- the GCD of all integer numbers in an array void GCD(int A[], int size, int &g) and another function that allows you to divide all numbers of an array by a given integer void Div(int A[], int size, int gcd) (assume the functions are in a library, therefore you don’t need to implement them, but just use them). 1. Write...

  • 1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please...

    1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please show all outputs. Write functions to add one day, another function to add one month, and yet another function to add one year to a Date struct. struct Date { int year; int month; int day; }; Pass Dates by reference when appropriate (i.e., Date& or const Date&). For example, the following function returns by value a new Date instance with one day added...

  • Please write this code in python programming and provide a screen short of the code. Reading:...

    Please write this code in python programming and provide a screen short of the code. Reading: P4E 7; Tut 7.2, 7.2.1 Upload an original Python script that satisfies the following criteria: It has at least two functions Function 1: This function has one parameter, a string containing the path to an existing text file that will be read by your function Using a with statement, the function opens the file indicated by the parameter for reading The function counts the...

  • Write a function getScores(...) that is given a string, an int type array to fill and...

    Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • #include <iostream> //write preprocessor file for string datatype here using namespace std; //write your function prototypes...

    #include <iostream> //write preprocessor file for string datatype here using namespace std; //write your function prototypes here: int main() {     cout << "Welcome to Mad Lib.\n\n";     cout << "Answer the following questions to help create a new story.\n";     string name = askText("Please enter a name: ");          string noun = askText("Please enter a plural noun: ");          int number = askNumber("Please enter a number: ");          string bodyPart = askText("Please enter a body part: ");          string...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The...

    c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second function accepts as input a two-dimensional array of integers and integer value V. It returns true if the value V is found in the array, false otherwise. Write a main program that declares and initializes the following...

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