Computers play an important role in the analysis of texts Co

Computers play an important role in the analysis of texts. Concordances are such an example. A concordance is a list of all (or at least the most important) words in a text including their context, frequency, and so on, to allow careful study of these texts. Before the computer age, concordances were produced manually, which is a time-consuming process, and were conducted only for important texts. In this assignment you design and implement a console program that reads words from a text file and stores them in their order of appearance. After reading the file the user can get information about word frequency, occurrence, and contexts. After doing this assignment you are able to: work with multi-dimensional arrays; work with console I/O that handles user queries and displays information: work with text file I/O; work with type synonyms to improve program-comprehension. On Blackboard, the file \"IPC014_2016_assignment_7_files.zip\" contains a number of test text files. Design and implement a console program that allows the user to enter the commands: enter filename: the program attempts to open a text file with file name filename and reads and stores all words in their order of appearance, in an array. The filename is allowed to contain spaces (e.g., enter Alice\'s Adventures In Wonderland). If the open operation is successful, the number of words read is reported to the user. If it fails, then this information is told to the user as well. For reading words, you must use >>. See lecture slide #44. It is up to you to choose a representation for Word either as a C-string or as a C++-string. content: the program displays all stored words in their order of appearance. stop: the program terminates.

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files
#include <string>
#include <fstream>

using namespace std;

int main() // driver method
{
string myArray[100]; // array to store the data
string filename; //required initialisations
ifstream file;
int count = 0;
cout << \"Please enter the input file name: \"; // prompt for the user to enter the filename
cin >> filename;
filename = filename+\".txt\";
file.open( filename.c_str() ); // opening the filename

if(file.is_open()) // checking for the opening of the file
{
while ( !file.eof() ){
count++; // incrementing the count for the lines
for(int x = 0; x < count; x++){
file >> myArray[x]; // saving the data to the array
cout << \"The Array Data is : \" << myArray[x] << endl; // printing the output to console
}
}
file.close(); // closing the file
} else {
cout << \"Error Opening the File!!\" << endl; // catching the exception
}
cout << \"\ The total Words in the file are : \" << count << endl; // getting the count from the lines
return 0;
}

OUTPUT :

Please enter the input file name: input
The Array Data is : John
The Array Data is : Carter
The Array Data is : Harry
The Array Data is : Mornie
The Array Data is : Michael
The Array Data is : Mary
The Array Data is : Newton

The total Words in the file are : 7


Hope this is helpful.

 Computers play an important role in the analysis of texts. Concordances are such an example. A concordance is a list of all (or at least the most important) wo
 Computers play an important role in the analysis of texts. Concordances are such an example. A concordance is a list of all (or at least the most important) wo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site