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
Which role involves designing and creating advertisements for marketing purposes?
SOVA2 [1]

Answer: I cant give you an exact answer, but your options are gonna be B or C.

Explanation: A computer programmer actually doesn't work with a marketing company at all, most of them work from home as it is. And a Tech Support Specialist may work with a marketing firm, but it would be strictly IT stuffs.

3 0
2 years ago
Read 2 more answers
Write a program to input a number and check whether it is even or odd number
Mashutka [201]

Answer:#include <stdio.h>

int main() {

   int num;

   printf("Enter an integer: ");

   scanf("%d", &num);

   // true if num is perfectly divisible by 2

   if(num % 2 == 0)

       printf("%d is even.", num);

   else

       printf("%d is odd.", num);

   

   return 0;

}

3 0
2 years ago
The part of the computer that provides access to the Internet is the
andrew11 [14]

Answer:

MODEM

Explanation:

5 0
2 years ago
What does ;-; mean during a text?
zzz [600]

Answer:

Its like an emotionless crying face, mainly used for humor

Explanation:

5 0
3 years ago
Read 2 more answers
What coding language should i begin with if i'm looking to get into AI ?
loris [4]

Depends really. Have you got prior coding experience? The semantics of certain languages are much easier to pick up if you've had prior experience, but it might seem impossible to someone who has minimal experience.

Assuming that you're no older than 15 or 16, I'm going to suggest Python. It's a simple, high-level language that's easier to understand than most languages. If you think you've got enough experience to quickly understand and pick up things, then I'd probably say R is a good language to start with. It's very well-suited for AI and tends to be a favourite for AI researchers.

7 0
3 years ago
Other questions:
  • Dr. Patterson’s office calls to give patient Sara Martin her test results from her most recent visit. Her husband answers the ph
    8·2 answers
  • Write a function to add two large integers of any length, say up to 200 digits. A suggested approach is as follows: treat each n
    12·1 answer
  • Repl.it Assignment 4.1.2 (Guess the Number)<br> Please help me<br> I will give brainliest and a like
    10·1 answer
  • When you use information hiding by selecting which properties and methods of a class to make public, you are assured that your d
    14·1 answer
  • Which of the following is true about advertisements?
    15·1 answer
  • Write a method named printGPA that takes in as a parameter a Scanner to read in user input, and calculates a student's grade poi
    8·1 answer
  • 11. Explain different types of program control with suitable flow chart.<br> N
    15·1 answer
  • Glenda is searching airline schedules on HolApp, a mobile Web application. While browsing the application, a banner appears on t
    12·1 answer
  • Which era marked a switch from agricultural practices to industrial practices?
    6·1 answer
  • Select the skill that matches the following definition.​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!