Question

C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It...

C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that array. The input parameters should be modified so that it holds the length of the array, the high value, and the low value. In main, call the function 1 to print out the array. *not including the high – in general when we specify a range, we include the first value but not the last. If I forget to say that in the future, you can assume that’s what I intended.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <cstdlib>

using namespace std;

int *function1(int *x, int *y, int *z) {

int random = rand()%(50-25) + 25; // excluding 25

int *arr = new int[random];

int high = rand()%(10 - 5 + 1) + 5;

int low = rand()%(-5 - (-10) + 1) + (-5);

*y = high;

*z = low;

*x = random;

for(int i=0; i<random; i++) {

arr[i] = rand()%(high-low) + low;

}

return arr;

}

int main() {

int high, low, n;

int *arr = function1(&n, &high, &low);

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

cout<<arr[i]<<" ";

cout<<endl;

delete [] arr;

return 0;

}

firstweek firstweek firstweek g++ cplusfunction.cpp firstweek./a.out 2 4 20251050 2351 1 4 4 3 135433021 1 2 2 1 2 firstweek

Add a comment
Know the answer?
Add Answer to:
C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It...
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
  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • Write a function that takes as an input parameter an integer that will represent the length...

    Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number in...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • Solve this problem using pointer variables wherever possible. to be completed in C Problem -  sort 3...

    Solve this problem using pointer variables wherever possible. to be completed in C Problem -  sort 3 numbers Modify the sort 3 program you previously wrote, to use pointers.  In main( ) read 3 numbers from the user into low, medium, high, then call a function to “sort” them. That is, if low = 50, medium = 10 and high = 30 before the function is called, then after the function call the variables will contain low = 10, medium = 30...

  • Write a C++ function that takes a pointer to an array of integers as a parameter...

    Write a C++ function that takes a pointer to an array of integers as a parameter and return the number of prime integers in the array. Write main() program to test the function.

  • Write a function that takes as input parameters an array of characters and a length field....

    Write a function that takes as input parameters an array of characters and a length field. The function will create a square matrix from the array by first determining the largest square matrix that will hold as many numbers as possible yet not have any blank spaces. So, for instance, if the array’s length was 22, the largest square matrix would be 4x4. If the array’s length was 37, the square matrix would be 6x6. Then create the square matrix...

  • please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function...

    please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...

  • IN C++ Write a function numberOfOddNumbers that takes an array of integers and its size (length)...

    IN C++ Write a function numberOfOddNumbers that takes an array of integers and its size (length) as parameters and then returns the number of the odd numbers found in the array. For example, if an array called list stores the following values: int list []= { 1,1, 8,6,9,4,3,9595,0 }; Then the call of numberOfOddNumbers (list,9) should return 5. If instead, the list had stored these values: int list2[] = { 2, 4, 6, 8, 10, 208 }; Then the call...

  • Code in C++ please! Write a function that takes an array of integers as an input...

    Code in C++ please! Write a function that takes an array of integers as an input parameter (the address of the first value of the array). It returns nothing. It prints out the array as a single line, with commas between each number, and when the array is finished being printed, it prints an endl; so that we flush the buffer and move to a new line. (I’m having you write this function because you’ll be wanting to print out...

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