Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<p>Please utilize C++ to answer the questions</p> <p>&#160;1. Assume that an arr

ID: 3626565 • Letter: #

Question

<p>Please utilize C++ to answer the questions</p>
<p>&#160;1. Assume that an array of integers named&#160; a that contains exactly five elements has been declared and initialized.</p>
<p>&#160;Write a single statement that assigns a new value to the first &#160;element of the array. This new value should be equal to twice the value stored in the last &#160;element of the array.</p>
<p>&#160;Do not modify any values in the array other than the first element.</p>
<p>2.&#160;An vector of&#160; int named&#160; a that contains exactly five elements has already been declared and initialized. In addition, an&#160; int variable&#160; j has also been declared and initialized to a value somewhere between 0 and 3.</p>
<p><br />&#160;Write a single statement that assigns a new value to the element of the vector indexed by&#160; j . This new value should be equal to twice the value stored in the next element of the vector (i.e. the element after the element indexed by&#160; j ).</p>
<p><br />Please be sure not to&#160;modify any other elements of the vector. Thanks</p>

Explanation / Answer

1. a[0] = 2 * a[ sizeof(a)/sizeof(int) - 1] The sizeof (a) finds the total size of your array in bytes, and then subtracts it by the type of each value in the array - in this case, int, so that you can find the number of elements in the array. The -1 part gets you the last element, since arrays start at 0 (this is called zero indexing) 2. a[j] = 2*a[j+1] I'm pretty sure you can use the [] syntax with vectors, but I'm not completely sure. But anyways, the logic should be sound.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote