Question

C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array...

C++

3. Random modification of all elements in an integer array.
a) Initialize an integer array of capacity 5.
b) Implement an array output function.
c) Output the array to console.
d) Implement an offset function that accepts an integer array as input and randomly
modifies each element by +/- 5.
e) Use the offset function to update the array.
f) Output the modified array.
Example Output (input in bold)
Original: 5 1 4 9 2
Offset: 7 -2 6 11 4

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

#include <iostream>

using namespace std;
void printArray(int arr[]){
for(int i=0;i<5;i++)
cout<<arr[i]<<" ";
cout<<endl;
}
int main()
{
int arr[]={5 ,1 ,4 ,9 ,2};
printArray(arr);
for(int i=0;i<5;i++){
  
if(rand()%2==0)
arr[i]+=5;
else
arr[i]-=5;
}
printArray(arr);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array...
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
  • Using C++ Insert elements into a partially filled array. a) Create a partially filled array of...

    Using C++ Insert elements into a partially filled array. a) Create a partially filled array of CAPACITY 100. b) Initialize the array with values 10,20,30,40,50,60,70,80,90,100 c) Create a print function for the array. d) Create an insert function which inserts an integer into the array in sorted position. e) Insert the numbers 5, 150 and 55. f) Print the array before and after each insertion. Output Example 10 20 30 40 50 60 70 80 90 100 5 10 20...

  • 7) Implement a two-dimensional grid with a one dimensional array. a) Implement an empty array of...

    7) Implement a two-dimensional grid with a one dimensional array. a) Implement an empty array of four integers. D) Request four integers from the console and store them into the array. In this array, the index represents a column, the value a row. c) Implement an output function to display the array as a two-dimensional grid of X's and dots where x is an array coordinate. Example output (input is bold and italicized) : Enter 4. row values (from 0...

  • Request an integer n from the console. Write a function that accepts n as input and...

    Request an integer n from the console. Write a function that accepts n as input and outputs the multiplication table of n from 1 to n to the console. Example Output (input in bold italics) Enter an integer: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9...

  • 1. Write a C function named find that receives a one-dimensional array of type integer named...

    1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer. The function fills the array with values that are the power of four (4^n) where n is the index. After that, the function must select a random index from the array and move the array elements around the element stored in the randomly selected index Example arr = [1, 4, 16, 64, 256) if the randomly selected...

  • Write a C++ function that prints an array, skipping over a number of elements. Use the...

    Write a C++ function that prints an array, skipping over a number of elements. Use the following header: void printArraySkip(int array[], int elems, int skip) { } Where 'array' is an input array of 'elem' integer elements, and 'skip' is the number of elements to skip over. For example, if the function is called like this: int array[6] = { 5, 7, 11, 12, 18, 19 }; printArraySkip(array, 6, 2); The output would be: 11 19 in c++. Thanks

  • Given an array of integer, please complete a function multiply(). The function accepts the first memory...

    Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example:   multiply([ 1, 2, 3], 3) → 6   multiply([1, 1, 4 ,2], 4) → 8   multiply([7, 0, 0, 7, 0, 7],...

  • Unit 4 Assignment 5: Coding Project using C# Binary Search Scenario Use the same integer array...

    Unit 4 Assignment 5: Coding Project using C# Binary Search Scenario Use the same integer array named partNumbers that you used for task 3. Sort the array in ascending order. 1065, 1095, 1075, 1055, 1056, 1090, 1098, 1088, 1097, and 1078. Java: use Array.sort() C#: use Array.Sort() PHP: use sort() Write code that asks the user to enter two part numbers. For C#, use console input. Implement a binary tree search function called binarySearch() to search the array for the...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) Matlab question Matrix Notation Interpreter (matrix elements to cell array of formatted character...

    Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) Matlab question Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) A system of linear algebraic equations can be writen in matrx notation by applying the definizion of matrix multiplication. For example, the linear system Can be writen as or where and x = 2 matrix input ror the variable A and a × T e function command dennes the output variable linearSystem Code has...

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