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]
4 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]4 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
You work as a computer technician for a production company that travels all over the world while filming and editing music video
gogolik [260]

Answer: Input Voltage

Explanation:

Based on the information given, since the power supply to install in the system is being determined, the input voltage is the most important characteristic to consider when choosing a power supply.

The input voltage indicates the type of voltage and the electrical current that's required to power a device safely and effectively.

4 0
3 years ago
_____ is a scam in which access to one's own computer is locked or restricted in some way.
gtnhenbr [62]
Ransomware is the answer to this.
5 0
3 years ago
20
denis-greek [22]

Answer:

true

Explanation:

because my 8 ball said so

6 0
4 years ago
A data dictionary is sometimes described as "the database designer's database" because it records the design decisions about tab
MrRa [10]

Answer:

True is the correct answer for the above questions.

Explanation:

  • A data dictionary is used to hold the structure and definition of the database. It is because it is used to hold information about the database or operational database.
  • It is a set of schema through which the user can understand the structure of the database. It can be used to define the metadata also. The metadata detailed the data of a database.
  • The above question-statement also wants to states about the same which is described above which is the definition of the data dictionary. Hence it is a true statement.
4 0
3 years ago
3 Points
gulaghasi [49]

Answer: Well, In my Opinion it would Be D! because these day people stick together with the internet!. If she adopt her Online business then she would be able to earn profits and also she can serve the people! Slowly people will get to know her business! That will be good for her!

<h3>I hope this works! :)</h3>

3 0
3 years ago
Other questions:
  • To paste text with the same formatting as the document in which it is entered, select _____ from the Paste menu.
    12·1 answer
  • When a project manager can look at the progress towards the goals set, this is considered...?
    11·2 answers
  • How do you site this page??
    12·1 answer
  • Hat is the purpose of the domain name?
    7·2 answers
  • Which UML relationships should be used between a subclass and a superclass? For example, suppose there is an interface or abstra
    5·1 answer
  • Domestic refers to things that happen __________ of the united states
    15·2 answers
  • Justice wrote a program and forgot to put the steps in the correct order. Which step does she need to review?
    5·2 answers
  • A soft news story and a feature story are the same thing.<br> O True<br> O False<br> HELLPP ASSAAAP
    12·2 answers
  • What would your leadership style be?
    14·1 answer
  • 100 POINTS PLEASE HELP Type the correct answer in the box. Spell all words correctly.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!