Chapter 6: Vectors: Participation Activities

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Array peoplePerDay has 365 elements, one for each day of the year. Valid accesses are peoplePerDay[0], [1], ..., [364]. What assigns element 0 with the value 250?

Answer: peoplePerDay[0] = 250 Explanation: Assigns element 0 with 250.

If itemPrices has elements 45, 22, 38, what is the vector after itemPrices.back() is called? Type answer as: 50, 60, 70

Answer: 45, 22, 38 Explanation: While push_back() appends an item and pop_back() removes the last item, back() merely gets the value of the last item, leaving the vector unchanged.

What is the resulting vector contents, assuming each question starts with a vector of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 3 ; ++i) { itemsList.at(i) = itemsList.at(i+1); }

Answer: -1, 0, 9, 9 Explanation: For each iteration, the next element is assigned to the current element. The loop expression exits before the last element.

What is the resulting vector contents, assuming each question starts with a vector of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 3 ; ++i) { itemsList.at(i+1) = itemsList.at(i); }

Answer: -55, -55, -55, -55 Explanation: After iteration with i = 0: -55, -55, 0, 9. With i = 1: -55, -55, -55, 9. Etc. New programmers commonly forget that each iteration deals with the latest modified vector.

Find the sum of all elements in vector valsVctr. valSum = ; for (i = -; i < NUM_VALS; ++i) { valSum += valsVctr.at(i); }

Answer: 0 Explanation: valSum is initialized to 0, then each element is added to valSum. Note that valSum= valsVctr.at(0) would be wrong, since valsVctr.at(0) would then be included twice in the sum.

What is the resulting vector contents, assuming each question starts with a vector of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList.at(i) = i; }

Answer: 0, 1, 2, 3 Explanation: First iteration assigns 0 to element 0. Next assigns 1 to element 1. Etc.

If vector itemPrices has two elements with values 45, 48, what does itemPrices.size() return?

Answer: 2 Explanation: The vector currently has two elements.

Array peoplePerDay has 365 elements, one for each day of the year. Valid accesses are peoplePerDay[0], [1], ..., [364]. Given the following statements: peoplePerDay[9] = 5; peoplePerDay[8] = peoplePerDay[9] - 3; What is the value of peoplePerDay[8]?

Answer: 2 Explanation: peoplePerDay[9] is 5. So peoplePerDay[9] - 3 is 5 - 3, which is 2.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; What value is assigned into yearsList.at(1)?

Answer: 2012 Explanation

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; What value does curr = yearsList.at(2) assign to curr?

Answer: 2025 Explanation: The element yearsList.at(2) is like its own variable. 2025 was earlier assigned to that element.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; What are the contents of the vector if the above code is followed by the statement: yearsList.at(0) = yearsList.at(2)?

Answer: 2025, 2012, 2025, 0 Explanation: Each element is its own variable, and can be read and assigned just like any other variable.

If itemPrices has elements 45, 22, 38, what does price = itemPrices.back() assign to price? Type error if appropriate.

Answer: 38 Explanation: back() gets the last element's value. back() does not remove that element, so another back() call would again yield 38.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; How many elments does the vector definition create?

Answer: 4 Explanation:

Using the above approach, how many swaps are needed to reverse this list: 999 888 777 666 555 444 333 222

Answer: 4 Explanation: 999 and 222 888 and 333 777 and 444 666 and 555

Given: vector<int> userVals(4), with element values 44, 55, 66, 77. Given: vector<int> newVals. What is newVals after: newVals = userVals; userVals.at(0) = 33; Type answer as: 10, 20, 30, 40 If appropriate type: Error

Answer: 44, 55, 66, 77 Explanation: Because newVals is a copy, subsequent changes to userVals don't affect newVals, and vice-versa.

Given: vector<int> userVals(4), with element values 44, 55, 66, 77. Given: vector<int> newVals. What is newVals after: newVals = userVals; Type answer as: 10, 20, 30, 40 If appropriate type: Error

Answer: 44, 55, 66, 77 Explanation: Each element of userVals is copied to newVals, which is resized from 0 to 4.

Array peoplePerDay has 365 elements, one for each day of the year. Valid accesses are peoplePerDay[0], [1], ..., [364]. Assume N is initially 1. Given the following: peoplePerDay[N] = 15; N = N + 1; peoplePerDay[N] = peoplePerDay[N - 1] * 3; What is the value of peoplePerDay[2]?

Answer: 45 Explanation: peoplePerDay[1] is assigned with 15. Then, peoplePerDay[2] is assigned with peoplePerDay[1] * 3, which is 15 * 3, so 45.

If itemPrices has element values 45, 48, then after itemPrices.push_back(38), what are itemPrices' element values? Type answer as: 50, 60, 70

Answer: 45, 48, 38 Explanation: push_back() adds a third element, then assigns 38 to that element.

Array scoresList has 10 elements with indices 0 to 9, accessed as scoresList[0] to scoresList[9]. If the array's last index was 499, how many elements does the array have?

Answer: 500 Explanation: Because numbering starts at 0, the last index is N - 1, where N is the number of elements.

What is the resulting vector contents, assuming each question starts with a vector of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { if (itemsList.at(i) < 0) { itemsList.at(i) = itemsList.at(i) * -1; } }

Answer: 55, 1, 0, 9 Explanation: Negative elements are negated, making them positive.

Given: vector<int> userVals(4), with element values 44, 55, 66, 77. Given: vector<int> newVals. Given: vector<int> otherVals(9). What size is newVals after: newVals = userVals; ... newVals = otherVals; If appropriate type: Error

Answer: 9 Explanation: The size of newVals before newVals = otherVals doesn't matter. The assignment resizes newVals to otherVals' size, which is 9.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; What is the index of the last element for the following vector: vector<int> prices(100);

Answer: 99 Explanation: The 100 elements will ahve idices 0...99.

Array scoresList has 10 elements with indices 0 to 9, accessed as scoresList[0] to scoresList[9]. If that array instead has 100 elements, what is the last element's index?

Answer: 99 Explanation: The last index is at N - 1, where N is the number of elements, because the first element has index 0.

Given that this loop iterates over all items of the vector, how many items are in the vector? for (i = 0; i < 99; ++i) { cout << someVector.at(i) << endl; }

Answer: 99 Explanation: The loop iterates from 0 to 98, so the vector has elements at indices 0 to 98. That's 99 items (the 0'th item counts as an item).

How should a function's vector parameter ages be defined for the following situations? ages may be very large, and the function will not modify the vector.

Answer: Constant and pass by reference. Explanation: Constant prevents the function from modifying ages. Since ages is large, pass by reference is used to pass the original vector, instead of creating a copy.

How should a function's vector parameter ages be defined for the following situations? ages will always be small (fewer than 10 elements) and the function will not modify the vector.

Answer: Constant but not pass by reference. Explanation: Constant prevents the function from modifying ages. Since ages is small, pass by reference is not used; instead, a copy of ages is made.

If itemPrices has elements 45, 22, 38, what does price = itemPrices.pop_back() assign to price? Type error if appropriate.

Answer: Error Explanation: pop_back() does not return a value, so trying to assign that return value to a variable is an error. pop_back() just removes the last element.

What is the resulting vector contents, assuming each question starts with a vector of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList.at(i) = itemsList.at(i+1); }

Answer: Error (program aborts) Explanation: When i is 3, the loop tries to assign element 3+1, or 4, to element 3. But element 4 does not exist, yielding an error.

True or False: Given: int arrayList[5]; vector<int> vectorList(5); vectorList.at(6) = 777 will execute without an error message.

Answer: False Explanation: .at() provides range checking, an advantage of vectors. The program will throw an exception.

Given the following code snippet, const int NUM_ELEMENTS = 5; vector<int> myVctr(NUM_ELEMENTS); int i = 0; To find the maximum element value, a reasonable statement preceding the for loop

Answer: False Explanation: 0 would yield a wrong final maxVal if all element values were negative. A better statement would be: maxVal = myVctr.at(0).

True or False: Given: int arrayList[5]; vector<int> vectorList(5); arrayList[6] = 777 will yield a compiler error.

Answer: False Explanation: Although 6 is not a valid index, the compiler does not check for out of range indices, for neither arrays nor vectors.

