From 68106d94900af8c5b4d57e2b15752167393e7338 Mon Sep 17 00:00:00 2001 From: tylr Date: Fri, 3 Dec 2021 09:54:33 -0800 Subject: Added additional data files. Number 2 complete. --- num2/num2.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'num2/num2.cpp') 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 // For the files!!!! #include // For manipulators & formatting options #include +#include +#include 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; - } -- cgit v1.2.3