Question: I have a program in C++ with the following Code and Text File below How Can I include a threshold computation method: choose one for#(A,B)/

I have a program in C++ with the following Code and Text File below

How Can I include a threshold computation method: choose one for#(A,B)/ #A or (#(A,B)/#A)/ #Transactions

Threshold: 0.30

banana ----> apple, 0.30

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

string toLower(string s) {

string data = s;

std::transform(data.begin(), data.end(), data.begin(), ::tolower);

return data;

}

string trim(string str){

stringstream trimmer;

trimmer << str;

str.clear();

trimmer >> str;

return str;

}

int main()

{

map item_count;

string line; // variable used to read a line from file

int lines =0; // variable conatining the number of transactions

ifstream myfile("/Users/TheKid/Library/Mobile Documents/com~apple~TextEdit/Documents/en.lproj/marketdata.txt");

if (myfile.is_open()) // checking if the file was opened

{

getline(myfile,line); // to ignore the first line which contains number of transactions

while(getline(myfile,line)) //read the file line by line until end of file is reached

{

// now we are processign each line

stringstream ss(line);

int i;

string item;

int count;

// ignore Transactions ID, #of Items

getline(ss, item, ',');

getline(ss, item, ',');

count = atoi(item.c_str());

while (count-- && getline(ss, item, ',')) {

item = trim(toLower(item));

// Now the item variable is containing the item name

map::iterator itr = item_count.find(item);

if (itr == item_count.end() ) {

// means the element is not present

item_count.insert(pair(item,1));

} else {

// increment the count

itr->second = 1 + itr->second;

}

}

}

// now traverse in the array and print entries which have count 1

cout << "unique items: " << endl;

for( map::const_iterator it = item_count.begin(); it != item_count.end(); ++it ) {

if(it->second == 1) {

cout << it->first << endl;

}

}

cout << endl << "Items frequencies: " << endl;

for( map::const_iterator it = 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;

return 1;

}

return 0;

}

20 // Number of Transactions

1, 2, gum, bread //transaction id, # of items purchased, item1, item2,...

2, 2, gum, napkin

3, 3, fruit, bread, fork

4, 7, milk, bread, napkin, fork, juice, soup, fruit

5, 4, juice, napkin, milk, bread

6, 2, bread, spoon

7, 1, juice

8, 3, juice, napkin, milk

9, 4, juice, napkin, milk, turkey

10, 1, pork

11, 10, milk, egg, bread, napkin, spoon, chicken, water, juice, soup, fork

12, 1, egg

13, 2, bread, milk,

14, 5, gum, salt, fruit, vegetable, bread

15, 1, bread

16, 2, bread, milk

17, 3, bread, salt, egg

18, 2, milk, napkin

19, 3, turkey, juice, milk

20, 3, turkey, chicken, soup

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!