Write the definition of the readandcount function.

Assignment Help C/C++ Programming
Reference no: EM13938072

Please enhance this program.

Write the definition of the readAndCount function. The function should read the input line, character by character, counting the number of words (a sequence of letters) and the number of occurrences of each letter.

The array to hold the number of occurrences of each letter is the parameter letterCount. Store the number of occurences of 'a' at index 0, 'b' at index 1, and so forth. Be sure to account for both upper and lowercase letters. Note that the index can be computed easily from the character using subtraction of ASCII codes (which are just the 'values' of characters in C++).

To count words you need a way of determining when you have completed reading a sequence of letters. There are a few different ways to do this.

Be sure your method of counting words counts the last one.

// **********************************************************

//

// WordLetterCount.cpp

//

// This program counts the number of words and the number

// of occurrences of each letter in a line of input.

//

// **********************************************************

#include <iostream>

#include <cctype>

using namespace std;

void readAndCount (int &numWords, int letterCount[]);

// Reads a line of input. Counts the words and the number

// of occurrences of each letter.

void outputLetterCounts (int letterCount[]);

// Prints the number of occurrences of each letter that

// appears in the input line.

// =========================

// main function

// =========================

int main()

{

int numWords;

int letterCount[26]; // stores the frequency of each letter

cout << endl;

cout << "Enter a line of text.." << endl << endl;

readAndCount (numWords, letterCount);

cout << endl;

cout << numWords << " words" << endl;

outputLetterCounts(letterCount);

return 0;

}

// =========================

// Function Definitions

// =========================

// --------------------------------

// ----- ENTER YOUR CODE HERE -----

// --------------------------------

// --------------------------------

// --------- END USER CODE --------

// --------------------------------

void outputLetterCounts(int letterCount[])

{

for (int i = 0; i < 26; i++)

{

if (letterCount[i] > 0)

{

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

}

}

}

Attachment:- wordlettercount.zip

Reference no: EM13938072

Questions Cloud

Find the effective rate charged by the bank : Bill Blank signed an $8,150 note at Citizen’s Bank. Citizen’s charges a 6.4 % discount rate. Assume the loan is for 310 days. Find the proceeds. Find the effective rate charged by the bank.
Calculate how much markway is able to borrow : Calculate how much Markway is able to borrow if each bond is sold at a discount of $30. Calculate how much Markway is able to borrow if each bond is sold at 96 percent of par.
Why have so many plants developed broad, flattened leaves : Why have so many plants developed broad, flattened leaves? What is heliotropism, and how does it make plants more efficient? What are sleep movements? Describe the model for leaf orientation in the upper, middle, and lower levels of a leaf canopy...
Calculate the gain or loss from subsidized debt : Triad Corporation has established a joint venture with Tobacco Road Construction, Inc., to build a toll road in North Carolina. The initial investment in paving equipment is $80.1 million. The equipment will be fully depreciated using the straight-li..
Write the definition of the readandcount function. : Write the definition of the readAndCount function. The function should read the input line, character by character, counting the number of words (a sequence of letters) and the number of occurrences of each letter.
The company is in the process of planning profit : The company is in the process of planning profit for the coming year.
The yield to maturity on a bond : The yield to maturity on a bond:
How do organisms acquire energy : What is the purpose of this pathway? What are the reactants? What are the products?
Develop a set of hrm recommendations for a fictitious : Develop a set of HRM recommendations for a fictitious, scenario organisation that will be assigned by the Faculty Member that contains the three primary assessment elements.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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