Program to count words and numbers in a plain text file

Assignment Help Computer Engineering
Reference no: EM132194686

Question :

Write a C++ program to count words and numbers in a plain text file. Words and numbers can be repeated.

The input is one text file, with words and integers, separated by any other symbols including spaces, commas, period, parentheses and carriage returns.

Keep in mind there can be be multiple separators together (e.g. many spaces, many commas together).

The input is simple. You can assume a word is a string of letters (upper and lower case) and a number a string of digits (an integer without sign).

Words and numbers will be separated by at least one non-letter or one non-digit symbol.

Length: You can assume one word will be at most 30 characters long and a number will have at most 10 digits. Repeated strings: words and numbers can be repeated.

However, you are not asked count distinct words or compute frequency per word, which require algorithms and data structures to be covered in the course. Therefore, you just simply need to count word or numver occurrences. #include "ArgumentManager.h" int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "Usage: count filename=input1.txt\n"; } ArgumentManager am(argc, argv); std::string filename = am.get("filename"); std::ifstream ifs(filename.c_str()); std::string line; while (getline(ifs, line)){ // replace symbols by space for line. // ... std::stringstream ss(line.c_str()); std::string str; while (ss >> str) { if (is_number(str)) { // ... } else { // ... } } } return 0; }

Reference no: EM132194686

Questions Cloud

Accurate measure of the standard of living : Is gross domestic product an accurate measure of the standard of living? Why or why not?
Create a 2-dimensional array of 10 by 5 elements : Create a 2-dimensional array of 10x5 elements that are populated by random numbers between 0 and 49.
Medical marijuana laws : In recent years, about twenty states have passed so-called medical marijuana laws. Typically, these laws permit individuals to lawfully purchase marijuana
Legalization of presently illegal substances : Of what significance is the elasticity of demand for drugs in the debate about legalization of presently illegal substances?
Program to count words and numbers in a plain text file : Write a C++ program to count words and numbers in a plain text file. Words and numbers can be repeated.
Supporters of a higher minimum wage : Why do you think organized labor groups, such as unions, are supporters of a higher minimum wage, even though all of their members earn much more
Ask the user to input the number of rows and columns : The program will fill the arry starting at location [0][0] with the user selected starting number and each element after will be incremented by the user direct.
How a change in the exchange rate affected firm : Describe how a change in the exchange rate affected your firm. Explain what happened to your price and quantity.
Elasticity of demand for a given product or services : What are the two primary factors that determine the elasticity of demand for a given product or services?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Write the program in c++ language

Write a program to read a student's number, his or her old grade point average, and old number of course credits (e.g., 31479, 3.25, 66) and to then print these with appropriate labels.

  How the prices paid differed for each staff member

ITECH1100 Understanding the Digital Revolution Assignment - Book Boomerang. How the prices paid differed for each staff member

  Define what is the look up table

The PIC18F4321 microcontroller is required to input a number from 0 to 9 from an ASCII keyboard interfaced to it and output to an EBCDIC printer.

  Define cfr and list its advantages and disadvantages

Define CFR and list its advantages and disadvantages. Divide the five modes of operation into two groups: those that use the encryption and decryption function.

  Suggesting the dss solution

Now you are asked to suggest a DSS solution in order to help the claim adjusters recognizes and red flag various types of fraud.

  What type of regular expressions does grep support

What type of regular expressions does grep support? (BRE, ERE, or both)

  World wide web affect accountability in important ways

the World Wide Web affect accountability in important ways. Do you think e-reporting makes government more responsive

  Design and implement a class to model a battery

A battery object should know its voltage, how much energy it is capable of storing, and how much energy it is currently storing (in joules).

  What is the minimum number of k bits necessary

What is the minimum number of ‘k' bits necessary for the Hamming singleerror-correcting (SEC)? Define Seek Time, Rotational Delay and Transfer Time.

  Define a class for a type called countertype

Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a nonnegative whole number.

  Examination of a storage media

Digital Forensics Examiner. Considering a real or a hypothetical case you are required to produce a formal report consisting of facts from your findings to your attorney who has retained you.

  Create a driver class called rollingdice-two

Using the Die class defined in this chapter, write a class called PairOfDice, composed of two Die objects. Include methods to set and get the individual die.

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