Question

In: Computer Science

array • First, create a function called addNumber, which has a formal parameter for an array...

array
• First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10.
o Add any other formal parameters that are needed.
• Second, create another function called printReverse that prints this array in reverse order.
• Then, you need to write a C++ program to test the use of these two functions.

Solutions

Expert Solution

Solution:-

C++ Code:-

// Including necessary header files
#include <iostream>
#include <time.h>
using namespace std;
// Function incrementing each array element by a random integer
void addNumber(int A[],int k,int s)
{
// Looping for each element
for(int i=0;i<s;i++)
{
// incrementing each element by random integer
A[i] += k;
}
}
// Function printing the updated array in reverse order
void printReverse(int A[],int s)
{
cout<<"Array in reverse order: ";
// Looping form last index till first index element
for(int j=s-1;j>=0;j=j-1)
{
// Printing the array
cout<<A[j]<<" ";
}
}
// Main function
int main()
{
// Declaring an array
int num, A[] = {21,14,5,11,7,19};
// Computing size of array
int len = sizeof(A) / sizeof(A[0]);
// random seed initialization
srand(time(NULL));
// Taking random integer from 1 to 10
num = rand()%10 + 1;
// Printing the generated random integer
cout<<"Random integer = "<<num<<endl;
// Calling addNumber function
addNumber(A,num,len);
// Calling printReverse function
printReverse(A,len);
return 0;
}

Code snapshot:-

Output snapshot:-


Related Solutions

Define a function called 'filterWords, which takes a parameter. The first parameter, text" is an nltk.text.Text...
Define a function called 'filterWords, which takes a parameter. The first parameter, text" is an nltk.text.Text object. The function definition code stub is given in the editor. Perform the given operation for the 'text' object and print the results: • Filter the words whose length is greater than 15 from the complete set of 'text', and store into "large_words' variable as a list
C++ Write a function called linearSearch that takes an array as a parameter and search for...
C++ Write a function called linearSearch that takes an array as a parameter and search for a specific value inside this parameter. The function returns the frequency of a specific value in the array. In the main function: 1. Define an array called salaries of length 5. 2. Initialize the array by asking the user to input the values of its elements. 3. Define a variable called key and ask the user to enter a value for this variable. 4....
Create a function named ‘dividing’. This function will take one parameter value, which will be an...
Create a function named ‘dividing’. This function will take one parameter value, which will be an integer. For the function you will use ‘Exception Handling’ with the use of the try and except statements to try and return the results of a number divided by the parameter value given to the function. If the parameter passed to the function is the integer value of zero then your function should return ‘You tried to divide by zero!’ through the use of...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output of longestMorseCodeWords should be an array of the strings that were passed in, but ordered by the length of their Morse Code equivalent in descending order. If the length of Morse Code is equal, order the words alphabetically.For convenience, the full table for the 26 letters of the English alphabet is given below: [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] let words = ["gin", "zen", "gig", "msg"] longestMorseCodeWords(words) The Morse...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child)....
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Write a C++ program that has a function which given n>=0, create an array length n*n...
Write a C++ program that has a function which given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups) generateGroups(3) → [0, 0, 1, 0, 2, 1, 3, 2, 1] generateGroups(2) → [0, 1, 2, 1] generateGroups(4) → [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
Design and implement a function which has one input parameter which is a number which is...
Design and implement a function which has one input parameter which is a number which is greater than 50, called num. Then the function will create a dictionary whose keys are 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9. Then the function calculates the values for each of the above keys. The value for a key is all the numbers between 2 and input “num” that are divisible by the key. The function...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an int. The function should return a tuple containing that int and its square. Suppose you were to call your function like this: print(make_squares_coordinate_pair(5)) This should output: (5, 25) Your function MUST be called make_squares_coordinate_pair. You can write code in the main part of your program to test your function, but when you submit, your code must ONLY have the function definition! 2, Write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT