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

  Distributing license activation keys for software product

distributing license activation keys for a software product in a manner which is trustworthy and secure

  Define how does internet change information systems

The Internet may not make corporations obsolete, but they will have to change their business models

  Implement a base class person

Implement a base class Person. Derive classes Student and Instructor from Person. A person has a name and a birthday.

  Explain possible control measure for each level of hierarchy

Determine a possible control measure for each of the six levels in the hierarchy of controls, and explain the reasoning behind each choice.

  This is an individually prepared assessment task in this

q. that governments need to do more to safeguard the internet from hacking and cyber warfare because such activity

  Create an manages a 2d array of ints

Creates an manages a 2d array of ints. It has a constructor that takes a 2d array as a parameter and assigns it to the instance variable.

  Identify the fundamentals of public key infrastructure

Imagine you are an Information Systems Security Officer for a medium-sized financial services firm that has operations in four (4) states (Virginia, Florida).

  Your job is to made a risk-management policy which

you have just been hired as an information security engineer for a large multi-international corporation. unfortunately

  What is your design strategy to support global vision

Given the fact you have one of the larger dimension and very large regional sales data, what is your design strategy to support global vision with regional.

  What are three reasons that advanced persistent threat pose

What are three reasons that advanced persistent threat pose the greatest cyber intelligence threat to nation-state and commercial targets?

  How you would buy a domain name and register it

Investigate how you would buy a domain name (like "mycooldomainname.org") and register it so that other users could find it.

  Describe cognitive social phenomena that occur

Describe cognitive social phenomena that occur specifically to the context of the MMORPG that wouldn't happen in a face-to-face checkers game.

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