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)
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]
A new element has recently been discovered but not yet named. Call it element X.
A new element has recently been discovered but not yet named. Call it element X.63        X33a.) What is the mass number of element X?b.) What is the atomic number of element X?c.) How many neutrons does element X have?d.) How many electrons does element X have?e.) How many protons does element X have?f.) How many electrons does element X have in the valence shell?g.) Is element X more electronegative or more electropositive?
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array...
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array to the sum of the corresponding elements in two other arrays. That is, if array 1 has the values 2,4, 5, and 8 and array 2 has the values 1, 0, 4, and 6, the function assigns array 3 the values 3, 4, 9, and 14. The function should take three array names and an array size as arguments. Test the function in a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT