Question

In: Computer Science

You will overload a function named printArray. The function will assign values to each element and...

You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. In C++

Solutions

Expert Solution

#include <iostream>

using namespace std;

void printArray(char arr[],int n){
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
}
void printArray(int arr[],int n){
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
}

int main()
{ char str[4] = {'C','+','+','\0'};
int a[4] = {1,2,3,4};
printArray(a,4);
cout<<endl;
printArray(str,4);
return 0;
}

 

 

Related Solutions

in C++ You will overload a function named printArray. The function will assign values to each...
in C++ You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. (6 points) Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables. (4 points)
Create a variable named specChars and assign it the values of all the punctuation items available...
Create a variable named specChars and assign it the values of all the punctuation items available on the top row of the keyboard, starting with the value above the number 1 through the value above the number 0. For example: !@#........ Prompt the user to enter a number between 1 and 10. For the number of times given by the user, randomly select one of the punctuation items in the specChars variable using the random.choice() function. Print the value that...
Define a function named posterize. This function expects an image and a tuple of RGB values...
Define a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function developed in Chapter 7 and shown below, but it uses passed in RGB values instead of black. def blackAndWhite(image): """Converts the argument image to black and white.""" blackPixel = (0, 0, 0) whitePixel = (255, 255, 255) for y in range(image.getHeight()): for x in range(image.getWidth()): (r, g, b) = image.getPixel(x, y) average =...
Assign an oxidation state to each element or ion: Part A V Express your answer as...
Assign an oxidation state to each element or ion: Part A V Express your answer as a signed integer. Part B Mg2+ Express your answer as a signed integer. Part C Cr3+ Assign an oxidation state to each atom in each polyatomic ion. Part B Express your answer as a signed integer. oxidation state of O: Part C OH− Express your answer as a signed integer. oxidation state of O: Part D Express your answer as a signed integer. oxidation...
PYTHON: Write a recursive function named linear_search that searches a list to find a given element....
PYTHON: Write a recursive function named linear_search that searches a list to find a given element. If the element is in the list, the function returns the index of the first instance of the element, otherwise it returns -1000. Sample Output >> linear_search(72, [10, 32, 83, 2, 72, 100, 32]) 4 >> linear_search(32, [10, 32, 83, 2, 72, 100, 32]) 1 >> linear_search(0, [10, 32, 83, 2, 72, 100, 32]) -1000 >> linear_search('a', ['c', 'a', 'l', 'i', 'f', 'o', 'r',...
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload...
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload and test function doubleNum(int) to also work with a parameter of type double. 3. Both functions for collecting input should validate such that negative values would not be allowed. Perform the following steps: a. Add the function prototypes at the top. b. In main(), add a new variable of type double. You can name it "value2" to distinguish from the other variable. c. Write...
For the following reaction KClO3---->KCl+1/2 O2 assign oxidation states to each element on each side of...
For the following reaction KClO3---->KCl+1/2 O2 assign oxidation states to each element on each side of the equation...reactants and products. Which element is oxidized? Which element is reduced? Reactants for K, Cl, and O please.
What does it mean to overload a function? What are the requirements?
What does it mean to overload a function? What are the requirements? Give an example of 2 overloaded functions.
create a function that sorted tuple by the second values of each tuple. If the values...
create a function that sorted tuple by the second values of each tuple. If the values are the same, sorted by increasing order. Finally returns a list of the first element of each tuple that sorted. def sort_tup(tup): #Code here input : tup1 = [(1, 15), (2, 8), (3, 22), (4, 30), (5, 15)] output: [4,3,1,5,2]
Make a python code. Write a function named max that accepts two integer values as arguments...
Make a python code. Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Write the program as a loop that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT