diff options
Diffstat (limited to 'num2')
| -rwxr-xr-x | num2/a.out | bin | 69858 -> 75266 bytes | |||
| -rw-r--r-- | num2/data2.txt (renamed from num2/data.txt) | 0 | ||||
| -rw-r--r-- | num2/hello.txt | 10 | ||||
| -rw-r--r-- | num2/num2.cpp | 41 |
4 files changed, 40 insertions, 11 deletions
| Binary files differ diff --git a/num2/data.txt b/num2/data2.txt index d28c343..d28c343 100644 --- a/num2/data.txt +++ b/num2/data2.txt diff --git a/num2/hello.txt b/num2/hello.txt new file mode 100644 index 0000000..d28c343 --- /dev/null +++ b/num2/hello.txt @@ -0,0 +1,10 @@ +120 +234 +33 +2021 +44 +23 +530 +567 +340 +501 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; - } |