1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
anygoal [31]
3 years ago
5

Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog

ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and k. 2 Your function should take a single string argument and return a dynamically allocated array of 26 integers representing the count of each of the letters a . . z respectively. Your function should be case insensitive, i.e., count 'A' and 'a' as the occurrence of the letter a. [Hint: use the letter to integer conversion functions.] Do not count non-letter characters (i.e., spaces, punctuation, digits, etc.) Write a program that will solicit a string from the user using getline, call your letter frequency function and print out the frequency of each letter in the string. Do not list letters that do not occur at least once. Example: Enter a string: my dog at my homework Letter frequency a 1 d 1 e 1 g 1 h 1 k 1 m 3 o 3 r 1 t 1 w 1 y 2

Computers and Technology
1 answer:
Nostrana [21]3 years ago
6 0

Answer:

Check the explanation

Explanation:

Code to copy:

// ConsoleApplication7.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

#include <cstring>

#include <string>

using namespace std;

int * letterFrequency(char s[]);

int main()

{

  int *freq_letters;

  char *s = new char[100];

  freq_letters = new int[26];

  //To read the input string in order to find the frequency of each letter

  cout << "Enter a string: ";

  cin.getline(s, ' ');

  //call the function to find the occurrence of each alphabet

  freq_letters = letterFrequency(s);

  //Display the count

  cout << "Letter Frequency " << endl;

  for (int i = 0; i < 26; i++)

  {

      //Constriant to check if the letter appeared at least once in the string and so printing the frequency of its occurence

      if (freq_letters[i] != 0)

      cout << " " << static_cast<char>(i + 'a') << " " << freq_letters[i] << endl;

  }

  system("pause");

  return 0;

}

//Define the function to find occurrence of each letter in the input string

int * letterFrequency(char s[])

{

  int *occurrence_array;

//to store the output of occurrences for each alphabet

  occurrence_array = new int[26];

// to store the count of occurrence for each letter temporarily

  int letter_count;

  // for loop to check the occurrence for all 26 alphabets

 

  for (int i = 0; i < 26; i++)

  {

      letter_count = 0;

      for (int j = 0; j < strlen(s); j++)

      {

          /*comparing the ascii values of each alphabet with every character from the string by converting it to lower case i.e. case insensitive*/

          if (int('a') + i == int(tolower(s[j])))

              letter_count++;

      }

      occurrence_array[i] = letter_count;//To store the count calculated for each alphabet

  }

  return occurrence_array;

}

The following below code screenshot and output shows that when the string is entered, the output will shows each lettercount irrespective of whether the letter is in capitals or small and does not count non-letter characters (i.e spaces, punctuations etc.)

You might be interested in
How does Virtual Reality help to make work experiences more inclusive?
FrozenT [24]

Answer:

It makes your brain work better and it's also fun.

Explanation:

The brain does not like just one thing it wants to have more experience.

7 0
2 years ago
Select the best answer from the drop-down menu.
maw [93]

Answer:

1) performance assessments

2) measurable goals

3)can't be measured quantitatively

4) milestones

Explanation:

Methods of evaluating the performance and productivity of an individual or group in relation to predetermined criteria and measurable goals are <u>performance assessments.</u>

<u>measurable goals</u> are goals that have concrete criteria for measuring progress toward their attainment.

Why are statements like “great customer experience” or “more sales” not good assessment criteria? <u>can't be measured quantitatively</u>

Personal goal setting helps lagging performance by setting <u>milestones</u>

which are short-term achievable tasks.

<u>OAmalOHopeO</u>

8 0
2 years ago
Read 2 more answers
Click to visit W3Schools.com
KonstantinChe [14]

Is this self advertising because its not a question so i have no answer for you and if i missed something on the website that was a question let me know

3 0
3 years ago
Read 2 more answers
PA theme is a major message that a writer convoys through a text. you have explored many themes in the hobbit one theme in the n
Nataly [62]

Answer:

The Hobbit’s main theme is Bilbo’s development into a hero, which more broadly represents the development of a common person into a hero. At the beginning of the story, Bilbo is timid, comfortable, and complacent in his secure little hole at Bag End. When Gandalf talks him into embarking on the quest with Thorin’s dwarves, Bilbo becomes so frightened that he faints. But as the novel progresses, Bilbo prevails in the face of danger and adversity, justifying Gandalf’s early claim that there is more to the little hobbit than meets the eye.??????

Explanation:

7 0
2 years ago
What is the scope of each variable?
kari74 [83]

Answer:

scope of pet name is limited to pet class and color is accessible to the whole program

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • How can development in ICT be utilized to speed up the development and integration efforts
    15·1 answer
  • Which attribute of the image tag specifies the URL of an image
    14·1 answer
  • To what would you compare the transport layer?
    14·1 answer
  • In the Mouse Properties window, you can?
    8·1 answer
  • Unless grunkle stan pines is mistaken, there is a family of deer’s in his garden
    6·1 answer
  • The field names in a database are also known as__?
    12·2 answers
  • HURRY please!!!!
    13·1 answer
  • What do you get with brainly points
    9·1 answer
  • How can you make a search phrase more effective?
    11·1 answer
  • When conducting memory and recall tests, some people make an effort to normalize memories by not reporting extreme cases. this l
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!