Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 "; } 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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions