aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab9/CST116F2021-Lab9.cpp
diff options
context:
space:
mode:
authorJordanHT-OIT <[email protected]>2021-12-05 21:25:20 -0800
committerJordanHT-OIT <[email protected]>2021-12-05 21:25:20 -0800
commit3a82a02c94aa66a523f6da119b2a008b7f980742 (patch)
tree83a56aee6bd7d48e3450e59637214f785428be4f /CST116F2021-Lab9/CST116F2021-Lab9.cpp
parentAdd online IDE url (diff)
downloadcst116-lab9-jordanht-oit-3a82a02c94aa66a523f6da119b2a008b7f980742.tar.xz
cst116-lab9-jordanht-oit-3a82a02c94aa66a523f6da119b2a008b7f980742.zip
Temporary commit to save progress
Diffstat (limited to 'CST116F2021-Lab9/CST116F2021-Lab9.cpp')
-rw-r--r--CST116F2021-Lab9/CST116F2021-Lab9.cpp144
1 files changed, 131 insertions, 13 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp
index d7b3cce..259721c 100644
--- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp
+++ b/CST116F2021-Lab9/CST116F2021-Lab9.cpp
@@ -1,20 +1,138 @@
-// CST116F2021-Lab9.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
+//Code by Jordan Harris-Toovy for OIT's CST116-01P lab 9, December 2021
+#include <sstream>
#include <iostream>
+#include <string>
+#include <fstream>
+#include <iomanip>
-int main()
+using namespace std;
+
+#define MV_1 10
+
+//16a - 11.14 Programming Exercises #2:
+/*
+void bubiSort(int[MV_1], int);
+int loadFileData(ifstream&, int[MV_1]);
+
+int main(void)
+{
+ string path = "C:\\Users\\jorda\\source\\repos\\cst116-lab9-JordanHT-OIT\\CST116F2021-Lab9\\", fileName, ext = ".txt";
+ ifstream dataFile;
+ int length = 0, data[MV_1];
+ bool fileValid = false;
+
+ do
+ {
+ cout << "Enter name of data file: ";
+
+ getline(cin, fileName);
+
+ dataFile.open(path + fileName + ext);
+
+ fileValid = !dataFile.fail();
+
+ if (!fileValid)
+ {
+ cout << "Invalid file name" << endl;
+ }
+
+ }
+ while (!fileValid);
+
+ length = loadFileData(dataFile, data);
+
+ dataFile.close();
+
+ bubiSort(data, length);
+
+ cout << "The smallest number in the file is: " << data[0] << "\nThe largest number in the file is: " << data[length - 1] << endl;
+ cout << "The file contents are: " << endl;
+
+ for (int idx = 0; idx < length; idx++)
+ {
+ cout << data[idx] << " ";
+ }
+
+ cout << endl;
+
+ return (0);
+}
+
+int loadFileData(ifstream& inData, int arr[MV_1])
{
- std::cout << "Hello World!\n";
+ int entries = 0;
+
+ while (!inData.eof())
+ {
+ inData >> arr[entries];
+ entries++;
+ }
+
+ return (--entries);
+}
+
+void bubiSort(int arr[MV_1], int len)
+{
+ int pass = 0, hold = 0;
+ while (pass <= len)
+ {
+ for (int idx = 0; idx < (len - 1); idx++)
+ {
+ if (arr[idx] > arr[idx + 1])
+ {
+ hold = arr[idx + 1];
+ arr[idx + 1] = arr[idx];
+ arr[idx] = hold;
+ pass = 0;
+ }
+ else
+ {
+ pass++;
+ }
+ }
+ }
+}
+*/
+
+//16a - 11.14 Programming Exercises #3:
+/*
+int main(void)
+{
+ string path = "C:\\Users\\jorda\\source\\repos\\cst116-lab9-JordanHT-OIT\\CST116F2021-Lab9\\", fileName, ext = ".txt", currentLine;
+ ifstream dataFile;
+ bool fileFailed = false;
+ int lineNumber = 0;
+
+ do
+ {
+ cout << "Enter name of data file: ";
+
+ getline(cin, fileName);
+
+ dataFile.open(path + fileName + ext);
+
+ fileFailed = dataFile.fail();
+
+ if (fileFailed)
+ {
+ cout << "Invalid file name" << endl;
+ }
+
+ } while (fileFailed);
+
+ while (!dataFile.eof())
+ {
+ getline(dataFile, currentLine);
+
+ cout << 1 + lineNumber++ << ")\t" << currentLine << "\t(" << currentLine.length() << " chars)" << endl;
+ }
+
+ dataFile.close();
+
+ return (0);
}
+*/
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
+//16a - 11.14 Programming Exercises #4:
-// Tips for Getting Started:
-// 1. Use the Solution Explorer window to add/manage files
-// 2. Use the Team Explorer window to connect to source control
-// 3. Use the Output window to see build output and other messages
-// 4. Use the Error List window to view errors
-// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
-// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file