What's wrong !! I try to run this code but still showing me this in the compile :-( #include #include #include #include #include using namespace std; template void printmap(map < KTy, Ty >&map){ typename std:: map::iterator p; for( p=map.begin();p!=map.end();p++){ cout << p->first<<":" <second< &a, const pair &b){ return (a.second < b.second); } void Printmap(vector> m){ vector>::iterator itr; for ( itr = m.end()-1; itr >= m.begin(); itr--) cout << itr->first << ": " << itr->second << endl; } int main(void){ static const char* fileName="hitchhikersguide.txt"; map wordscount; { ifstream filestream(fileName); if(filestream.is_open()){ while (filestream.good()){ string word; filestream>> word; if(wordscount.find(word)==wordscount.end()){ wordscount[word]=1; } else{ wordscount[word]++; } } } else{ cerr << "Can't open the given file."<> vec; // copy key-value pairs from the map to the vector map :: iterator it2; for (it2= word.begin(); it2!= word.end(); it2++) { vec.push_back(make_pair(it2->first, it2->second)); } //sorting the map sort(vec.begin(),vec.end(),compare); // Print the words map. Printmap(vec); } printmap(wordscount); return EXIT_SUCCESS; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What's wrong !!

I try to run this code but still showing me this in the compile :-(

#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<fstream>
using namespace std;
template <class KTy,class Ty>

void printmap(map < KTy, Ty >&map){
typename std:: map<KTy,Ty>::iterator p;
for( p=map.begin();p!=map.end();p++){
cout << p->first<<":" <<p->second<<endl;
}


}
//comparing map on the basis of second element
bool compare( const pair <string, int> &a, const pair<string, int> &b){
return (a.second < b.second);
}
void Printmap(vector<pair<string, int>> m){
vector<pair<string, int>>::iterator itr;
for ( itr = m.end()-1; itr >= m.begin(); itr--)
cout << itr->first << ": " << itr->second << endl;
}
int main(void){
static const char* fileName="hitchhikersguide.txt";
map<string , unsigned int > wordscount;
{
ifstream filestream(fileName);
if(filestream.is_open()){
while (filestream.good()){
string word;
filestream>> word;
if(wordscount.find(word)==wordscount.end()){
wordscount[word]=1;
}
else{
wordscount[word]++;
}
}
}
else{
cerr << "Can't open the given file."<<endl;
return EXIT_FAILURE;
}
vector<pair<string, int>> vec;

// copy key-value pairs from the map to the vector
map<string, int> :: iterator it2;
for (it2= word.begin(); it2!= word.end(); it2++)
{
vec.push_back(make_pair(it2->first, it2->second));
}
//sorting the map
sort(vec.begin(),vec.end(),compare);

// Print the words map.
Printmap(vec);
}
printmap(wordscount);

return EXIT_SUCCESS;
}

 

64
|ubuntu [Running] - Oracle VM VirtualBox
File
Machine
View
Input
Devices
Help
Activities
A Visual Studio Code
Dec 14 19:23 •
SV
Labb4.cpp - labb4 - Visual Studio Code
File Edit Selection View Go Run Terminal Help
PROBLEMS 2
OUTPUT
DEBUG CONSOLE
TERMINAL
1: Code
+ 띠
v L4_wc
arwakhaddour@osboxes:~/Documents/C++/labb4/L4_wc$ cd "/home/arwakhaddour/Documents/C++/labb4/L4_wc
/" && g++ Labb4.cpp -o Labb4 && "/home/arwakhaddour/Documents/C++/labb4/L4_wc/"Labb4
Labb4.cpp: In function 'int main()':
Labb4.cpp:51:19: error: 'word' was not declared in this scope
51 |
E hitchhikersguide.txt
E labb4
E Labb4
for (it2= word.begin(); it2!= word.end (); it2++)
C• labb4.cpp
Labb4.cpp:56:9: error: 'sort' was not declared in this scope; did you mean 'qsort'?
56
G• Labb4.cpp
sort(vec.begin (),vec.end(),compare);
e wc.pdf
qsort
L4_wc.zip
arwakhaddour@osboxes:-/Documents/C++/labb4/L4_wc$ I
C• lab4.cpp
O 2 A0 6
Live Share -- INSERT --
Ln 13, Col 6 Spaces: 4 UTF-8 LF
C++ Linux 1.72 KB Q
2.
Transcribed Image Text:64 |ubuntu [Running] - Oracle VM VirtualBox File Machine View Input Devices Help Activities A Visual Studio Code Dec 14 19:23 • SV Labb4.cpp - labb4 - Visual Studio Code File Edit Selection View Go Run Terminal Help PROBLEMS 2 OUTPUT DEBUG CONSOLE TERMINAL 1: Code + 띠 v L4_wc arwakhaddour@osboxes:~/Documents/C++/labb4/L4_wc$ cd "/home/arwakhaddour/Documents/C++/labb4/L4_wc /" && g++ Labb4.cpp -o Labb4 && "/home/arwakhaddour/Documents/C++/labb4/L4_wc/"Labb4 Labb4.cpp: In function 'int main()': Labb4.cpp:51:19: error: 'word' was not declared in this scope 51 | E hitchhikersguide.txt E labb4 E Labb4 for (it2= word.begin(); it2!= word.end (); it2++) C• labb4.cpp Labb4.cpp:56:9: error: 'sort' was not declared in this scope; did you mean 'qsort'? 56 G• Labb4.cpp sort(vec.begin (),vec.end(),compare); e wc.pdf qsort L4_wc.zip arwakhaddour@osboxes:-/Documents/C++/labb4/L4_wc$ I C• lab4.cpp O 2 A0 6 Live Share -- INSERT -- Ln 13, Col 6 Spaces: 4 UTF-8 LF C++ Linux 1.72 KB Q 2.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education