Question

PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge...

PA #1: Word Counter
Tabulating basic document statistics is an interesting exercise that leverages your knowledge of strings, files, loops, and arrays. In this homework, you must write a C++ program that asks the user for an input and output file. For each line in the input file, write a modified line containing a line number to the output file. Additionally, calculate the number of paragraphs, lines, words, and characters. Write the summary information to the bottom of the output file.
Program Flow
Your program should operate as follows:
 Prompt the user for an input and output file
 Loop through the input file
o Increment the current line number
o If the line contains only a single newline character (\n), it is considered to be a paragraph. Increment the number of paragraphs
o Add the line's number of characters with spaces, characters without spaces, and word count to the document total.
 To make things simpler, use spaces to determine word boundaries. For example "quick thinking" is two words whereas "quick-thinking" is one.
 Remember to not count newlines '\n' as characters in any circumstances
o Write the current line number plus the line to the output file
 Write the following statistics at the bottom of the output file:
o paragraphs
o words
o characters (not counting spaces)
o characters (counting spaces)
o total lines
Required Functions
In all, you must define and use the following functions:
int get_character_count_with_spaces(string line);
This returns the total number of characters (including spaces) present in the given character array. Be sure not to count newline characters '\n' in this count.
int get_character_count_without_spaces(string line);
This returns the total number of characters (not including spaces) present in the given character array. Be sure to not count newline '\n' characters and spaces ' '.
int get_words(string line);
This returns the total number of words present in the given character array. For simplicities sake, words are defined by spaces. For example "quick thinking" is two words whereas "quick-thinking" is one.
int is_paragraph(string line);
This returns a value of 1 if the current line is a paragraph (only contains a newline '\n') and 0 otherwise.
void parse_file(ifstream input_file, ofstream output_file);
This function accepts input and output files and should be responsible for performing file calculations via the other functions. This is also where you will output the modified document with line numbers.
Sample Output
Your program's output should match the following:
Please enter a file to parse: savio.txt
Please enter a destination file: savio_parsed.txt
Program Complete.
The contents of the outputted file (in this case, savio_parsed.txt) would then look like:
1 We have an autocracy which runs this university. It's managed.
2 We asked the following: if President Kerr actually tried to get something more
3 liberal out of the Regents in his telephone conversation, why didn't he make
4 some public statement to that effect? And the answer we received -- from a
5 well-meaning liberal -- was the following: He said, "Would you ever imagine
6 the manager of a firm making a statement publicly in opposition to his board
7 of directors?" That's the answer! Now, I ask you to consider: if this is a
8 firm, and if the Board of Regents are the board of directors, and if President
9 Kerr in fact is the manager, then I'll tell you something: the faculty are a
10 bunch of employees, and we're the raw material! But we're a bunch of raw
11 material[s] that don't mean to have any process upon us, don't mean to be made
12 into any product, don't mean to end up being bought by some clients of the
13 University, be they the government, be they industry, be they organized labor,
14 be they anyone! We're human beings!
15
16 There is a time when the operation of the machine becomes so odious, makes you so
17 sick at heart, that you can't take part; you can't even passively take part,
18 and you've got to put your bodies upon the gears and upon the wheels, upon the
19 levers, upon all the apparatus, and you've got to make it stop. And you've got
20 to indicate to the people who run it, to the people who own it, that unless
21 you're free, the machine will be prevented from working at all!
--------------------------------------------------------------------------------
paragraphs: 1
words: 271
characters (no spaces): 1206
characters (with spaces): 1457
total lines: 21

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • C++ Programming question For this exercise, you will receive two string inputs, which are the names...

    C++ Programming question For this exercise, you will receive two string inputs, which are the names of the text files. You need to check if the input file exists. If input file doesn't exist, print out "Input file does not exist." You are required to create 4 functions: void removeSpace (ifstream &inStream, ofstream &outStream): removes white space from a text file and write to a new file. If write is successful, print out "Text with no white space is successfully...

  • Hello, I am struggling with this C# WPF application for one of my classes. I am...

    Hello, I am struggling with this C# WPF application for one of my classes. I am using visual studio to work on it. The description for the problem is as follows: Create an app that can open a text file. Each line of the file contains an arbitrary number of words separated by spaces. Display the count for how many words are in the line and the count how many non-space characters are in the line on the form /...

  • C language huffman This exercise will familiarize you with linked lists, which you will need for...

    C language huffman This exercise will familiarize you with linked lists, which you will need for a subsequent programming Getting Started assignment Overview Requirements Getting Started Submit Start by getting the files. Type 264get hw13 and then cd hw13 from bash. Pre-tester You will get the following files: Q&A Updates 1. huffman.h: An empty header file, you have to define your own functions in this homework. 2. huffman.c: An empty c file, you have to define your own functions in...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • FINAL Project 1-) Please submit the solution of your final as Ms-word or PDF document 2-)...

    FINAL Project 1-) Please submit the solution of your final as Ms-word or PDF document 2-) Complete THREE QUESTIONS out of the four exam questions below. 3-) FOR EACH QUESTION, IT IS REQUIRED to include Ms-Word or Pdf file contains the following A. Source file and sample of your output screen shots. B. Up to one page of your program discussion. In the discussion, state the issues that you may have problem with if there is any. Why your program...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT