Lessons 11–15 · About 60 min per lesson

Strings and vectors

Store and scan a batch of data, with attention to indexes and bounds.

Lesson breakdown

  1. Lesson 11

    Store a word in string and iterate through its characters.

  2. Lesson 12

    Compare token extraction with cin and line input with getline.

  3. Lesson 13

    Use vector and push_back to store an unknown number of values.

  4. Lesson 14

    Use indexes and range-for to compute a total and maximum.

  5. Lesson 15

    Check an empty vector, a single element and the last valid index.

Worked example

Store 12, 5 and 12 in a vector and find the maximum and its frequency.

How to solve it

Scan once to find maximum 12 and again to count its 2 occurrences.

Assignment

Read a batch of nonnegative scores and report the maximum and its frequency. Print Empty for an empty batch.

Check your result

[12,5,12] → 12 2; [0] → 0 1; an empty batch → Empty.