Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9903000

Have any Question?


Related Questions in Computer Engineering

Suppose you were working on a very large system that

Suppose you were working on a very large system that consisted of many .cpp files and the associated header files. Lots of libraries too, developed for the project. a. What ADT structure could you use to represent all th ...

Why the ytms of bond and zero coupon yields are different

Why the YTMs of bond and Zero coupon yields are different for the same term.

Cullumber corp issued a four-year bond one year ago with a

Cullumber Corp. issued a four-year bond one year ago with a coupon rate of 6.0 percent. The bond pays interest semiannually. If the yield to maturity on this bond is 9 percent, what is the price of the bond? (Round answe ...

Solve the problem by implementing the whole class with main

Solve the problem by implementing the whole class with main() function and demonstrate that your Java code can pass several appropriate test cases successfully in your main() function? Write a short recursive Java method ...

Part 1whats the importance of a documentation plan please

Part 1: What's the importance of a Documentation Plan? Please provide an example of a Documentation Plan that you would use. Part 2: How do you calculate how long a project will take? These questions are for my Introduct ...

Can someone help solve this problem in lisp-programming

Can someone help solve this problem in Lisp-Programming language? More specifically in DrRacket. Exercise: A professor keeps the quiz grades of a student in a non-empty vector of non-negative numbers. Write a function th ...

Simplifya factor and find the vertex form x2 6x 8b factor

Simplify a) Factor and find the vertex form x^2 +6x + 8 b) Factor the h value of of the vertex of 2x^2 - 10x - 30 c) Find the x-intercept and y-intercept of 5x - 4y=30

One state lottery has 1100 prizes of 1 145 prizes of 10 20

One state lottery has 1,100 prizes of $1; 145 prizes of $10; 20 prizes of $75; 5 prizes of $285; 2 prizes of $1,080; and 1 prize of $2,300. Assume that 24,000 lottery tickets are issued and sold for $1. 1)  What is the l ...

What is a good analogy of subnetting whats a break down of

What is a good analogy of Subnetting? What's a break down of how it is used within a company?

Scenario your algorithm will keep track of a customers

Scenario Your algorithm will keep track of a customer's purchases at the local fireworks stand. Customers will not know exactly how many items they will purchase, so using a For loop on this lab is not allowed. Let's kee ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As