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 =...
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',...
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...
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?
Give the named probability distribution for each of the following random variables with specific parameter values....
Give the named probability distribution for each of the following random variables with specific parameter values. You should name the parameters, that is, write the parameter name in your answer (for example, Binomial(n=30,p=0.5)) a) One of Nia’s cat meows when he wants petting. Assuming that the meows are independent of each other and the probability that a meow results in petting is 0.7, what is the distribution of Y: the number of meows until Nia pets him? (b) Nia has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT