// main.cpp // This program is the driver program which tests the sequential and binary searches // Author: Brian Brindle #include #include #include #include #include "customer.h" #include "KeyedCollection1.h" // #include "KeyedCollection2.h" //use one or the other at a time using namespace std; ifstream fin; ifstream finkey; ofstream fout; void main() { KeyedCollection MailingData; string inputfile = "random.txt"; fin.open(inputfile.c_str()); // converts string to character array if (!fin) { cerr << "\nThere was an error in opening the file: " << inputfile << "\nThis program is being terminated immediately.\n\n"; exit(1); } string inputfile2 = "keys.txt"; finkey.open(inputfile2.c_str()); // converts string to character array if (!finkey) { cerr << "\nThere was an error in opening the file: " << inputfile2 << "\nThis program is being terminated immediately.\n\n"; exit(1); } string outputfilename = "mydata2.txt"; fout.open(outputfilename.c_str()); if (!fout) { cerr << "There was an error in opening the file " << outputfilename << "\nThis program is being ended.\n\n"; exit(1); } int id, zip, counter=0, keyNum=0, n=1; double salesVolume; bool found = false; string custName; Customer person, tempObj; while (fin >> id >> zip >> salesVolume) { getline(fin, custName, '\n'); person.SetCustID(id); person.SetZipCode(zip); person.SetSales(salesVolume); person.SetName(custName); MailingData.insert(keyNum, person); counter++; if (counter == 10) { finkey >> keyNum; found = MailingData.find(keyNum, tempObj); fout << n*counter << "\t" << MailingData.getNumComparisons() << endl; n++; counter = 0; } } cout << endl; fin.clear(); fin.close(); finkey.clear(); finkey.close(); fout.close(); }