Question

In: Computer Science

Write a C++ function to print out all unique letters of a given string. You are...

Write a C++ function to print out all unique letters of a given string. You are free to use any C++ standard library functions and STL data structures and algorithms and your math knowledge here. Extend your function to check whether a given word is an English pangram (Links to an external site.). You may consider your test cases only consist with English alphabetical characters and the character.

Solutions

Expert Solution

#include <iostream>

using namespace std;

void function(string str){
  
// Array to store 0 and 1 if a is present in string a[0]=1,if b is present a[1] = 1,
// if b is absent a[1] = 0 and so on.
int a[26] = {0};
  
cout<<"Unique letters : ";
  
//Iterating all the letters of string
for(int i=0;i<str.length();i++){
  
//Converting each letter to lower case if it is in upper case.
if(isupper(str[i]))
str[i] = tolower(str[i]);
  
// 'a'-'a'=0, 'b'-'a'=1 this way, w'll get index of letter in array a by str[i]-'a'
//checking if letter was already present in the string
if(a[str[i]-'a'] == 0){
  
//updating array a
a[str[i]-'a'] = 1;
  
//printing letter
cout<<str[i];
}
}
  
// To check if string is pangram
  
// Assuming that string is pangram
bool pangram = true;
  
//iterating array a
for(int i=0;i<26;i++){
  
//if any of the letter is absent, then string is not pangram
if(a[i] == 0){
pangram = false;
break;
}
}
  
// if pangram is true, it means string is pangram
if(pangram){
cout<<"\n String is pangram";
}
  
// if pangram is false, it means string is not pangram
else{
cout<<"\n String is not pangram";
}
}

int main()
{   
  
cout<<"Enter String : ";
string str;
  
//Input of String
cin>>str;
  
//Calling method to print unique letters and checking for pangram
function(str);
  
return 0;
}
OUTPUT:


Related Solutions

Write a c++ function named multi_table to print out multiplication table for a given number of...
Write a c++ function named multi_table to print out multiplication table for a given number of rows and columns. Your program should print a header row and a header column to represent each row and column number. For example your function call multi_table(4, 4) would print below to the command line: 1 | 1 2 3 4 _________ 2 | 2 4 6 8 3 | 3 6 9 12 4 | 4 8 12 16 Test your function in...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
Write a C++ function to print any given std::array of a given type to the standard...
Write a C++ function to print any given std::array of a given type to the standard output in the form of {element 0, element 1, element 2, ...}. For example given the double array, d_array = {2.1, 3.4, 5.6, 2.9}, you'd print {2.1, 3.4, 5.6, 2.9} to the output upon executing std::cout << d_array; line of code. Your function mus overload << operator.
Write a program that counts the letters in a given string and then display the letter...
Write a program that counts the letters in a given string and then display the letter count in order from high to low. The program should: Display a message stating its goal Prompt the user to enter a string input Count the letters in the string (hint: use dictionaries) Display the letter count in order from high to low (sort your letter count) For example, for the input Google the output should be G - 2 O - 2 E...
C# Palindrome Permutation: Given a string, write a function to check if it is a permutation...
C# Palindrome Permutation: Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words. Input: Tact Coa Output: True (permutations: "taco cat", "atco cta", etc.) Comment your code to explain it.
Give pseudocode for a recursive function that sorts all letters in a string. For example, the...
Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy". Java
Give pseudocode for a recursive function that sorts all letters in a string. For example, the...
Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy". Python
In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with...
In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with 4 vowels and 7 consonants". Create the following methods to complete this application: Methods int countLetters(string userInput) Create integer variable to store the number of letters Use foreach to cycle through each character in the string userInput Check to see if the character is a letter (IsLetter). If it is, count as a letter The method will return a numeric value which is the...
In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with...
In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with 4 vowels and 7 consonants". Create the following methods to complete this application: Methods int countLetters(string userInput) Create integer variable to store the number of letters Use foreach to cycle through each character in the string userInput Check to see if the character is a letter (IsLetter). If it is, count as a letter The method will return a numeric value which is the...
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT