Kodewick
Start learning →
Basic←→0 / 60

Names by letter

#026BasicvectorStrings4 min

The class does chores in groups by first letter. Write starts_with(names, letter) to put the names that begin with letter into a new vector, in the same order, and return it. No name is empty, and each starts with a capital.

Examples
starts_with({"Amy", "Bob", "Ann"}, 'A')→['Amy', 'Ann']
starts_with({"Bob"}, 'Z')→[]
The functionvector<string> starts_with(const vector<string> &names, char letter)
main.cpp
#include <string>
#include <vector>
using namespace std;

vector<string> starts_with(const vector<string> &names, char letter) {
    vector<string> found;
    for (const string &name : names) {
        // your code here: if name starts with letter, put it in found
    }
    return found;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.