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
pychu [463]
3 years ago
11

Write a program that will read in a line of text and output the number of words in the line and the number of occurrences of eac

h letter. Define a word to b any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, and periods. When outputting the number of letters that occur in a line, be sure to count upper and lowercase versions of a letters as the same letter. Output the letters I alphabetical order and list only those letters that do occur in the input line.

Computers and Technology
1 answer:
kherson [118]3 years ago
7 0

Answer:

Here is the C++ program:

#include<iostream>  //to use input output functions

#include <algorithm>  //to use tolower() function

using namespace std;  //to identify objects like cin cout

int main() {  //start of main function

 string text;  // to hold text input

 cout<<"Enter a line of text: ";  // prompts user to enter a string

 getline(cin,text);  // reads the input string (text) from user

transform(text.begin(), text.end(), text.begin(), ::tolower);  //converts the text into lower case

 int letter[26] = {0}; //to hold the letters

 int i;  // used as a loop variable

 int words=0;  // to hold the count of words

 for(i = 0; i< text.size();i++){  // iterates through the text

 if(isalpha(text[i])&&(text[i+1]=='.'||text[i+1]==','||text[i+1]==' '))  //checks if the character at i-th index of text is a letter, and checks if i+1 index position of text is a period, comma or a space

 words++;  // adds 1 to the count of words

 if(isalpha(text[i]))  // if the character at the i-th index of text is a letter

 letter[text[i]-'a']++;  }  // counts the occurrences of each letter

 char j = text[text.size()-1];  // sets j to the last character of text

 if(j != '.' && j!= ' '&& j!=',' &&j!= '\0')  //if the last character is not a period or empty space  or comma or end of lone

 words++;  //add 1 to the count of words

 cout<<"Number of words: "<<words<<endl;  //display the number of words in the text

 for(i=0; i<26; i++)  {  //iterates 25 times

   if(letter[i]>0)  //if letter at index i is greater than 0

   cout<<(char)('a'+i)<<" : "<<letter[i]<<endl;  }} //displays each letters and its number of occurrences in the text

 

Explanation:

The program is explained in the attached document with an example.

You might be interested in
Write Java program to allow the user to input the amount of deposit, yearly interest rate (percentage), and income tax(percentag
Vedmedyk [2.9K]

Answer:

import java.util.Scanner;

public class num12 {

   public static void main(String[] args) {

       Scanner scr = new Scanner(System.in);

       System.out.println("Enter a Deposit Amount");

       double amt = scr.nextDouble();

       System.out.println("Income tax in percentage");

       double incomeTaxRate = scr.nextDouble()/100;

       System.out.println("Yearly interest rate:");

       double rate = scr.nextDouble();

       double intRate = rate/100;

       double interest = (amt*intRate)-(amt*incomeTaxRate);

       System.out.println("The Interest on "+amt+" at "+rate+"% after one year is "+interest);

   }

}

Explanation:

Find the sample output attached

Java's Scanner class is used to prompt and receive values for deposit amount, income tax rate and interest rate

The yearly interest is calculate by interest = (amt*intRate)-(amt*incomeTaxRate);

3 0
3 years ago
When you're working with a word processing document and you press the del key, what happens?
LuckyWell [14K]
The correct answer is C.
6 0
3 years ago
What is Server Message Block (SMB) used for in Windows and can a hacker still damage a network using SMB?
Aleksandr [31]

Answer:

The absolute most decimating ransomware and Trojan malware variations rely upon vulnerabilities in the Windows Server Message Block (SMB) to proliferate through an association's system. Windows SMB is a convention utilized by PCs for record and printer sharing, just as for access to remote administrations.  

A fix was discharged by Microsoft for SMB vulnerabilities in March 2017, yet numerous associations and home clients have still not applied it. So now, the unpatched frameworks permit dangers that exploit these vulnerabilities inside, helping dynamic malware crusades spread like Californian rapidly spreading fire.  

SMB vulnerabilities have been so effective for danger entertainers that they've been utilized in the absolute most unmistakable ransomware episodes and refined Trojan assaults of the most recent two years. Truth be told, our item telemetry has recorded 5,315 discoveries of Emotet and 6,222 of TrickBot in business systems—two Trojan variations that are utilizing the SMB vulnerabilities—over the most recent 30 days alone.

7 0
3 years ago
Read 2 more answers
3. Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side i
iren2701 [21]

Answer:

Following are the program to this question:

#include <iostream>//defining header file

using namespace std;

void squareOfAsterisks(int x) //defining method squareOfAsterisks

{

   int i,j; //defining integer variable

   for(i=1;i<=x;i++) //defining loop to print column value

   {

   for(j=1;j<=x;j++) //defining loop to print row value

   {

   cout<<"*"; //print value

   }

   cout<<endl; //for line break

   }

}

int main() //defining main method

{

int x; //defining integer variable

cout<<"Enter any number: "; //print message

cin>>x; //input value from user

squareOfAsterisks(x); //calling the method and pass the value

return 0;

}

Output:

Enter any number: 4

****

****

****

****

Explanation:

The description of the above program can be given as follows:

  • In the given program a method "squareOfAsterisks" is declared, that accepts an integer value "x" in its arguments, inside the method two integer variable I, j is used, that uses a to print the given pattern.
  • In the main method, an integer variable x is declared, which takes input from the user end, and then calls the method, that is "squareOfAsterisks" and passes its value.
8 0
3 years ago
5-11) (Find the Smallest Value) Write an application that finds the smallest of several integers. Write a program which first as
Elanso [62]

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class num4 {

   public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

       System.out.println("How many numbers? ");

       int n = in.nextInt();

       int []intArray = new int[n];

       //Entering the values

       for(int i=0; i<intArray.length;i++){

           System.out.println("Enter the numbers");

           intArray[i]=in.nextInt();

       }

       System.out.println(Arrays.toString(intArray));

       int min =intArray[0];

       for(int i =0; i<intArray.length; i++){

           if(min>intArray[i]){

               min = intArray[i];

           }

       }

       System.out.println("The Minimum of the numbers is "+min);

   }

}

Explanation:

  • Using Java programming language
  • Prompt the user for the number of values
  • Using Scanner class receive and store in a variable
  • Create an array of size n
  • Using an for loop continuously ask the user to enter the integers
  • Print the array of integers
  • Using another for loop with an if statement, find the smallest element in the array of numbers
  • Output the the smallest number
8 0
3 years ago
Other questions:
  • Di bawah ini tampilan submenu pada tab menu insert pada microsoft word 2010,yaitu...
    6·1 answer
  • How do I make Dank memes
    13·2 answers
  • Which is the last step in conducting a URL search?
    5·2 answers
  • Write a program to test the various operations of the class clockType
    8·1 answer
  • Assume that a variable variable, number Of Sides has been initialized. Write a statement that assigns the value True to the vari
    8·1 answer
  • You are developing a system to process lists of days of the week, represented as strings. Create a function is_weekend that cons
    12·1 answer
  • Explain three specific &amp; major security threats to internet users. In each case, address whether or not the vulnerabilities
    15·1 answer
  • Consider a disk that rotates at 3600 rpm. The seek time to move the head between adjacent tracks is 2 ms. There are 32 sectors p
    5·1 answer
  • Define a function below, filter_out_strs, which takes a single argument of type list. Complete the function so that it returns a
    10·1 answer
  • The first version of Windows to have automatic updates from the Internet was _____.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!