//********************************************************************************
// C++ Certificate Program Intermediate Spring 1999 : Stephen Philips
//
// Final Project
// File       : \\Venus\katy\C++ Certificate\intermediate\Final Project
//				\WordCountBTree.h
//
// Purpose    : Declaration for class WordCountBTree to be used for counting words
//				in Lecture 6
//
// Author     : Hsin-yi F. Berg
// Date		  : 6/2/99
// Update	  : 6/8/99
//********************************************************************************
#include "WordCountBTree.h"
#include <iostream.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/*-----------------member function definition for class Token------------------*/
/*
	Token::Token()
	Constructor for a Token.
*/
Token::Token()
{
	token = "";
}
/*
	Token::~Token()
	Restructor for the Token.
*/
Token::~Token()
{
	if(token != "")
		delete[] token;
}
/*
	char *Token::GetNextToken(istream & in)
	Takes an istream and breaks it up into "tokens".
	Returns a string.
	If an empty string is returned, it's EOF
*/
char *Token::GetNextToken(istream &in)
{
	char next;						// char for peek operation
	char ch;						// char for get operation
	token = new char[max_char + 1];
	int flag = 0;	// flag to be set when a token is finished
					// being read in
	if(in.eof())
	{
		cout << "End of file reached...\n\n" << endl;
		exit(0);
	}
	// start at new token
	while(flag == 0)
	{
		// look ahead in istream
		next = in.peek();
		// if it's not the end-of-file, check if it's space or tab
		// ignore all the space
		if(isspace(next))
			in.eatwhite();
		// quit while we're ahead
		if(next == EOF)
		{
			token = "";
			flag = 1;
			break;
		}
		// keep reading in chars from istream until we
		// get to a white space or EOF or until maximum char size
		// is reached.
		int i = 0;
		do {
			ch = in.get();
			token[i++] = ch;
			next = in.peek();
		} while (! isspace(next) && (next != EOF) && (i < max_char));
		// terminate the string
		token[i] = '\0';
		// set the end-of-token flag
		flag = 1;
	}
	return token;
}
/*
	char *Token::GetValue()
	Converts Token to a char *.
*/
char *Token::GetValue()
{
	return token;
}
/*--------------member function definition for class WordCountTree---------------*/
/*
	WordCountBTree::WordCountBTree()
	Constructor of a WordCountBTree.
*/
WordCountBTree::WordCountBTree()
{}
/*
	WordCountBTree::~WordCountBTree()
	Destructor of a WordCountBTree.
*/
WordCountBTree::~WordCountBTree()
{}
/*
	void WordCountBTree::CountWordFreq(istream &in)
	Put all the words in the Btree and count the frequencies.
*/
void WordCountBTree::CountWordFreq(istream &in)
{
/*
	cout << "curToken is: " << curToken.GetValue();
	cout << endl;
	
	curToken.GetNextToken(in);
	cout << "next token is : " << curToken.GetValue() << endl;
	
	curToken.GetNextToken(in);
	cout << "next token is : " << curToken.GetValue() << endl;
*/
	// if the word is "" then we reach EOF
	while(strcmp(curToken.GetNextToken(in), "") != 0) {
		Add(curToken.GetValue());
	}
}
/*
	void WordCountBTree::PrintWordFreq()
	Print out all the words that are in the tree, and their frequencies.
*/
void WordCountBTree::PrintWordFreq()
{
	Print();
}

 

Back	End