Exemplo n.º 1
0
void makeData(hashTable & table)
{
    data aData;
    char ticker[100];
    char name[100];
    char date[100];
    float value, ytd;
    cin.ignore(100, '\n');
    cout << "Please enter the stock ticker: ";
    cin.get(ticker, 100, '\n');
    cin.ignore(100, '\n');
    cout << "Please enter the stock asset name: ";
    cin.get(name, 100, '\n');
    cin.ignore(100, '\n');
    cout << "Please etner the net asset value: ";
    cin >> value;
    cin.ignore(100, '\n');
    cout << "Please enter the date of that value: ";
    cin.get(date, 100, '\n');
    cin.ignore(100, '\n');
    cout << "Please enter the year-to-date return: ";
    cin >> ytd;
    cin.ignore(100, '\n');
    
    aData.setTicker(ticker);
    aData.setName(name);
    aData.setValue(value);
    aData.setDate(date);
    aData.setYtd(ytd);
    
    table.insert(aData);

}
Exemplo n.º 2
0
void loadDict() {
	string filename;
	cout << "Enter name of dictionary: ";
	cin >> filename;

	clock_t t1 = clock();
	ifstream inputDict(filename.c_str());
	if (!inputDict) {
		cerr << "Error: could not open " << filename << endl;
		exit(1);
	}

	string line;
	while (getline(inputDict, line)) {
		line = toLowerCaseSTD(line);
		if (line.find_first_not_of(validCharacters) != string::npos
				|| line.length() > 20) {
			continue;
		}
		dict.insert(line);
	}
	inputDict.close();

	clock_t t2 = clock();
	double timeDiff = ((double) (t2 - t1)) / CLOCKS_PER_SEC;
	cout << "Total time (in seconds) to load dictionary: " << timeDiff << endl;
}
Exemplo n.º 3
0
bool fileRead(hashTable& table)
{
  int count = 0;
  string data;
  ifstream inFile;
  //Open file
  inFile.open(INFILENAME.c_str());
  //Read from file
  while (inFile >> data) {
	table.insert(data);
	count++;
  }
  inFile.close();
  return (count > 0);
}
Exemplo n.º 4
0
void loadDictionary(){
    string line;
    int newline;
    while (getline(dictfile, line)){ // Read in line from dictionary file
        newline = line.find_last_not_of("\n");
        if (newline != string::npos){
            line.erase(newline+1);
        }
        if (line.length() > 20 || line.find_first_not_of(valid_chars) != string::npos){
            continue;
        }
        dictionary.insert(toLowercase(line));
    }
    dictfile.close();
}
Exemplo n.º 5
0
/**
 * fileHandle(char*, hashTable&), reads in a file and passes each word of the file
 * onto a tokenize function and inserts the word into a hashtable
**/
void fileHandle ( char* fileName, hashTable &h )
{
    ifstream in;
    in.open ( fileName, ios::in );

    if ( !in )
    {
        cout << "Unable to open " << fileName << ". Exiting program.\n";
        return;
    }

    string x;
    auto c1 = clock();

    while ( in >> x )
    {
        x = tokenize ( x );

        // we would add into a hash table here..
        // should only need to add in, in the insert function for
        // our hash table it should be able to handle everything else
        if ( x != "" && !h.insert ( x ) )
        {
            cout << "Unable to insert " << x << " into hashtable. Exiting program\n";
            return;
        }
    }

    cout << "Finished generating a hash table of size " << h.getSize() << ".\n";
    cout << "Read " << h.getNumWords() << " words from the file " << fileName << ".\n";
    cout << "Inserted " << h.getNumDistinct() << " distinct words into the hash table.\n";
    cout << "Compacting and sorting the hash table ... ";
    h.sort();
    cout << "finished!\n";

    auto c2 = clock();
    auto totalTime = c2 - c1;
    cout << fixed << showpoint;
    cout << "Elapsed time = " << setprecision ( 1 ) << totalTime / ( CLOCKS_PER_SEC / 1000.0 )  <<  " msec.\n";

    h.printStats ( fileName );
}