CODE:
CODE (for copy):
#include<iostream>
#include<vector>
using namespace std;
int f1(vector<int> &vec, int **arr)
{
int arrlen = vec.size()/2;
*arr = new int[arrlen];
for(int i = arrlen-1; i >= 0; i--){
(*arr)[i] = vec.back();
vec.pop_back();
}
return arrlen;
}
int main()
{
vector<int> vec1(3); vec1[0] = 3; vec1[1] = 4; vec1[2] =
5;
vector<int> vec2(2); vec2[0] = 3; vec2[1] = 4;
int *array1, *array2;
int n1, n2;
n1 = f1(vec1, &array1);
// Should return with vec1 = {3, 4} and array1 = {5}, n1 = 1
/*
cout<<"Vector vec1: ";
for(int i=0;i<vec1.size();i++)
cout<<vec1[i]<<" ";
cout<<endl;
cout<<"Value of n1: "<<n1;
cout<<"\narray1: ";
for(int i=0;i<n1;i++)
cout<<array1[i]<<" ";
*/
n2 = f1(vec2, &array2);
// Should return with vec1 = {3} and array1 = {4}, n2 = 1
/*
cout<<"\n\nVector vec2: ";
for(int i=0;i<vec2.size();i++)
cout<<vec2[i]<<" ";
cout<<endl;
cout<<"Value of n2: "<<n1;
cout<<"\narray2: ";
for(int i=0;i<n2;i++)
cout<<array2[i]<<" ";
*/
// Cleanup code
delete[] array1,array2;
vec1.clear();
vec2.clear();
return 0;
}
For output remove the paragraph comments
OUTPUT:
For any doubt please comment.
1- Complete all the blanks in the function f1() below such that it implements the operations...
c++, need help thank you Given an array of ints, return the sum of all elements from the array that come before the first element that equals number 4 in the array. The array will contain at least one 4. Function prototype: int pre4int array ( ], int size); Hint: to find the array size, use: int size = sizeof(array) / sizeof( array[0]); Sample runs: int array1[ ] = {1, 2, 4, 1); pre4(array1, 4); // returns 3 int array2...
Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example: multiply([ 1, 2, 3], 3) → 6 multiply([1, 1, 4 ,2], 4) → 8 multiply([7, 0, 0, 7, 0, 7],...
Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...
Need help with java code, this is all in a method 1) 3 different arrays are brought in 2) I create local array called arrayWithLargestValues which is the size of the largest array from the 3 brought in 3) I need to somehow fill the local 'arrayWithLargestValues' with the all different largest values from the 3 different arrays hopefully I made sense sample input/output int [ ] arrayWithLargestValues = new int [ ] // this has to be set to...
Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...
Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...
Problem 6(15 Points) MARIE Assembly Programming Develop a MARIE program containing a main function which finds the smallest element of an array T is shown below. The passing arguments and one subroutine function called Sindmin findmin function array and the aro the findmin subroutine functon are the beginning e pseudo code for the subroutine elements of Array1 and Arra array size Continue the following MARIE program to find the smallest ORG 100 Jump Start nt findmin (int "addr, int size)...
Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....