Question

ii. why should you not test the function with a value of n ? (b) Now suppose that you are testing a function that calculates the sum of an array of integers. Provide values for four arrays that you would use as test inputs and their corresponding output values. 4. Function semantics [18] (a) Given the following function definition: double foo (dowb1e x, e0eb] e y, char o) ie (o ,+) return x + y; else ie (o=-) retyrn-y; else ie (o #+) retprn * y; else id (。ソ) return x / y; else ie (o = ) return pow(x, y); i. What, at a high level, does foo do? ii, What would be a better name for this function? iii, What is the logical error in this function:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer to b) : Two test an array which sums its integer elements,

1. select two very small numbers: 1,1, output=2

2. select one very large number and one very small number : 29989576, 2 output=29989578

3. select two very large numbers : 99999999, 88888777, output=188888776

4. select two normal numbers : 10, 50 output=60

Answer to 4 (a):

1. At high level, foo performs some elementry mathematical operations.

2. A better name for this function could be math_operations

3. A better way could have been to use return(0) statements.

Add a comment
Know the answer?
Add Answer to:
Why should you not test the function with a value of n -1? (b) Now suppose...
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 C++ program that will test function described below that use pointers and dynamic memory...

    Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...

  • Note: None of these functions should use cout. It is OK to use cout while debugging...

    Note: None of these functions should use cout. It is OK to use cout while debugging to check how your function is working, but your final submission should not contain cout in any function but main. Head ==== Name the source file for this section head.cpp. Write a function named "head" which takes an array of integers as an argument, and returns the first element in the array. Write a function named main which outputs the result of testing your...

  • This assignment will test your algorithm/logic development in which you will perform the sort function with some different characteristics.

    This assignment will test your algorithm/logic development in which you will perform the sort function with some different characteristics. You will be required to ensure that your program meets the following requirements: i.    Existence of an array which can accept an unknown number of positive integersii.    ExistenceofafunctionwhichcanperformadifferentsortwheretheEvennumberswillappear first before the Odd numbers. In this sorted sequence, all the even numbers will appear first in descending order followed by the odd numbers (in the same order). You are only allowed to use one...

  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

  • 1. All functions should be written AFTER the main procedure. 2. A function prototype should be...

    1. All functions should be written AFTER the main procedure. 2. A function prototype should be written for each function and placed BEFORE the main procedure. 3. Each function should have a comment explaining what it does. 4. Each function parameter should have a comment explaining the parameter. 5. Prompt for the number of elements of the list. 6. Allocate an array whose size equals the number of elements specified by the user. 7. Read into the array the elements...

  • Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called...

    Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called isright, that takes three inputs, a, b, and c, and determines whether they are could be the lengths of the sides of a right triangle; the output, y, will be set equal to the following: i). -1 if at least one of the values is not positive. Also, only for this case, have the function print out an error message, which states "At least...

  • (b) Suppose you are designing a search aggregator, which for a given query fetches search results from two different se...

    (b) Suppose you are designing a search aggregator, which for a given query fetches search results from two different search engines and presents an intersection of the two search results. Here is a simplified version of this problem: Given two sorted integer arrays of lengths m and n, return a new array with elements that are present in both input arrays. The input array may contain duplicates, but there should be no duplicates in the output array. For example, if...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • How would you interpret (1-a) in the hypothesis testing framework? A)the power of a test B)...

    How would you interpret (1-a) in the hypothesis testing framework? A)the power of a test B) the probalilitybof a type I error C)The probalility of failing to reject the null hypothsis then it is true D) the probability of Type Ii error

  • Given below is a partially completed C program, which you will use as a start to...

    Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count - @; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; return count; Task 1: (10 pts) Show the design of the function compareAndCount() by writing a pseudocode. To...

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