/* 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
using namespace std; // Replaces genlib.h

const int NUM_COLUMNS = 3;
const int NUM_ENTRIES = 4;
const int COLUMN_WIDTH = 15;

int main()
{
	// Open the file
	ifstream input("table-data.txt");
	
	// Print the table header
	cout << setfill('-');	
	for(int i = 0; i < NUM_COLUMNS - 1; i++)
		cout << setw(COLUMN_WIDTH) << "" << "-+-";	
	cout << setw(COLUMN_WIDTH) << "" << setfill(' ') << endl;
	
	/* 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++)
	{
		int readInInteger;
		double readInDouble;
		input >> readInInteger >> readInDouble;
		cout << setw(COLUMN_WIDTH) << i << " | ";
		cout << setw(COLUMN_WIDTH) << readInInteger << " | ";
		cout << setw(COLUMN_WIDTH) << readInDouble << endl;
	}
	
	return 0;
}