True or False: Given: int arrayList[5]; vector<int> vectorList(5); vectorList.at(6) = 777 will yield a compiler error.

Answer: False Explanation: Although 6 is not a valid index, the compiler does not check for out of range indices, for neither arrays nor vectors.

True or False: Given: int arrayList[5]; vector<int> vectorList(5); while ( i < arrayList.size() ) loops while i is less than the array's size.

Answer: False Explanation: Arrays do not have a .size() feature, but vectors do, as well as other features too.

True or False: Consider the TV watching program involving multiple vectors: #include <iostream> #include <vector> #include <string> using namespace std; int main() { // Source: www.statista.com, 2010 const int NUM_CTRY = 5; // Num countries supported vector<string> ctryNames(NUM_CTRY); // Country names vector<int> ctryMins(NUM_CTRY); // Mins TV watched daily string userCountry; // User defined country bool foundCountry = false; // Match to country supported int i = 0; // Loop index // Define array contents ctryNames.at(0) = "China"; ctryMins.at(0) = 158; ctryNames.at(1) = "India"; ctryMins.at(1) = 119; ctryNames.at(2) = "Russia"; ctryMins.at(2) = 226; ctryNames.at(3) = "UK"; ctryMins.at(3) = 242; ctryNames.at(4) = "USA"; ctryMins.at(4) = 283; // Prompt user for country name cout << "Enter country name: "; cin >> userCountry; // Find country's index and avgerage TV time foundCountry = false; for (i = 0; i < NUM_CTRY; ++i) { if (ctryNames.at(i) == userCountry) { foundCountry = true; cout << "People in " << userCountry << " watch "; cout << ctryMins.at(i) << " mins of TV daily." << endl; break; } } if (!foundCountry) { cout << "Country not found; try again." << endl; } return 0; } Multiple vectors saved memory over using one larger vector.

Answer: False Explanation: Memory usage was not the reason for using multiple vectors, and is not saved by using multiple vectors.

Assume vectors have been defined as follows and have been initialized as indicated in the comments: vector<int> vctrX(2); // {3,4} vector<int> vctrY(5); // {3,4,0,7,8} vector<int> vctrZ(5); // {3,4,0,6,8} (vctrZ == vctrY) will evaluate to:

Answer: False Explanation: Not all elements are equal, i.e., elements at 3 differ (7 vs. 6)

Given the following code snippet, const int NUM_ELEMENTS = 5; vector<int> myVctr(NUM_ELEMENTS); int i = 0;

Answer: False Explanation: The normal structure uses <, not <=. The <= causes the loop to iterate outside of the vector's valid index range.

True or False: Given the vector definition: vector<int> agesVctr; Immediately after the definition, agesVctr has only 1 element.

Answer: False Explanation: The vector has no elements. agesVctr.at(0) would yield an error.

True or False: Consider the TV watching program involving multiple vectors: #include <iostream> #include <vector> #include <string> using namespace std; int main() { // Source: www.statista.com, 2010 const int NUM_CTRY = 5; // Num countries supported vector<string> ctryNames(NUM_CTRY); // Country names vector<int> ctryMins(NUM_CTRY); // Mins TV watched daily string userCountry; // User defined country bool foundCountry = false; // Match to country supported int i = 0; // Loop index // Define array contents ctryNames.at(0) = "China"; ctryMins.at(0) = 158; ctryNames.at(1) = "India"; ctryMins.at(1) = 119; ctryNames.at(2) = "Russia"; ctryMins.at(2) = 226; ctryNames.at(3) = "UK"; ctryMins.at(3) = 242; ctryNames.at(4) = "USA"; ctryMins.at(4) = 283; // Prompt user for country name cout << "Enter country name: "; cin >> userCountry; // Find country's index and avgerage TV time foundCountry = false; for (i = 0; i < NUM_CTRY; ++i) { if (ctryNames.at(i) == userCountry) { foundCountry = true; cout << "People in " << userCountry << " watch "; cout << ctryMins.at(i) << " mins of TV daily." << endl; break; } } if (!foundCountry) { cout << "Country not found; try again." << endl; } return 0; } Each vector should be the same data type.

