diff options
Diffstat (limited to 'num2/num2.cpp')
| -rw-r--r-- | num2/num2.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/num2/num2.cpp b/num2/num2.cpp index 1426386..18f17bf 100644 --- a/num2/num2.cpp +++ b/num2/num2.cpp @@ -2,6 +2,8 @@ #include <fstream> // For the files!!!! #include <iomanip> // For manipulators & formatting options #include <stdio.h> +#include <string> +#include <algorithm> using std::cin; using std::cout; @@ -13,47 +15,65 @@ using std::setiosflags; using std::ifstream; using std::ofstream; - const int MAX = 10; -int ReadData ( ifstream &inFile, int data_arr[]); +int ReadData (ifstream &inFile, int data_arr[]); void Sort (int data_arr[], int counter); void Display_LS(int data_arr[], int counter); int main() { + std::string input; + int i; int record_counter = 0; int data[MAX]; + int flag; + + cout << "THE FILES WE HAVE TO CHOOSE FROM: " << endl; + cout << "===================================================" << endl; + cout << "data.txt" << endl; + cout << "data2.txt" << endl; + cout << "hello.txt\n\n" << endl; + + + cout << "Please enter a name for the file to open: "; + cin >> input; + transform(input.begin(), input.end(), input.begin(), ::tolower); ifstream inFile; // Notice how this automatically opens the file - inFile.open ( "data.txt"); + inFile.open (input); if ( inFile.is_open ( ) ) { record_counter = ReadData (inFile, data); inFile.close ( ); + flag = 1; } else { - cout << "Trouble Opening File: inFile"; + cout << "Trouble Opening File: " << input << endl; + cout << "Check to make sure your spelling is correct for the file you are trying to open. Include .txt or whatever file extension is relevant." << endl; cout << "\n\n\t\t ** About to EXIT NOW! ** "; + flag = 0; } - Display_LS(data, record_counter); + if (flag == 1) + { + Display_LS(data, record_counter); + Sort(data, record_counter); - Sort(data, record_counter); + for (i = 0; i < record_counter; i++) + cout << data[i] << endl; + } - for (i = 0; i < record_counter; i++) - cout << data[i] << endl; - - return 0; + return 0; } @@ -111,5 +131,4 @@ void Display_LS(int data_arr[], int counter) cout << "The smallest number is: " << small << endl; cout << "The largest number is: " << large << endl; - } |