Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program that reads a text file filled with words (for example animal names) and counts the number of occurrences of its constituent tokens

Create a program that reads a text file filled with words (for example animal names) and counts the number of occurrences of its constituent tokens using iterative object arrays. The arrays are limited to a capacity of 10. (The first 10 unique tokens take up the array slots.)

For testing purposes to create 2 text files. One is filled with max 10 words (some of them can be duplicates), and the other is filled with 10 unique words and multiple repetitions. I already have some code. I need help with the rest. Open to suggestions for fixing the code. #include #include #include using namespace std;

int main() { //Declaring all variables that will be used within the main function string fileName =""; //name of the input file string fileContents=""; //contents within the input file

////Start of the program cout<<"This program will count the number of words within your selected file, using the parallel iterative arrays."<

//Promting the user for the name of the file cout<<"Please enter the name of the file: "<>fileName;

//function to find the input file ifstream MyReadFile(fileName);

// Using a while loop together with the getline() function to read the file line by line, and input it into fileContents while (getline (MyReadFile, fileContents)) { //Output the text from the file - This section is to be deleted when done, just a process to make sure that the program reads the contents of the file. cout << "Your files contents: "<

// Here call the separate function (or subfunction) that will perform the operation from the given problem.

}

Name of the file: test1.txt Contents: Dog Cat Cow Pig Dog Cat Cow Cat Cow Pig

Name of the file: test2.txt Contents: Cat Cow Pig Alpaca Hamster Dog Fish Rat Zebra Lion Cat Cow Pig Alpaca Rat Zebra Lion Cow Pig Alpaca Hamster Dog Fish

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions