Need Help. The program compiles and runs but not working to full capacity. I cant figure out how to make the program pick up spaces. I have "trash bag" and "trash can" in my code but it only picks up trash, and its to many frequencies for the item .
#include<iostream>#include<map>#include<iterator>#include<algorithm>#include<string>#include<fstream>#include<sstream>usingnamespacestd;stringisLower(strings){stringdata=s;std::transform(data.begin(),data.end(),data.begin(),::tolower);returndata;}stringtrim(stringstr){stringstreamtrimmer;trimmer<<str;str.clear();trimmer>>str;returnstr;}intmain(){map<string,int>item_count;stringline;// variable used to read a line from fileintlines=0;// variable containing the numbers of transactionsifstreammyfile("C:/Users/marqu_000/Documents/marketda.txt");if(myfile.is_open())// checking if the file was open{getline(myfile,line);// to ignore the first line which contains number of transactions while(getline(myfile,line))// read the file line by linr until end of file is reached{//now we are processing each linestringstreamss(line);inti;stringitem;// ignore Transection ID, #of Itemsgetline(ss,item,',');getline(ss,item,',');while(getline(ss,item,',')){item=trim(isLower(item));// Now the item variable is containing the item namemap<string,int>::iteratoritr=item_count.find(item);if(itr==item_count.end()){//means the element is not presentitem_count.insert(pair<string,int>(item,1));}else{// increment the countitr->second=1+itr->second;}}}// now traverse in the array and print entries which have count 1 cout<<"unique item: "<<endl;for(map<string,int>::const_iteratorit=item_count.begin();it!=item_count.end();++it){cout<<it->first<<endl;}cout<<endl<<"Items frequencies: "<<endl;for(map<string,int>::const_iteratorit=item_count.begin();it!=item_count.end();++it){cout<<it->first<<":"<<it->second<<endl;}myfile.close();//closing the file}else{cout<<"Unable to open input file."<<endl;return1;}return0;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Need Help. The program compiles and runs but not working to full capacity. I cant figure out how to make the program pick up spaces. I have "trash bag" and "trash can" in my code but it only picks up trash, and its to many frequencies for the item .