//To generate a coin flip
// constants for head and tail (if you want)
const tail = 0,
head = 1;
// A method to simulate a coin that is heads with probability 1/4
int coinFlip() {
if (drand48() < .25)
return head;
else
return tail;
}
// Here's some code that can be used to read either of the events
// file. Below has allEvents but you can change that to 20events.
// You'll have to add the calls to your skiplist and hashtable as
// needed.
#include <iostream>
#include <fstream>
using namespace std;
// parses the description and puts all characters in lower case
void parse(char* description, int length) {
char word[50];
clear(word,50);
int charc = 0; // counter of number of chars in word
for (int i=0; i < length; i++) {
if (description[i] != ' ' && description[i]!=0 && charc < 49)
word[charc++] = tolower(description[i]);
else {
word[charc]=0; // add end of word character
if (charc > 0) // if the word had at least one character
cout << "the word is " << word << endl;
charc = 0; // set charc to 0 for the next word
}
}
}
// the main driver for reading the events file
int main(int argc, char *argv[]) {
const char *fileName = "20events"; // 20events will be used if there is no
if (argc > 1) // filename given as the argument
fileName = argv[1];
ifstream is(fileName);
if (!is) {
cout << "Error: could not open file " << fileName << endl;
return -1;
}
int date;
char description[200];
while (is.peek() != EOF){
is >> date;
clear(description,200); //remove old description
is.getline(description,200);
parse(&(description[1]),199); // put description into lower case
// do something with the date and description beforing moving on
}
}