Answer: False Explanation: The vectors commonly involve different data types.

True or False: Given the vector definition: vector<int> agesVctr; Given agesVctr has 3 elements, agesVctr.resize(4) adds 4 more elements, totalling 7 elements.

Answer: False Explanation: agesVctr.resize(4) adds just 1 more element, to bring the total to 4.

True or False: Given the vector definition: vector<int> agesVctr; agesVctr.size(4) allocates 4 elements for agesVctr.

Answer: False Explanation: agesVctr.resize(4) allocates elements. agesVctr.size() returns the current size of vector agesVctr.

True or False: Given the vector definition: vector<int> agesVctr; After agesVctr.resize(5) and agesVctr.at(0) = 99, agesVctr.size() evaluates to 1.

Answer: False Explanation: agesVctr.size() evaluates to the number of allocated elements, regardless of whether those elements have been assigned with values yet. agesVctr.size() would return 5.

Array peoplePerDay has 365 elements, one for each day of the year. Valid accesses are peoplePerDay[0], [1], ..., [364]. What assigns element 1 with the value 99?

Answer: peoplePerDay[1] = 99 Explanation: Assigns element 1 with 99.

Assume vectors have been defined as follows and have been initialized as indicated in the comments: vector<int> vctrX(2); // {3,4} vector<int> vctrY(5); // {3,4,0,7,8} vector<int> vctrZ(5); // {3,4,0,6,8} (vctrX == vctrY) will evaluate to:

Answer: False Explanation: vctrX and vctrY are not the same size.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; Is curr = yearsList.at(4) a valid assignment?

Answer: No, yearsList.at(4) does not exist. Explanation: The valid indices start at 0, so the four elements are 0, 1, 2, and 3. Accessing yearsList.at(4) will cause an error.

How should a function's vector parameter ages be defined for the following situations? ages may be very large, and the function will modify the vector.

Answer: Pass by reference but not constant. Explanation: Pass by reference makes ages modifiable, but constant prevents ages from being modified.

How should a function's vector parameter ages be defined for the following situations? ages will always be small, and the function will modify the vector.

Answer: Pass by reference but not constant. Explanation: Pass by reference makes ages modifiable, but constant prevents ages from being modified.

What is the purpose of this check in the code: if ((nthPerson >= 1) && (nthPerson <= 5)) { ... }

Answer: To ensure only valid vector elements ar eaccessed because vector oldestPeople only has 5 elements. Explanation: The user enters 1...5, which is converted to 0...4 when accessing the vector's 5 elements.

True or False: Given: int arrayList[5]; vector<int> vectorList(5); arrayList[6] = 777 will execute without an error message.

Answer: True Explanation: Arrays involve no out-of-range checking. The statement may write to another variable's memory location, causing later problems.

True or False: Given: int arrayList[5]; vector<int> vectorList(5); vectorList[6] = 777 will execute without an error message.

Answer: True Explanation: Bracket access provides no range checking, even for vectors. The statement may write to another variable's memory location, causing later problems.

Assume vectors have been defined as follows and have been initialized as indicated in the comments: vector<int> vctrX(2); // {3,4} vector<int> vctrY(5); // {3,4,0,7,8} vector<int> vctrZ(5); // {3,4,0,6,8} Given: vctrX = vctrY; (vctrX == vctrY) will evaluate to:

Answer: True Explanation: The copy operator will resize vctrX as necessary and copy all elements from vctrY into vctrX, so the vectors are equal.

True or False: Consider the TV watching program involving multiple vectors: #include <iostream> #include <vector> #include <string> using namespace std; int main() { // Source: www.statista.com, 2010 const int NUM_CTRY = 5; // Num countries supported vector<string> ctryNames(NUM_CTRY); // Country names vector<int> ctryMins(NUM_CTRY); // Mins TV watched daily string userCountry; // User defined country bool foundCountry = false; // Match to country supported int i = 0; // Loop index // Define array contents ctryNames.at(0) = "China"; ctryMins.at(0) = 158; ctryNames.at(1) = "India"; ctryMins.at(1) = 119; ctryNames.at(2) = "Russia"; ctryMins.at(2) = 226; ctryNames.at(3) = "UK"; ctryMins.at(3) = 242; ctryNames.at(4) = "USA"; ctryMins.at(4) = 283; // Prompt user for country name cout << "Enter country name: "; cin >> userCountry; // Find country's index and avgerage TV time foundCountry = false; for (i = 0; i < NUM_CTRY; ++i) { if (ctryNames.at(i) == userCountry) { foundCountry = true; cout << "People in " << userCountry << " watch "; cout << ctryMins.at(i) << " mins of TV daily." << endl; break; } } if (!foundCountry) { cout << "Country not found; try again." << endl; } return 0; } Each vector should have the same number of elements.

Answer: True Explanation: The ctryMins vector store information corresponding to the ctryNames vector. Both vectors should have the same number of elements.

True or False: Given the vector definition: vector<int> agesVctr; Given agesVctr has 3 elements with values 22, 18, and 19, agesVctr.resize(2) changes agesVctr to have 2 elements with values 22 and 18.

Answer: True Explanation: When the new size is smaller than the existing size, resize removes elements from the end.

Given the following code snippet, const int NUM_ELEMENTS = 5; vector<int> myVctr(NUM_ELEMENTS); int i = 0;

Answer: True Explanation: sumVal starts at 0, then as the for loop iterates through each element, that element's value gets added to sum.

Assume vectors have been defined as follows and have been initialized as indicated in the comments: vector<int> vctrX(2); // {3,4} vector<int> vctrY(5); // {3,4,0,7,8} vector<int> vctrZ(5); // {3,4,0,6,8} (vctrZ.size() == vctrY.size()) will evaluate to:

Answer: True Explanation: vctrZ and vctrY are both size 5.

Define a function's vector parameter ages for the following situations. Assume ages is a vector of integers. Example: ages will always be small (fewer than 10 elements) and the function will not modify the vector: const vector<int> ages. ages may be very large, and the function will not modify the vector void MyFct ( )

Answer: const vector<int>& ages Explanation: Pass by reference (achieved using &) and constant (achieved using const).

If itemPrices has elements 45, 22, 38, then after itemPrices.pop_back(), what does itemPrices.at(2) return? Type error if appropriate.

Answer: error Explanation: pop_back() removes element 2, so subsequently trying to access itemPrices.at(2) is an error.

Complete the code to print all items for the given vector, using the above common loop structure. vector<int> daysList(365); for (i = 0; ; ++i) { cout << daysList.at(i) << endl; }

Answer: i < 365 Explanation: Valid elements are 0..364. When i reaches 365, the loop body does not execute.

Count the number of negative-valued elements in vector valsVctr. numNeg = 0; for (i = 0; i < NUM_VALS; ++i) { if (valsVctr.at(i) < 0) { numNeg = ; } }

Answer: numNeg + 1 Explanation: numNeg is initialized to 0, and then is incremented each time a negtive element is visited.

Find the error in the vector reversal code. for (i = 0; i < numPrices; ++i) { tmp = prices.at(i); prices.at(i) = prices.at(numPrices - 1 - i); pieces.at(numPrices - 1 - i) = tmp; }

Answer: numPrices; Explanation: Should be numPrices / 2; else array gets reversed twice.

Find the error in the vector reversal code. for (i = 0; i < numPrices; ++i) { tmp = prices.at(i); prices.at(numPrices - i - 1) = tmp; pieces.at(i) prices.at(numPrices - 1 - i); }

Answer: pieces.at(i) prices.at(numPrices - 1 - i); Explanation: Swap fails; statements are in wrong order, value is overwritten before being copied.

Find the error in the vector reversal code. for (i = 0; i < numPrices; ++i) { tmp = prices.at(i); prices.at(i) = prices.at(numPrices - 1 - i); pieces.at(numPrices - 1 - i) = tmp; }

Answer: prices.at(numPrices - i); Explanation: Second item needs -1 because last element is numPrices-1, not numPrices.

Array scoresList has 10 elements with indices 0 to 9, accessed as scoresList[0] to scoresList[9]. Assign the first element in scoresList with 77.

Answer: scoresList[0] = 77; Explanation: scoresList[0] refers to element number 0, which is the first element.

Array scoresList has 10 elements with indices 0 to 9, accessed as scoresList[0] to scoresList[9]. Assign the second element in scoresList with 77.

Answer: scoresList[1] = 77; Explanation: When indices start at 0, the second element is at index 1.

Array scoresList has 10 elements with indices 0 to 9, accessed as scoresList[0] to scoresList[9]. Assign the last element with 77.

Answer: scoresList[9] = 77; Explanation: When indices start at 0, an N-element array's last element has index N - 1. With 10 elements, the last index is 9.

Find the minimum element value in vector valsVctr. tempVal = valsVctr.at(0); for (i = 0; i < NUM_VALS; ++i) { if (valsVctr.at(i) < ) { temVal = valsVctr.at(i); } }

Answer: tempVal Explanation: tempVal stores the minimum seen thus far. If valsVctr.at(i) is less than tempVal's current value, the variable is updated with the new minimum. After visiting all vector elements, tempVal's value will be the minimum of all the elements. Note that tempVal is NOT initialized to 0, but rather to the first element's value.

Assign the value 555 to the element at index 2 of vector testVctr.

Answer: testVctr.at(2) = 555; Explanation: testVctr.at(2) will be treated as if it was an int and not a vector.

Define an int vector testVctr with 50 elements each initialized to 10.

Answer: vector <int> testVctr(50, 10); Explanation: vector <int> creates a vector of ints. The 50 indicates the number of elements in the vector, while the 10 is automatically copied to each element.

Define a vector named testVctr that stores 10 items of type int.

Answer: vector<int> testVctr(10); Explanation: The value inside the <> indicates the type of elements stored in vector. The value inside the () defines the number of these elements.

Define a function's vector parameter ages for the following situations. Assume ages is a vector of integers. Example: ages will always be small (fewer than 10 elements) and the function will not modify the vector: const vector<int> ages. ages may be very large, and the function will modify the vector void MyFct ( )

Answer: vector<int>& ages Explanation: Pass by reference but not constant. Because the function modifies the vector, the size is irrelevant.

Define a function's vector parameter ages for the following situations. Assume ages is a vector of integers. Example: ages will always be small (fewer than 10 elements) and the function will not modify the vector: const vector<int> ages. ages will always be small, and the function will modify the vector void MyFct ( )

Answer: vector<int>& ages Explanation: Pass by reference (achieved using &) but not constant.

Assign the value stored at index 8 of vector testVctr to a variable x.

Answer: x = testVctr.at(8); Explanation: Any element in a vector can be accessed by the .at() function as long as the element is in the vector's scope.

Given x = 22 and y = 99. What are x and y after the given code? tempVal = x; x = y; y = tempVal;

Answer: x is 99 and y is 22. Explanation: The swap succeeds, because x's value is saved before being assigned 99, and then that saved value is assigned to y.

Given x = 22 and y = 99. What are x and y after the given code? tempVal = x; x = y; y = x;

Answer: x is 99 and y is 99. Explanation: The last statement reads x's new value of 99 and assigns it to y. Instead, that statement should read tempVal.

Given x = 22 and y = 99. What are x and y after the given code? x = y; y = x;

Answer: x is 99 and y is 99. Explanation: x = y assigns 99 to x. y = x then assign x's value, now 99, to y.

Given x = 22 and y = 99. What are x and y after the given code? x = y; y = x; x = y;

Answer: x is 99 and y is 99. Explanation: x = y assigns 99 to x. y = x then assign x's value, now 99, to y. The last x = y assigns 99 to x.

Given: vector<int> yearsList(4); yearsList.at(0) = 1999; yearsList.at(1) = 2012; yearsList.at(2) = 2025; What is the proper way to access the first element in vector yearsList?

Answer: yearsList.at(0) Explanation: Vector elements are indexed starting with 0. That idea can be hard for new programmers to remember.


Ensembles d'études connexes

FAR - R&D Costs + Software Costs

View Set

Oracle Database 12c: SQL Fundamentals (1Z0-061)

View Set

Chapter 1 Checkpoints & Review Questions

View Set

Citi Certifications for Psychology

View Set