Skip to main content
Became Hot Network Question
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
 

bool isPangram(std::string str){
    

 {
    std::transform(str.begin(), str.end(), str.begin(), ::toupper); // Transforming a string to upper case
    std::vector<bool> hash_table(26, false); // a hash_table that maps the  index of a letter from the alphabet
                                             // and a boolean saying if the string contains this element                                             
    int index;
 
    for(auto c: str){
        
        if(isalpha(c))
            // Checks if the element in the string is in the alphabet
            index = c - 'A';
            hash_table[index] = true; 
            std::cout << index << std::endl;

    };

    if(std::any_of(hash_table.begin(), hash_table.end(), [](bool v) { return !v; })) {
        // if any of the items in the array evaluates to false
        // means that the string don't contain all the elements 
        // in the alphabet,hence, it's not a pangram

        return false;
    }
 
    return true;    
};
 

int main() {
 
    std::string str = "We promptly judged antique ivory buckles for the next prize"; 
 
     if (isPangram(str)){ 
         std::cout << "Yes" << std::endl; 
     }
     else {
         std::cout << "No" << std::endl; 
           
     };
     return 0;
    

}



 
```
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
 

bool isPangram(std::string str){
    

 
    std::transform(str.begin(), str.end(), str.begin(), ::toupper); // Transforming a string to upper case
    std::vector<bool> hash_table(26, false); // a hash_table that maps the  index of a letter from the alphabet
                                             // and a boolean saying if the string contains this element                                             
    int index;
 
    for(auto c: str){
        
        if(isalpha(c))
            // Checks if the element in the string is in the alphabet
            index = c - 'A';
            hash_table[index] = true; 
            std::cout << index << std::endl;

    };

    if(std::any_of(hash_table.begin(), hash_table.end(), [](bool v) { return !v; })) {
        // if any of the items in the array evaluates to false
        // means that the string don't contain all the elements 
        // in the alphabet,hence, it's not a pangram

        return false;
    }
 
    return true;    
};
 

int main() {
 
    std::string str = "We promptly judged antique ivory buckles for the next prize"; 
 
     if (isPangram(str)){ 
         std::cout << "Yes" << std::endl; 
     }
     else {
         std::cout << "No" << std::endl; 
           
     };
     return 0;
    

}



 
```
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

bool isPangram(std::string str) {
    std::transform(str.begin(), str.end(), str.begin(), ::toupper); // Transforming a string to upper case
    std::vector<bool> hash_table(26, false); // a hash_table that maps the  index of a letter from the alphabet
                                             // and a boolean saying if the string contains this element                                             
    int index;
    for(auto c: str){
        if(isalpha(c))
            // Checks if the element in the string is in the alphabet
            index = c - 'A';
            hash_table[index] = true; 
            std::cout << index << std::endl;

    };

    if(std::any_of(hash_table.begin(), hash_table.end(), [](bool v) { return !v; })) {
        // if any of the items in the array evaluates to false
        // means that the string don't contain all the elements 
        // in the alphabet,hence, it's not a pangram

        return false;
    }
    return true;    
};

int main() {
    std::string str = "We promptly judged antique ivory buckles for the next prize"; 
    if (isPangram(str)){ 
         std::cout << "Yes" << std::endl; 
     }
     else {
         std::cout << "No" << std::endl; 
     };
     return 0;
}
```
Tweeted twitter.com/StackCodeReview/status/1371929276006666249

A c++C++ program to check if a string is a pangram

Spelling and grammar
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308

Im a noob in c++I'm new to C++ and decided to implement a simple program that checks if a string is a pangram (ifi.e. the string contains all the English alphabet letters). It's my first program in c++C++ and iI have some background with interpreted programming languages like pythonPython and R.

I want to know what are the common beginners mistake immistakes I'm making in this implementation : if im, whether I'm following good practices, what iI should avoid and etc. Any tip/help/advice is more than welcome. Thank you all for your attention.

Im a noob in c++ and decided to implement a simple program that checks if a string is a pangram (if the string contains all the English alphabet letters). It's my first program in c++ and i have some background with interpreted programming languages like python and R.

I want to know what are the common beginners mistake im making in this implementation : if im following good practices, what i should avoid and etc. Any tip/help/advice is more than welcome. Thank you all for your attention.

I'm new to C++ and decided to implement a simple program that checks if a string is a pangram (i.e. the string contains all the English alphabet letters). It's my first program in C++ and I have some background with interpreted programming languages like Python and R.

I want to know what are the common beginners mistakes I'm making in this implementation, whether I'm following good practices, what I should avoid etc.

Source Link
Occhima
  • 273
  • 2
  • 8
Loading