//
//
//  FilePairs.cc
//
//      AUTHOR: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Five, Main - question 1 [worth 12pts],  7/17/2002
//
// Description: Write a program that reads the file thousand.wrd
//				and writes an alphabetical list of all pairs of letters
//				that do NOT occur together in any of the words.
//				list each pair only once.
//
//       Usage: 
//
//      Method: main loop asks for a filename via getString(),
//              subsequently setting the pFileName property, and
//				calling readFile() and printData()
//
//              readFile()   - opens file [pFileName] and counts words
//              printData()  - prints the data collected by readFile()
//              
//   Functions: getString()  - reads a string from input
//
//		 Notes:
//

// include header
#include "FilePairs.h"


//
//   FilePairs class
//   analyzes files, counting number of small, large, and medium words
//
class FilePairs
{
	private :
	
		char *  pFileName;						// name of file being read
		int		pWordCount[MWORDSZ + 1];		// count of words in file
	   ifstream pInStream;						// in stream for file
		
      public:
       
		        FilePairs(char *filename); 		// constructor
		        ~FilePairs();					// destructor
       	int     readFile();						// open and read
		void    printData();					// display
		int     openFile();						// generic open
		int     closeFile();					// generic close
};


//
//  constructor for FilePairs class
//
FilePairs :: FilePairs (char * fileName)
{
	pFileName = fileName;
	for (int i = 1; i <= MWORDSZ; i++) {
		pWordCount[i] = 0;
	}
}


//
//  destructor for FilePairs class
//  
FilePairs :: ~FilePairs()
{
}

int FilePairs :: openFile()
{
	// open file		
	pInStream.open(pFileName);
	
	// ensure file exists
	if (pInStream == NULL) {					// file not found
	
		cout << pFileName << " -- Input file not found!\n";
		return -1;								// readFile failed
		
	} else {									// file OK
	
		pInStream.unsetf(ios::skipws);			// unset skip whitespace	
		
		return 0;								// readFile worked
	}
}


int FilePairs :: closeFile()
{
	pInStream.close();
	return 0;									// closeFile worked
}


//
//  read file [pFileName]
//
int FilePairs :: readFile()
{
	char c;
	int  wordLength;		
		
	while (! pInStream.eof() ) {
	
		pInStream >> c;						// read file
		
		cout << c;
	}
	
	return 0;									// readFile worked
}

//
//  Print data for FilePairs 
//
void FilePairs :: printData()
{	

}



void main()
{
	char fileName[MAXSTR];
	
	getString("Name of your file: ", fileName, MAXSTR);
	FilePairs robot( fileName );				// construct FilePairs object
	if ( robot.openFile() == -1 ) {
		 exit(1);								// file not found
	}
	robot.readFile();
	robot.printData();
	robot.closeFile();
	
	exit(0);
}