Question

In: Computer Science

How do i change the vector v to size 20 in C++. Also given the following,...

How do i change the vector v to size 20 in C++.

Also given the following, which line of code stores 40 into the 4th column of the 6th row of array dataVals?

const int rows = 7;
const int cols = 5;
int dataVals[rows][cols];

Select one:

a. dataVals[5, 3] = 40;

b. dataVals[5 * 3] = 40;

c. dataVals[3][5] = 40;

d. dataVals[5][3] = 40;

Solutions

Expert Solution

1. To increase the Size of vector in C++ , twn method can use .
[1] resize();
   The resize() method (and passing argument to constructor is equivalent to that) will insert or delete appropriate number of elements to the vector to make it given size (it has optional second argument to specify their value).
    It will affect the size(), iteration will go over all those elements, push_back will insert after them and you can directly access them using the operator[].
[2] reverse();
   method only allocates memory, but leaves it uninitialized. It only affects capacity(), but size() will be unchanged. There is no value for the objects, because nothing is added to the vector.
   If you then insert the elements, no reallocation will happen, because it was done in advance, but that's the only effect.

2. Array Will start From [0][0] and end with [n-1][m-1] for dataVals[n][m]
    So [D] dataVals[5][3] = 40 Correct Answer


Related Solutions

In c++ how do I search a vector for a name and then determine if the...
In c++ how do I search a vector for a name and then determine if the name is found?
Given the following 40x40 matrix below, with starting vector V shown below also, apply the power...
Given the following 40x40 matrix below, with starting vector V shown below also, apply the power method to find the dominant eigenvalue of matrix using MATLAB program, MAPLE program or some other computer program to print out: the estimate of the lambda with tolerance 0.01, the number of iterations, and the converged lambda. Then print out the transpose of the eigenvector (should be 40 components) produced with up to two decimals. Starting Vector V= [ 1 1 1 1 1...
I have a question in that if v is s any nonzero vector, and v is...
I have a question in that if v is s any nonzero vector, and v is positioned with its initial point at the origin, then the terminal points of all scalar multiples of v will occur at all the points on a straight line through the origin. But if we want to find two vectors, let's say m and n, that are parallel to each other, we need to determine whether they are multiples of each other. So my question...
how do I find the direction vector u, given the direction angles of 60 75 and...
how do I find the direction vector u, given the direction angles of 60 75 and 34.3 degrees?
What is an interrupt vector table. How do I create an interrupt vector table in Arm...
What is an interrupt vector table. How do I create an interrupt vector table in Arm Architecture . Please include as much information as you can, including pictures, examples etc. Thank you very much.
1. Vector u =< 0,−1,3 > is given. Find a non zero vector v which is...
1. Vector u =< 0,−1,3 > is given. Find a non zero vector v which is perpendicular to u. Then find a vector w which is perpendicular to both u and v. Explain the reason for your selection clearly. 2. Find the slope of the tangent line to the parametric curve x = 5 + sin(3θ) and y = −3 + 2tanθ at θ = π.
A) Given a vector electric field: E i = x̅100e−γ z V/m                       Find the associated magnetic...
A) Given a vector electric field: E i = x̅100e−γ z V/m                       Find the associated magnetic field. B) If this field is normally incident on a uniform lossy medium with Er = 3.0, tan δ = 0.1, and μ = μ0    initially propagating in air, find bot h the reflection and transmission coefficients.
Let V be a finite-dimensional vector space over C and T in L(V). Prove that the...
Let V be a finite-dimensional vector space over C and T in L(V). Prove that the set of zeros of the minimal polynomial of T is exactly the same as the set of the eigenvalues of T.
Given a doubly linked list in c++, how do I create a function that returns the...
Given a doubly linked list in c++, how do I create a function that returns the pointer to first node in the given pattern, For example, given mainList (a -> b -> c -> d) and sublist  (b -> c), our function should return a Node pointer that points to first node of the sublist in the mainList. If the pattern doesn't exist in the mainList, we should return a nullptr, there are multiple of the same sublist in the mainList,...
Given a doubly linked list in c++, how do I create a function that returns the...
Given a doubly linked list in c++, how do I create a function that returns the pointer to first node in the given pattern, For example, given mainList (a -> b -> c -> d) and sublist  (b -> c), our function should return a Node pointer that points to first node of the sublist in the mainList. If the pattern doesn't exist in the mainList, we should return a nullptr, there are multiple of the same sublist in the mainList,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT