Chapter 6: Vectors Flashcards
15 Questions
100 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What assigns element 0 with the value 250?

peoplePerDay = 250

What assigns element 1 with the value 99?

peoplePerDay = 99

What is the value of peoplePerDay after these statements: peoplePerDay = 5; peoplePerDay = peoplePerDay - 3;

2

What is the value of peoplePerDay given: peoplePerDay[N] = 15; N = N + 1; peoplePerDay[N] = peoplePerDay[N - 1] * 3?

<p>45</p> Signup and view all the answers

Assign the first element in scoresList with 77.

<p>scoresList[0] = 77</p> Signup and view all the answers

Assign the second element in scoresList with 77.

<p>scoresList[1] = 77</p> Signup and view all the answers

Assign the last element in scoresList with 77.

<p>scoresList[9] = 77</p> Signup and view all the answers

If the array has 100 elements, what is the last element's index?

<p>99</p> Signup and view all the answers

If the array's last index was 499, how many elements does the array have?

<p>500</p> Signup and view all the answers

How many elements does the vector yearsList(4) create?

<p>4</p> Signup and view all the answers

What value is assigned into yearsList.at(1)?

<p>2012</p> Signup and view all the answers

What value does curr = yearsList.at(2) assign to curr?

<p>2025</p> Signup and view all the answers

Is curr = yearsList.at(4) a valid assignment?

<p>False</p> Signup and view all the answers

What is the proper way to access the first element in vector yearsList?

<p>yearsList.at(0)</p> Signup and view all the answers

What are the contents of the vector after yearsList.at(0) = yearsList.at(2)?

<p>2025, 2012, 2025, 0</p> Signup and view all the answers

Study Notes

Array Basics

  • An array peoplePerDay has 365 elements corresponding to each day of the year.
  • To assign a value to an array element, use the format array[index] = value;.

Assigning Values

  • peoplePerDay[0] = 250 assigns the first element the value 250.
  • peoplePerDay[1] = 99 assigns the second element the value 99.

Arithmetic Operations

  • If an element's value is modified through arithmetic, e.g., peoplePerDay = 5; peoplePerDay -= 3;, it results in peoplePerDay holding a value of 2.

Indexed Assignments

  • For peoplePerDay[N] = 15;, if N starts at 1, the first assignment initializes peoplePerDay[1] to 15.
  • The subsequent assignment peoplePerDay[N] = peoplePerDay[N - 1] * 3; results in peoplePerDay[2] = 45.

Accessing Array Elements

  • The first element of an array scoresList initialized with 10 elements is accessed via scoresList[0].
  • The last element of a 10-element array is scoresList[9].

Array Indices

  • For an array of size N, the last index is N - 1.
  • An array with a last index of 499 has 500 elements.

Vector Basics

  • A vector yearsList(4) initializes four elements, which can be accessed using the .at(index) method.
  • Each yearsList.at(index) corresponds to the element at that position within the vector.

Vector Assignments

  • yearsList.at(1) = 2012 assigns the second element the value 2012.
  • Using curr = yearsList.at(2) assigns curr the value 2025.

Validity of Access

  • Attempting to access yearsList.at(4) results in an error since valid indices for four elements are 0, 1, 2, and 3.

Accessing First Element

  • The first element can be accessed with yearsList.at(0).

Content Changes

  • Assigning yearsList.at(0) = yearsList.at(2) changes the first element to 2025, resulting in the vector contents being 2025, 2012, 2025, 0.

Summary of Valid Indices

  • Only indices 0 to 3 are valid for a vector of size 4.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your understanding of vectors with these flashcards covering participation activities from Chapter 6. Each card presents an array-related question, helping reinforce your grasp of the material. Perfect for review and preparation before exams.

More Like This

Mastering Vectors
5 questions
Vectors Overview and Components
29 questions
Use Quizgecko on...
Browser
Browser