aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Taormina <[email protected]>2021-11-30 22:19:04 -0800
committerTyler Taormina <[email protected]>2021-11-30 22:19:04 -0800
commitff730b6e4dbdf741d65fac0475b0eeab52e6bc51 (patch)
treefd4767ad15e04288ea3e7b40da9b31177530a9c2
parentAdding File. (diff)
downloadcst116-lab9-till-t-ff730b6e4dbdf741d65fac0475b0eeab52e6bc51.tar.xz
cst116-lab9-till-t-ff730b6e4dbdf741d65fac0475b0eeab52e6bc51.zip
Adding num2 folder that contains data file and code.
-rw-r--r--num2.cpp0
-rwxr-xr-xnum2/a.outbin0 -> 69858 bytes
-rw-r--r--num2/data.txt10
-rw-r--r--num2/num2.cpp115
4 files changed, 125 insertions, 0 deletions
diff --git a/num2.cpp b/num2.cpp
deleted file mode 100644
index e69de29..0000000
--- a/num2.cpp
+++ /dev/null
diff --git a/num2/a.out b/num2/a.out
new file mode 100755
index 0000000..a3b089b
--- /dev/null
+++ b/num2/a.out
Binary files differ
diff --git a/num2/data.txt b/num2/data.txt
new file mode 100644
index 0000000..d28c343
--- /dev/null
+++ b/num2/data.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
new file mode 100644
index 0000000..1426386
--- /dev/null
+++ b/num2/num2.cpp
@@ -0,0 +1,115 @@
+#include <iostream>
+#include <fstream> // For the files!!!!
+#include <iomanip> // For manipulators & formatting options
+#include <stdio.h>
+
+using std::cin;
+using std::cout;
+using std::endl;
+using std::setw;
+using std::ios;
+using std::resetiosflags;
+using std::setiosflags;
+
+using std::ifstream;
+using std::ofstream;
+
+const int MAX = 10;
+
+int ReadData ( ifstream &inFile, int data_arr[]);
+void Sort (int data_arr[], int counter);
+void Display_LS(int data_arr[], int counter);
+
+
+int main()
+{
+ int i;
+ int record_counter = 0;
+ int data[MAX];
+
+ ifstream inFile;
+
+ // Notice how this automatically opens the file
+
+ inFile.open ( "data.txt");
+
+ if ( inFile.is_open ( ) )
+ {
+
+ record_counter = ReadData (inFile, data);
+ inFile.close ( );
+ }
+
+ else
+ {
+ cout << "Trouble Opening File: inFile";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ }
+
+ Display_LS(data, record_counter);
+
+ Sort(data, record_counter);
+
+ for (i = 0; i < record_counter; i++)
+ cout << data[i] << endl;
+
+ return 0;
+
+}
+
+
+int ReadData(ifstream &inFile, int data_arr[])
+{
+ int counter = 0;
+ inFile >> data_arr[counter]; // Priming Read
+
+ while ( !inFile.eof ( ) )
+ {
+ counter++;
+ inFile >> data_arr[counter] ;
+ }
+
+ return counter;
+}
+
+
+void Sort (int data_arr[], int counter)
+{
+ int i;
+ int j;
+ int temp;
+
+ for (i = 0; i < counter; i++)
+ {
+ for (j = i+1; j < counter; j++)
+ {
+ if (data_arr[i] > data_arr[j])
+ {
+ temp = data_arr[i];
+ data_arr[i] = data_arr[j];
+ data_arr[j] = temp;
+ }
+ }
+ }
+}
+
+
+void Display_LS(int data_arr[], int counter)
+{
+ int large, small;
+ int i;
+ small = data_arr[0];
+ large = data_arr[0];
+ for (i = 1; i < counter; i++)
+ {
+ if (small > data_arr[i])
+ small = data_arr[i];
+ if (large < data_arr[i])
+ large = data_arr[i];
+
+ }
+
+ cout << "The smallest number is: " << small << endl;
+ cout << "The largest number is: " << large << endl;
+
+}