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

  A system that calculates and returns the mean and a method

A system that calculates and returns the mean and a method

  While design a relational database

What guidelines/steps should you follow as you design a relational database? In addition to using the course material, use the Library to find best-practice guidelines. Be sure to cite your sources.

  Create a wbs and enter the tasks in project

Enter realistic durations for each task. Assume you have only four months to complete the project. Take a screen shot of the resulting Gantt chart and paste this into the Word for Windows file.

  Linux advanced server vs windows 2003 server

Please give me 10 topic examples that I can select to write about in my class assignment. The example must be able to cover the directions that are listed below.

  Write down a program that, given the amount of a purchase

note down a program that, given the amount of a purchase and the amount received in payment, computes the change in dollars, half-dollars, quarters, dimes, nickles, and pennies.

  What fields you believe would be primary keys

Be sure to include the field type and size. Please do not jump ahead and try to create tables. now I'm just looking for a list of fields. This is somewhat vague on purpose. I want you to decide what is required in the database.

  How can the average person fight this

Recent news articles are talking about how Internet is being used as a method of posting slanderous, private or simply unverified information.

  Write a simple java application

Write a simple Java application which calculates the power dissipation in a simple circuit. Your application should ask the user to enter the voltage and resistance values of the circuit.

  Program to insert the name cervantes

"In the following exercises, suppose that the Simple combo box appears as shown and that the Sorted property is set to True. Give a statement or statements that will carry out the stated task."

  Write down a javascript function to validate a text field

Write down a JavaScript function to validate a text field on a form for holding a positive integer value, without using any inbuilt functions like IsNaN and so forth. If the text field contains a valid number then the JavaScript function would ret..

  Economic life of technology product

Explain what do you understand by the economic life of a technology product. Discuss how does economic life of the technology product is compared with the technology life and product life?

  How could one improve such protocol

Considering the performance of a communincation protocol design, how may the number of messages have potentially the largerst impact as compared to the total amount of data.

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