Write a template function that returns the average of all the elements of an array. The arguments to the function should be the array name and the size of the array (type int). In main (), exercise the function with arrays of type int, long, and double.
Q: 1. Implement a function named insert that takes a dynamically allocated array of ints, the array’s…
A: the program is an given below :
Q: Task 01: Create an array of 10 elements. Initialize it as follows. INITIAL array: 24 58 13 15 63 9 8…
A: arrays : An array is a linear data structure that is used to store the elements of the same data…
Q: Implement the following: 1) Define a function subMessage() which takes two parameters, a and b. a is…
A: Program import random def subMessage(text1,n): substr=text1[0:n] print(substr) n =…
Q: Write in C++ 1. Define a struct for a soccer player that stores their name, jersey number, and…
A: #include<iostream>#include<string>using namespace std; //struct for a soccer player that…
Q: Write a template function that returns the average of all the elements of an array. The arguments to…
A: PROGRAM STRUCTURE: Include the required header files for using various functions. Include iostream…
Q: Write the code to copy values in one array to another. In the following code snippet, we copy values…
A: To allocate space, new operator is used followed by type of variable. To de-allocate memory, delete…
Q: Write a removeAllValuesMatching Function--PHP Write a function removeAllValuesMatching($arr, $value)…
A: Given array is $arr = array( 'a' => "one", 'b' => "two", 'c' => "three", 'd'…
Q: Print the following List in the reversed order using lambda / arrow operator. var array = new List…
A: Print the following List in the reversed order using lambda / arrow operator. var array = new List…
Q: Q3: Write a function for given main function int * return_an_array(int n) which takes an integer n…
A: The function first finds size of array to be created by finding number of digits in function…
Q: Write a function in c++ that will receive a pointer to the address of the first element of the array
A: The C++ program is written where the input will be taken from the user and will store in the array.…
Q: C++ 1.Write the function with function header void processList (int list [], int newList[], int…
A: #include <iostream> using namespace std; /*Define a function that receives as arguments two…
Q: Question 2. Write a C++ program to perform following tasks: Declare a dynamic array of size 's’.…
A: #include<iostream>using namespace std;int main() { int s,i,randomNumber; cout <<…
Q: Please answer in c++. Create a template class UniversalArray which createss an array of a given…
A: Solution :: The program code to copy is provided along with the program code screenshots and the…
Q: Q1) Write the prototypes and the definitions of the overloaded functions FillA(string, fchar),…
A: Step 1 : Start Step 2 : Declare the prototypes of the overloaded function FillA and Define the…
Q: Q3: Write a program in C++ using OOP to create a class (A), that have a two dimensional array…
A: /******************************************************************************…
Q: 1. Define a struct for a soccer player that stores their name, jersey number, and total points…
A: As per Bartleyby guideline: “Since you have posted a question with multiple sub-parts, we will solve…
Q: .13 Define a method named swapValues that takes an array of four integers as a parameter, swaps…
A: Java code to swap elements at index 0 and 1, 2, and 3 are given below with an output. Algorithm:…
Q: // Program 4.7.1 #include using namespace std; double getAverage(int *arr, int size); // function…
A: In this question array name balance store 5 elements and getAverage function find average of…
Q: 2. Write a function that has one parameter which is an array of type double with 50 elements. The…
A: #include <iostream> using namespace std; // Function to find the last negative element in the…
Q: 1. Given the following array declaration: int A [3 ][2 ]={{13, -23}, {3, 80} ,{91,55} }; declare…
A: I give the code in CPP along with output and code screenshot
Q: 6. Write a C++ program to check whether the sequence of the numbers in a given array is a…
A: I give the code in c++ along with output screenshot and code screenshot
Q: 4. Consider the following function main: int main() { int alpha[20]; int beta[20]; int gamma[4] =…
A: PROGRAM: //Header file #include<iostream> #include<iomanip> //Using namespace std…
Q: 1.Write a c++ program that adds the value present at index 5 8 and 3 of an array called Array_1…
A: datatype array_name [ array_size ]; For example, take an integer array 'n'. int n[6]; n[ ] is used…
Q: 13.5 LAB: Zip code and population (class templates) Define a class StatePair with two template types…
A: Code is written below in c++ language- Main.cpp #include<iostream>#include…
Q: Consider a Dynamic Array declared inside the code using int* z = new int[10]; . How we will free the…
A: memory is the very important component while writing programs and to avoid running out of memory,…
Q: I am having trouble with these 2 review questions for my C++ course. Ex 9: Storing an array into a…
A: Because of our guidelines, we can answer only one question so post other question seperately.
Q: Write a template function that returns the average of all the elements of an array. The arguments to…
A: Answer in step2
Q: Consider an 1-d array of type int and a pointer pointing variable pointing to the 2nd item of the…
A: Q: Code the given problem
Q: 25) Write C++ for a Function that receives an int array named array of length 5 and shows the memory…
A: #include <iostream> using namespace std; //creating function void func(int array[]){…
Q: Write a template function that returns the third minimum out of all the element of an array. The…
A: Algorithm: Start Define a template function to return the third minimum element of an array Let the…
Q: 6. Write a swap function, that swaps the values of two variables in main, but use pointers instead…
A: As per our policy, "Since you have asked multiple questions, we will solve the first question for…
Q: Q1 / Write a program in C++ that reads a binary array of dimensions (383) containing integers, and…
A: Given: Q1 / Write a program in C++ that reads a binary array of dimensions (383) containing…
Q: Write a program in C++ using OOP to create a class (A), that have a two dimensional array X[5][5],…
A: Please note the data type of the X is not mentioned i have used int.
Q: Write a program in C/C++ that receives a series of integer values from the user. The user nominates…
A: Let us use C++ programming.
Q: 3) a)Write a function template for finding the minimum value contained in an array.
A: As per our guidelines we are supposed to answer only one question. Kindly repost the remaining…
Q: 10. What is the result of the following code in C++ ? (assume all #include and the unseen code is…
A: p points to array x then exchange values using pointer in the for loop to after exchanging value…
Q: 13.5 LAB: Zip code and population (class templates) Define a class StatePair with two template…
A: C++ code: main.cpp #include<iostream>#include <fstream>#include <vector>#include…
Q: 1. Write a statement that defines a string constant called Terminal that has the value…
A: Given:
Q: 13.5 LAB: Zip code and population (class templates) Define a class StatePair with two template types…
A: Note: TODO code is highlighted bold in StatePair.h and StatePairMain.cpp files. Sample data…
Q: Q5. (a) Write a program to input a list of numbers in an array and then rearrange this array in such…
A: Introduction of the Program: The C program takes the size of the array from the user and then the…
Q: Implement the binary search function below that returns the index of the target value in an integer…
A: ALGORITHM:- 1. Initialize the array with the given values. 2. Take input for the target number to be…
Q: Implement a function named insert that takes a dynamically allocated array of ints, the array’s…
A: Note : As per guidelines of the company, we are authorized to answer first question when multiple…
Q: 3.40 Implement function partition() that splits a list of soccer players into two groups. More…
A: This is your solution code
Q: What do the keywords virtual and override do in C++?
A: Function overriding is redefinition of base class work in its inferred class with same mark i.e…
Q: 13.5 LAB: Zip code and population (class templates) Define a class StatePair with two template…
A: The answer is given in the following steps for your reference.
Q: **11.18** Java Solve (ArrayList of Character) Using the following header, create a method that…
A: Introduction We need to write a java program that converts String to an Arraylist of characters. We…
Q: Q 5. Write a program in C++ using object oriented concepts to input a list of numbers in an array…
A: Sample Response: //C++ program to arrange the odd and even numbers…
Q: 5.b. How do you define and use double indirection pointers, pointer to array and array of pointers?…
A: In C programming, pointers are used to hold the address value of a variable that can be declared in…
Q: Implement Exercise 8-13 using single-dimensional parallel arrays. (8-13: Write a program to…
A: EXPLANATION: - void readFile(ifstream& infile,string names[],double scores[][5],int& n): -…
Q: First, write a function which will find the sum of all elements of one-dimensional array:…
A: Programming instructions: Include necessary header files. Declare and initialize the array. Call…
10.1 Write a template function that returns the average of all the elements of an array. The
arguments to the function should be the array name and the size of the array (type int). In main (),
exercise the function with arrays of type int, long, and double.
10.2 Create a function called amax() that returns the value of the largest element in an array. The
arguments to the function should be the address of the array and its size. Make this function into a
template so it will work with an array of any numerical type. Write a main () program that applies
this function to arrays of various types.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- 3. Consider an 1-d array of type int and a pointer pointing variable pointing to the 2nd item of the array. Write down the code for the following: int arr(10) = (5,6,23,4,89,70,12,78,33); int *ptr = arr+1; (a) Print the first item of the array using ptr. (b) Print all prime numbers of the array using value at address. (c) Print the last item of the array using a pointer to an array. You are not allowed to initialize the pointer to the address of the last item. Iterate using a loop to change the value of the pointer. (d) Now print the array in reverse order using a pointer. 1019.5.1: Use the addChoice method to add any needed instance variables. Provide a different implementation of ChoiceQuestion. Instead of storing the choices in an array list, the addChoice method should add the choice to the question text. For this purpose, an addLine method has been added to the Question class. ChoiceQuestion.java: /** A question with multiple choices.*/public class ChoiceQuestion extends Question{ // Add any needed instance variables, but don't store the choices // The choices should be added to the text of the superclass /* Your code goes here */ /** Constructs a choice question with a given text and no choices. @param questionText the text of this question */ public ChoiceQuestion(String questionText) { /* Your code goes here */ } /** Adds an answer choice to this question. @param choice the choice to add @param correct true if this is the correct choice, false otherwise */ public void…in c++ 1. Write a function that takes a 1 Dimensional array and an integer n andreturns the number of times ‘n’ appears in the array. If ‘n’ does not appearin the array, return -1.2. Write a function that takes a 2 Dimensional array and returns the positionof the first row with an odd sum. Assume that the column size is fixed at 4.If no sum is odd, return -13. Write a class, “pie”, that has a number of slices (int slices) as a privateproperty. Construct the pie with a number of slices and remove a slice witha function. Tell the user how many slices are in the pie.
- Create two dynamic arrays A and B with random numbers.a) Merge B in array A calling a function by reference.b) Delete the Prime numbers from the merged array A calling a function by pointer.c) Print the Array A in ascending order.You have to use only two Arrays A and B throughout the code. Be carefulabout memory leakage.Example:A= [20, 30, 5, 7, 19]B= [19, 10, 15, 11, 17, 25] a) After merging B in A, the merged Array A will look like-A= [20, 30, 5, 7, 19, 19, 10, 15, 11, 17, 25] b) After deleting prime numbers the merged Array would look like-A= [20, 30, 10, 15, 25] c) Finally print the merged array in ascending orderA= [10, 15, 20, 30, 25] In C++ Please6. Write a swap function, that swaps the values of two variables in main, but usepointers instead of reference parameters.7. Write a function that takes an array of ints and its size as arguments. It shouldcreate a new array that is the same size as the argument. It should set the values inthe new array by adding 10 to each element in the original array. The functionshould return a pointer to the new array. (Make sure you use dynamic memoryallocation) can i get answers for this two sub parts. thanks2. Implement a function called findMinGap that will return the smallest gap betweenadjacent entries of an integer array. A gap between two numbers is the absolutevalue of their difference. For example, if an array contains the elements {10, 14,-5, -3, 0, 5, 7}, the minimum gap is 2 (between -5 and -3).Title line: int findMinGap(int array[], int length)
- **11.18** Java Solve (ArrayList of Character) Using the following header, create a method that produces an array list of characters from a string: toCharacterArray public static ArrayListCharacter> (String s) ToCharacterArray("abc"), for example, returns an array list containing the characters 'a', 'b', and 'c'.CODE IN C++.Write the code to copy values in one array to another. In the following code snippet, we copy values from intArr1 to intArr2. Also, intArr1 will no longer be used and therefore the memory used for intArr1 should be deallocated....int * intArr1 = new int [2];// assign values to intArr1...int * intArr2; // now write the code for allocating space for intArr2, copying values from intArr1 to intArr2, and for deallocating space used by intArr1.I am having trouble with these 2 review questions for my C++ course. Ex 9: Storing an array into a file.a) Implement the integer array {1,2,3,4,5}.b) Implement a save function which stores the array into a file using comma delimited format (1,2,3,4,5).Example File1,2,3,4,5, Ex 10: Reading an array into a file.a) Implement a partially filled integer array of size 100.b) Implement a load function which:1) Reads the input file (from problem 9) one line at a time.2) Parses each line using stringstream into tokens (comma delimiter).3) Converts each token into an integer then stores each token into the array.c) Implement an output function that outputs the array to the console.Example Output (from file to the array, to console)1 2 3 4 5
- Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks3. Implement a function called findLargestIndex which returns the index of the rowwith the largest sum.ex. int array[3][6] = {{3, 6, 8, 2, 4, 1}, // sum = 24{2, 4, 5, 1, 3, 4}, // sum = 19{1, 0, 9, 0, 1, 0}}; // sum = 11If the findLargestIndex function was called using this array, it would return 0, asit is returning the index of the row, not the sum.Note that the number of columns is required when passing a 2d array to a function.Assume that 2D arrays passed to this function will have 6 columns.Title line: int findLargestIndex(int array[][6], int rows, int columns);5. Write a C++ function which accepts an int array and the array size as arguments. The function should dynamically create a new array which is the same size as the array passed in. Each element in the new array should be double the corresponding element in the array passed in. Return a pointer to the new array. E.g. if you pass in the array {2, -3, 5} of size 3, it should create a new array of size 3 with values {4, -6, 10} and return a pointer to it. int *doubler(int a[], int size) 6. Consider the following line of code: int temps[3] = {68, 72, 62}; - What does *temps contain? - What does *(temps+1) contain? - What does temps[1] contain? 7. The _____ function returns true if the character is an upper case letter of the alphabet: a) toupper() b) isupper() c) isalpha() d) isdigit() e) none of these 8. The _____ function converts a C-string to an int: a) strlen() b) length() c) len() d) atoi() e) none of these