without using map
1. Write a C++ program to find out the top 10 words in terms of number of appearances in a given file, named “picasso.txt”. The data file is to be downloaded from iLMS system (http://lms.nthu.edu.tw). (Hint: The most efficient way to handle this problem is to build a word dictionary using class map in STL (Standard Template Library) if you know how to do it. On the other hand, without using map, it is still possible to solve this problem using only class vector in STL.) (Demonstrate it to one of your classmates, and then tell one of our TAs that you are done with this homework, and then you can get the 3 score points). (Results to be reported) Total no. of lines: 11 The total number of words in “picasso.txt”: 674 The 0-th frequent word is (the) with no. of appearances (87) The 1-th frequent word is (of) with no. of appearances (61) The 2-th frequent word is (and) with no. of appearances (48) The 3-th frequent word is (in) with no. of appearances (45) The 4-th frequent word is (a) with no. of appearances (38) The 5-th frequent word is (to) with no. of appearances (28) The 6-th frequent word is (Picasso) with no. of appearances (18) The 7-th frequent word is (was) with no. of appearances (17) The 8-th frequent word is (by) with no. of appearances (16) The 9-th frequent word is (is) with no. of appearances (15)
Answer:-
C++ Code
#include <iostream>
#include <map>
#include <fstream>
using namespace std;
int main()
{
std::map<std::string, int> wordCount;
ifstream input;
input.open("test.txt");
int counter = 0;
std::string word;
while(input >> word)
{
counter++;
++wordCount[word];
}
std::map<int, string, std::greater<int> > numMap;
for (std::map<std::string, int>::iterator it =
wordCount.begin(); it != wordCount.end(); ++it)
{
numMap.insert(make_pair(it->second, it->first ));
}
cout << " Total words: " << counter << endl << endl;
int output = 0;
for (std::map<int, string>::iterator it = numMap.begin(); it
!= numMap.end(); ++it)
{
cout << "The " << output << "- th frequent word
is (" << it->second << ") with no. of appearances ("
<< it->first << ")" <<endl;
output++;
if(output == 10) {
return 0;
}
}
}
Output:-
without using map 1. Write a C++ program to find out the top 10 words in...
All the white space among words in a text file was lost. Write a C++ program which using dynamic programming to get all of the possible original text files (i.e. with white spaces between words) and rank them in order of likelihood with the best possible runtime. You have a text file of dictionary words and the popularity class of the word (words are listed from popularity 1-100 (being most popular words), 101-200, etc) - Input is a text file...
using c++ program write this program without the optional exercise 3. Word Counter Write a function that accepts a pointer to a C-string as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago” the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the func tion. The number...
Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list....
write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File HANDLING..... you have to create functions 1. insert 2. delete 3. search(if we search with any letter then the words with same first letter have been shown) 4. display 6. exit Appearance should be like proper dictionary.
In C++ Please!!!!! Example main: #include <iostream> #include <fstream> #include <istream> #include <cstring> using namespace std; const int MAXRESULTS = 20; // Max matches that can be found const int MAXDICTWORDS = 30000; // Max words that can be read in int main() { string results[MAXRESULTS]; string dict[MAXDICTWORDS]; ifstream dictfile; // file containing the list of words int nwords; // number of words read from dictionary string word; dictfile.open("words.txt"); if (!dictfile) { cout << "File not found!" << endl; return...
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly. and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...
1. Specification For this assignment, write a static class named ShortestRoute to find the shortest route between San Francisco to New York City. (What makes it "static" is that all its members will be static.) The class will include two static recursive functions -- the first is simple, and just finds a valid route through the network, without regards to shortest distance. The second finds the shortest route. Both are explained below. 2. Create A Network Create a constant array...
Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...