Question

You must write a program which reads, processes and reports on the contents of a text file.

Your program should:
1. Read the name of the text file from the console.
2. Read in a text file, line by line.
3. Split each line into words, discarding punctuation and folding all letters into lower case.
4. Store the unique words and maintain a count of each different word.
5. Sort the words first by decreasing count and, if there are multiple words with the same count, alphabetically.
6. Output the first ten words in the sorted list, along with their counts.
7. Output the last ten words in the list, along with their counts.
You must choose appropriate data structures and algorithms to accomplish this task.

Note: in the context of this assignment, appropriate choices will be efficient and will not use excessive instructions or data.
Note: where a punctuation mark appears between two letters, the sequence is to be treated as a single word. Thus, it’s will become its, you’ll will become youll and loop-hole will become loophole.
Note: you can assume that the input file contains no more than 50,000 different words.

Note: you may use any data structures or algorithms that have been presented in class. If you use other data structures or algorithms appropriate references must be provided.
Programs must compile and run under gcc (C programs), g++ (C++ programs) java or python.

Programs should be appropriately documented with comments.
All coding must be your own work. Standard libraries of data structures and algorithms such as STL may not be used, nor may code be sourced from textbooks, the internet, etc.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <cstdlib>
#include <iostream>
#include <string.h>
#include <fstream>

using namespace std;

const int MAX_SIZE = 50176; // 10240 * 49
const int WORD_LENGTH = 50;
const int LINE_LENGTH = 1024;
const int NIL = -1;

//wordPos points at the start of the word in the words array.
//wordCnt keeps count of the word frequency
//wordLen stores the length of the word.

struct IndexType {
    int wordPos, wordCnt, wordLen;
};

// array of index

struct IndexTypeArray {
    IndexType data[MAX_SIZE];
    int size;
};

struct Node {
    int index_ITA;
    char word[WORD_LENGTH];
    int left;
    int right;
    int hght;
};

struct AVL {
    Node node[MAX_SIZE];
    int size;
    int root;
};...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

C++ Programming Algorithms
Homework Solution
$25.00
Computer Science
Programming
Algorithms
C++
Closest Pairs
Sequences
Subsequences
Naive Bayes
Functions
Methods
Loops
Variables
Statements
Accounting Problems Using C++ Programming
Homework Solution
$10.00
Computer Science
Accounting
C++ Programming
Saving Money
Monthly Interest
Future Value
Present Value
Functions
Statements
Conditions
E-Commerce Website Discussion (420 words)
Homework Solution
$5.00
Computer Science
E-Commerce
Website Development
Technology
Interactivity
Information Density
Products
Business
NewEgg
Customer Support
Search Functions
Social Networking
Diversity
Main Memory Management
Homework Solution
$180.00
Computer Science
C++
Programming
Main Memory Management
Operations
Systems
Allocated Blocks
Memory Arrays
Assumptions
Codes
Distribution
Allocation Strategies
Steep Curves
Algorithms
Calculator Using C++ Programming
Homework Solution
$73.00
Computer Science
Programming
C++
Algorithms
Calculator
Vectors
Operands
Users
Classes
Overloaded Operators
Management
Member Functions
Floating Point
Addition
Symbols
Fractions
Multiplication
Subtraction
Division
Java Programming: Game Development Problems
Homework Solution
$205.00
Computer Science
Java Programming
Game Development
Customers
Requests
Buyers
Suppliers
Profit
Maximization
Tables
Excel Sheets
Functions
Statements
Variables
Classes
Interfaces
Get help from a qualified tutor
Live Chats