Write a program that reads in a line of text, counts

Assignment Help Computer Engineering
Reference no: EM13323698

Count words and letters

Write a program that reads in a line of text, counts and outputs the number of words in the line and the number of occurrences of each letter.

Define a word to be a string of letters delimited by white space (blank, newline, tab), a comma, or a period. Assume that the input consists only of characters and these delimiters. For purposes of counting letters, case is immaterial.

Output letters in alphabetic order and only output those letters that occur.

Some Help with your Algorithm development:

The word count is carried out with a state machine. We enter with our state variable, inWord set to false, and our word count set to0.

while(input characters is successful)

if we have encountered a blank, newline or a tab,

we set state to false

else if inWord is false,

set state to true

increment word count

lowCase = tolower(inChar);

charCount[int(lowCase) - int('a')]++;

cout << wordCount << " " words" << endl;

for(i = 0; i < 25; i++)

if(charCount[i] != 0)

cout << charCount[i] << " " << char(i + 'a')<< endl;

Comments on the letter count code:

We run tolower() on all characters entered. The data structure for the letter count is a 26-letter int array with indices in the range 0-25, calculated by

index = int(character) - int('a')

as each letter is read in, increment the appropriate array element.

Output of the letter count is a loop running from 0-25, with an if statement that allows output if the array entry isn't zero.

 

Reference no: EM13323698

Questions Cloud

Write an user defined function : Write an user defined function, that takes as input the x and y co-ordinate of three points, i.e. (x1,y1), (x2,y2) and (x3,y3). The output arguments represents the length of three side of a triangle i.e. l1,l2,l3. (25)
Write a matlab program that takes 2 number : Write a Matlab program that takes 2 number and choice of the user as input.
How much would the roe changed : Had it reduced its assets in this amount, and had the debt ratio, sales, and cost remained constant, by how much would the ROE changed?
Write an user defined function to print all the prime number : Write an user defined function to print all the prime numbers within a range.
Write a program that reads in a line of text, counts : Output of the letter count is a loop running from 0-25, with an if statement that allows output if the array entry isn't zero.
In what sense is it an inflation tax : What is seignior age? In what sense is it an inflation tax? What are shoe-leather costs? What are menu costs?
How does hyperinflation occur : What is hyperinflation How does hyperinflation occur?
Find length of shortest ladder that can stand outside wall : a tower is surrounded by a wall that is 10 m high and 30 m away from the base of the tower. compute the length of the shortest ladder that can stand outside the wall and lean against the tower.
Determine which company the customer could buy each item : Design a polynomial time algorithm to determine which company the customer could buy each item from to minimize her total cost.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Why is it difficult to conduct a qualitative risk assessment

Why is it difficult to conduct a qualitative risk assessment for an IT infrastructure?

  Assume a direct access file consists of sectors

assume a direct access file consists of sectors with 1024 byte capacity. Suppose also that records are 32 bytes long. On which logical sector do the following logical records lie? What is the relative record number in the sector?

  In how many ways can the student choose classes

A student must select 5 classes for the next semester from 12, but one of the classes must be either american history or english literature. in how many ways can the student choose classes??

  What levels of osi model tcp/ip functions

in brief answer to explain at what levels of the OSI model TCP/IP functions.

  Define in detail minimum five practices

Your Web design firm has just hired a talented graphic artist with years of expertise in print media and no experience with producing image production. You have to train this person in the best practices for Web graphics. Explain in detail minimum..

  Benefit and drawback of each major operating system

Benefit and drawback of each major operating system

  Shiny buttons game

Write a public void cleanTable() method in the ShinyGame class that causes all selected sequences of game pieces to be removed from the game board and add a private score integer attribute to the ShinyButtons model class. Create a getScore() method..

  Find speed of execution of application programs

As computer word size gets larger and larger, there is a law of diminishing returns; the speed of execution of application programs does not increase and may, in fact, decrease. define why this can occur.

  How to maintain network configuration including ip address

In a Windows 2003 server network discuss several devices as in : repeaters, routers, hubs, and gateways. What are the functions for those devices? At which layer(s) of the OSI model do those devices operate?

  Make a powerpoint presentation to share with the owner

A twenty year old company, SewWorld, comprised of six locations in three states, sells sewing machines, sewing related software, and accessories.

  Benefit of ethical hacking

Describe what you consider is the main benefit of the ethical hacking be sure to involve what is the role of an ethical hacker.

  Drawbacks of supporting links to files that cross mount

explain the advantages and disadvantages of supporting links to files that cross mount points (that is, the file link refers to a file that is stored in a different volume).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd