/* Lecture Code 0.2
 *
 * Printing a table based on file contents.  To run this program, copy the following 
 * text and save it as a file called table-data.txt
 *
 * 137 2.71828
 * 42  1.0000
 * 1000000000 4.1498235
 * -5 -1.01101010001
 */
 
#include <iostream>
#include <fstream>	// Necessary for ifstream
#include <string>	// These two lines replace #include "genlib.h"
using namespace std;

const int NUM_COLUMNS = 3;
const int NUM_ENTRIES = 4;
const int COLUMN_WIDTH = 15;

void PrintTableHeader()
{
	cout << setfill('-');
	
	for(int i = 0; i < NUM_COLUMNS - 1; i++)
		cout << setw(COLUMN_WIDTH) << "" << "-+-";
	
	cout << setw(COLUMN_WIDTH) << "" << setfill(' ') << endl;
}
int main()
{
	int readInInteger;
	double readInDouble;
	
	ifstream input("table-data.txt");
	
	PrintTableHeader();
	
	/* As an exercise, rewrite this code so it reads until the end of the file, not just
	   NUM_ENTRIES entries. */
	for(int i = 0; i < NUM_ENTRIES; i++)
	{
		input >> readInInteger >> readInDouble;
		cout << setw(COLUMN_WIDTH) << i << " | ";
		cout << setw(COLUMN_WIDTH) << readInInteger << " | ";
		cout << setw(COLUMN_WIDTH) << readInDouble << endl;
	}
	
	return 0;
}