Avatar of rjmcgrew

rjmcgrew's solution

to Pangram in the C++ Track

Published at Oct 15 2019 · 0 comments
Test suite

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

Getting Started

Make sure you have read the Installing and Running the Tests pages for C++ on exercism.io. This covers the basic information on setting up the development environment expected by the exercises.

Passing the Tests

Get the first test compiling, linking and passing by following the three rules of test-driven development. Create just enough structure by declaring namespaces, functions, classes, etc., to satisfy any compiler errors and get the test to fail. Then write just enough code to get the test to pass. Once you've done that, uncomment the next test by moving the following line past the next test.


This may result in compile errors as new constructs may be invoked that you haven't yet declared or defined. Again, fix the compile errors minimally to get a failing test, then change the code minimally to pass the test, refactor your implementation for readability and expressiveness and then go on to the next test.

Try to use standard C++14 facilities in preference to writing your own low-level algorithms or facilities by hand. CppReference is a wiki reference to the C++ language and standard library. If you are new to C++, but have programmed in C, beware of C traps and pitfalls.


Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


#include "pangram.h"
#include "test/catch.hpp"


    REQUIRE(pangram::is_pangram("the quick brown fox jumps over the lazy dog"));

    REQUIRE(!pangram::is_pangram("a quick movement of the enemy will jeopardize five gunboats"));

    REQUIRE(!pangram::is_pangram("the quick brown fish jumps over the lazy dog"));


    REQUIRE(pangram::is_pangram("the 1 quick brown fox jumps over the 2 lazy dogs"));

    REQUIRE(!pangram::is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"));

    REQUIRE(pangram::is_pangram("\"Five quacking Zephyrs jolt my wax bed.\""));

    REQUIRE(!pangram::is_pangram("the quick brown fox jumps over with lazy FX"));


#if !defined(PANGRAM_H)
#define PANGRAM_H

#include <string>

namespace pangram {
bool is_pangram(const std::string& s);
}  // namespace pangram

#endif // PANGRAM_H


#include "pangram.h"
#include <cctype>
#include <unordered_set>

namespace pangram {

constexpr int alphabet_size { 26 };

bool is_pangram(const std::string& s)
    std::unordered_set<char> unique_characters;
    for (auto c : s) {
        if (std::isalpha(c))
    return unique_characters.size() == alphabet_size;
}  // namespace pangram

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?