/******************************************************************************************** readstr.cpp Jim Millard for CO311 read strings into an array, then display them in either direction ********************************************************************************************/ #include <iostream> #include <string> #include <fstream> using namespace std; //prototypes void readFrom(string file, string list[], const int size, int& count); void showForward(string [], const int count); void showBackward(string [], const int count); void main() { const int MaxSize = 25; string 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, string 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(string list[], const int count) { cout << "Forward:" << endl; for (int i = 0; i < count; i++) cout << list[i] << endl; cout << endl; return; } void showBackward(string list[], const int count) { cout << "Backward:" << endl; for (int i = count; i > 0; i--) cout << list[i-1] << endl; cout << endl; return; }