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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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