1. Define an array of ints with the ten elements { 0, 1,2,3, 4, 5, 6, 7, 8, 9 }. 2. Define a vector with those ten elements. 3. Define a list with those ten elements. 4. Define a second array, vector, and list, each initialized as a copy of the first array, vector, and list, respectively. 5. Increase the value of each element in the array by 2; increase the value of each element in the vector by 3; increase the value of each element in the list, by 5. 6.Print out a label and then the values of each of the containers
ANSWER:
#include<iostream>
#include <vector>
#include <list>
using namespace std;
int main(){
// an array of ints
int a[10]={0,1,2,3, 4, 5, 6, 7, 8, 9 };
//a vector<int>
std::vector<int> v (&a[0],&a[0]+10);
//List <int>
std::list<int> l (&a[0],&a[0]+10);
//Define a second array, vector, and list, each initialized as a
copy of the first array, vector, and list, respectively
int b[10];
for(int i=0;i<10;i++){
b[i]=a[i];
}
std::vector<int> v2(v);
std::list<int> l2(l);
// Increase the value of each element in the array by 2
for(int i=0;i<10;i++){
b[i]+=2;
}
//Increase the value of each element in the vector by 3;
for(int i=0;i<10;i++){
v2[i]+=3;
}
//Increase the value of each element in list by 5.
for (std::list<int>::iterator it = l2.begin(); it !=
l2.end(); it++)
*it=*it+5;
cout<<"Values of each of the containers are:
"<<endl;
cout<<"First Array is"<<endl;
for(int i=0;i<10;i++){
cout<<a[i]<<" ";
}
cout<<"\nFirst Vector is:\n";
for(int i=0;i<10;i++){
cout<<v[i]<<" ";
}
cout<<"\nFirst List is:\n";
for (std::list<int>::iterator it = l.begin(); it != l.end();
it++)
cout << *it << ' ';
cout<<"\nSecond Array is"<<endl;
for(int i=0;i<10;i++){
cout<<b[i]<<" ";
}
cout<<"\nSecond Vector is:\n";
for(int i=0;i<10;i++){
cout<<v2[i]<<" ";
}
cout<<"\nSecond List is:\n";
for (std::list<int>::iterator it = l2.begin(); it !=
l2.end(); it++)
cout << *it << ' ';
return 0;
}

1. Define an array of ints with the ten elements { 0, 1,2,3, 4, 5, 6,...
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
Consider a non-empty int array ints. A contiguous subarray ints[ start .. start + len -1 ] (with starting index start and length len) is called a flat if all elements of that subarray are equal. Furthermore, such a subarray is called a plateau if it is flat and each of the elements ints[start -1] and ints[start + len] that immediately proceed/succeed the subarray are either nonexistent (i.e., out of array’s index range) or are strictly smaller than the elements...
a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...
Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array? Shows the code. Consider the declaration: int v[1]; What is the index of the last element of this array? Declare an array named a of 10 int elements and initialize the elements (starting with the first) to the...
Can I please get some help with this?? It's matlab.
Code 1 1) Define a function as [NE]- nb_elemt24( n1,n2). 2) Define two vectors A and B by randi(10, [1,n1]) and randi(10, [1,n2]), respectively. 3) Using the commend [C1,D1] hist(A, unique(A)) to find four vectors C1, D1 (for A) and C2, D2 (for B), respectively. Here, vector C1 shows how many times each element of A is repeated. And the elements of vector D1 are the same as elements of...
f a as a sequence of adjacent array elements such that each value in the run array was of size 10 9. We define a "run" of elements o (except for the first) is one greater than the previous and looked like: value. For example, say the 3 2 16 9 7 8 9 2 a: position 0 3 We have three runs in this array: (1) between 9,10,1, 12) and, (3) between positions 7 and 8, (15, 16) positions...
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...
In C++, develop a class that supports array rotation. Rotating an array is an operation where you shift all elements of the array some number of positions left or right, and elements that are shifted off of the left or right end of the array "wrap around" to the right or left end, respectively. For example, if we rotate the array [1, 2, 3, 4, 5] to the right by 1, we get the array [5, 1, 2, 3, 4]....
I ONLY NEED PART 4 I HAVE DONE 1,2,3 Arrays This assignment is designed in small progressive parts, with the intention of developing the skill of working with arrays. Do each part separately. Include in your submission the code and output for Part I, then the code and output for Part 2, etc. into a Word document. Specification: Part 1. Write a main function that declares an array of 10 int’s. Assign each element in the array a value between...