C++ Please!
There are several fields in computer science that aim to understand how people use languages. One of the methods is to analyze the most frequently used words by certain writers.
Write a program that reads in a text file and stores the unique words and their counts in the array and compute the following:
The top n most frequent words found in the text file
Total number of unique words
Total number of words
Program specifications
Your program should use arrays (not vectors)
Each line in the text file contains at most 50 words.
In the text file, there are at most 200 unique words.
We have pre-processed the file to remove all punctuation.
All the words are in lowercase.
If the file cannot be opened, print “Could not open the file.”
Example:
For a text file that contains just the following line:
|
a true friend will be the true true friend |
Expected output:
Enter a filename:
friends.txt
Enter the value of n:
2
3 - true
2 - friend
Unique words: 6
Total words: 9
//C++ program
#include<iostream>
#include<fstream>
using namespace std;
int find(string words[],int totalUnique,string word){
for(int i=0;i<totalUnique;i++){
if(words[i] == word)return i;
}
return -1;
}
void Sort(string words[],int a[],int n){
int max;
for(int i=0;i<n-1;i++){
max=i;
for(int
j=i+1;j<n;j++)if(a[j]>a[max])max=j;
if(max!=i){
int
temp=a[i];
a[i]=a[max];
a[max]=temp;
string
str=words[i];
words[i]=words[max];
words[max]=str;
}
}
}
int main(){
string word,filename;
ifstream in;
cout<<"Enter a filename: ";
cin>>filename;
in.open(filename.c_str());
if(!in){
cout<<"File not
opened\n";
return 0;
}
string words[200];
int count[200],totalWords=0,totalUnique=0,n;
for(int i=0;i<200;i++){
count[i] = 0;
}
while(!in.eof()){
in>>word;
totalWords++;
int index =
find(words,totalUnique,word);
if(index==-1){
count[totalUnique]=1;
words[totalUnique++] = word;
}
else{
count[index]++;
}
}
Sort(words,count,totalUnique);
cout<<"Enter the value of n: ";
cin>>n;
if(n>totalUnique){
cout<<"There are only
"<<totalUnique<<" Words in the file"<<endl;
}
else{
for(int i=0;i<n;i++){
cout<<count[i]<<"-"<<words[i]<<endl;
}
}
cout<<"Unique
words:"<<totalUnique<<endl;
cout<<"Total
words:"<<totalWords<<endl;
in.close();
return 0;
}
C++ Please! There are several fields in computer science that aim to understand how people use...
please use c++
please write down the input file information
please add comments for some codes
please do not use #include <bits/stdc++.h> we did not
learn it yet
thank you
CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....
Problem 1. Implement a C++ program that has the following functions: Reads in a paragraph of English text up to 100 words from the keyboard and stores this paragraph in a string object. Feel free to include this task in the main() function. Identifies the least frequent letter (case insensitive) in the above paragraph. Implement a separate function getLeastFreqLetter() for this task. The main() function then calls this function to find out the least frequent letter and its frequency. Calculate...
hey please answer in python 3
This is the test for these questions. it has to be exactly the
same as the Expected output.
notice my code is very close to getting it but im always
off by 0.01 or 0.02.
Thank you for the help!
In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may...
Hi, I need help with my comp sci assignment. The parameters are listed below, but I am having trouble generating the number of occurrences of each word. Please use a standard library. Read in the clean text you generated in part 2 (start a new cpp file). Create a list of all the unique words found in the entire text file (use cleanedTextTest.txt for testing). Your list should be in the form of an array of structs, where each struct...
Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...
Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...
In this assignment, you will explore more on text analysis and an elementary version of sentiment analysis. Sentiment analysis is the process of using a computer program to identify and categorise opinions in a piece of text in order to determine the writer’s attitude towards a particular topic (e.g., news, product, service etc.). The sentiment can be expressed as positive, negative or neutral. Create a Python file called a5.py that will perform text analysis on some text files. You can...
The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been...
Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...
this is python do it in pycharm
Programming Practice 8.3: Most Frequent Character 15 pts Not Submitted Due Mar 15, 2020 at 11:59 PM Submission Types Website URL Grade O Out of 15 pts Points Submission & Rubric Description Lesson Objective(s): • Use the .upper function • Use loops with strings • Use lists with strings Lesson: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string. Ignore spaces,...