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.
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.
|