/********************************************************************************************
readint.cpp
Jim Millard
for CO311
read integers into an array, then display them in either direction
********************************************************************************************/
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//prototypes
void readFrom(string file, int list[], const int size, int& count);
void showForward(int [], const int count);
void showBackward(int [], const int count);
void main()
{
const int MaxSize = 25;
int Array[MaxSize];
int count = 0;
string filename;
cout << "What is the file to read: ";
cin >> filename;
readFrom(filename, Array, MaxSize, count);
cout << "Total Elements Used: " << count << endl
<< "Out of a maximum of: " << MaxSize << endl;
showForward(Array, count);
showBackward(Array, count);
return;
}
void readFrom(string file, int list[], const int size, int& count)
{
ifstream fin(file.c_str());
for (int i = 0; i < size; i++)
{
if(fin >> list[i])
count++;
else
break;
}
return;
}
void showForward(int list[], const int count)
{
cout << "Forward:" << endl;
for (int i = 0; i < count; i++)
cout << list[i] << endl;
cout << endl;
return;
}
void showBackward(int list[], const int count)
{
cout << "Backward:" << endl;
for (int i = count; i > 0; i--)
cout << list[i-1] << endl;
cout << endl;
return;
}