aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lab8.txt24
-rw-r--r--num1.cpp66
-rw-r--r--num3.cpp2
3 files changed, 92 insertions, 0 deletions
diff --git a/lab8.txt b/lab8.txt
index 4e14e2f..a8952ef 100644
--- a/lab8.txt
+++ b/lab8.txt
@@ -15,6 +15,30 @@ p 317
4 pts #5-6
Submit: Statements for 5, Judgements for 6
+5.
+ a.) .is_open()
+ b.)
+
+ int num_data = 0;
+
+ //open file
+ ifstream input ("lab8.txt");
+
+ // check open file
+ if (input.is_open())
+ {
+ // priming
+ input >> lname[num_data] >> id[num_data] >> age[num_data];
+ }
+ else
+ cout << "File not opened" << endl;
+ return 0;
+
+ c.)
+ for the above ^^
+ input.close()
+
+
================================================================================================
diff --git a/num1.cpp b/num1.cpp
index e69de29..48c19aa 100644
--- a/num1.cpp
+++ b/num1.cpp
@@ -0,0 +1,66 @@
+// Tyler Taormina
+// CST 116
+// Nov 2021
+// Lab 8 Exercises
+
+
+#include <iostream>
+using namespace std;
+
+void findMedian(float arr[], int);
+float GetValues (float values[]);
+#define MAX 20
+
+int main ()
+{
+ int num_values;
+ float values [MAX] = {0};
+ num_values = GetValues(values);
+
+ cout << "Here is our list..." << endl;
+ for (int i = 0; i < num_values; i++)
+ cout << values[i] << " ";
+ cout << endl;
+
+ cout << "===================================================" << endl;
+
+ findMedian(values, num_values);
+ return 0;
+}
+
+
+float GetValues (float values[])
+{
+ int num_values = 0;
+ char cont = 'n';
+
+ do
+ {
+ cout << "Enter a number: ";
+ cin >> values[num_values++];
+
+ cout << "Enter another values (y/n)? ";
+ cin >> cont;
+ } while (toupper (cont) == 'Y' &&
+ num_values < MAX);
+ return num_values;
+}
+
+void findMedian(float arr[], int num_val)
+{
+ float x;
+
+ if ((num_val % 2) == 0)
+ {
+ x = (arr[num_val/2] + arr[(num_val/2) - 1])/2;
+
+ cout << "Even number Array. We will average the two middle most numbers to determine the median." << endl;
+ cout << "The median is: " << x << endl;
+ }
+ else
+ {
+ cout << "Odd number Array. We will find the number in the middle of the list which determines the median." << endl;
+ cout << "The median is: " << arr[num_val/2] << endl;
+ }
+
+}
diff --git a/num3.cpp b/num3.cpp
index e69de29..139597f 100644
--- a/num3.cpp
+++ b/num3.cpp
@@ -0,0 +1,2 @@
+
+