diff options
| author | JordanHT-OIT <[email protected]> | 2021-12-05 21:25:20 -0800 |
|---|---|---|
| committer | JordanHT-OIT <[email protected]> | 2021-12-05 21:25:20 -0800 |
| commit | 3a82a02c94aa66a523f6da119b2a008b7f980742 (patch) | |
| tree | 83a56aee6bd7d48e3450e59637214f785428be4f | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab9-jordanht-oit-3a82a02c94aa66a523f6da119b2a008b7f980742.tar.xz cst116-lab9-jordanht-oit-3a82a02c94aa66a523f6da119b2a008b7f980742.zip | |
Temporary commit to save progress
| -rw-r--r-- | CST116F2021-Lab9/1114_2_datafile.txt | 1 | ||||
| -rw-r--r-- | CST116F2021-Lab9/1114_3_datafile.txt | 10 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 144 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj | 4 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters | 4 |
5 files changed, 150 insertions, 13 deletions
diff --git a/CST116F2021-Lab9/1114_2_datafile.txt b/CST116F2021-Lab9/1114_2_datafile.txt new file mode 100644 index 0000000..85eb644 --- /dev/null +++ b/CST116F2021-Lab9/1114_2_datafile.txt @@ -0,0 +1 @@ +120 234 33 2021 44 23 530 567 340 501
\ No newline at end of file diff --git a/CST116F2021-Lab9/1114_3_datafile.txt b/CST116F2021-Lab9/1114_3_datafile.txt new file mode 100644 index 0000000..bba5287 --- /dev/null +++ b/CST116F2021-Lab9/1114_3_datafile.txt @@ -0,0 +1,10 @@ +He has a few screws loose. +Barking dogs and screaming toddlers have the unique ability to turn friendly neighbors into cranky enemies. +Mushrooms are a kind of fungus. +In that instant, everything changed. +The toddler's endless tantrum caused the entire plane anxiety. +He decided water-skiing on a frozen lake wasn't a good idea. +You have every right to be angry, but that doesn't give you the right to be mean. +As the years pass by, we all know owners look more and more like their dogs. +Tom didn't sound as if he was in trouble. +The door slammed on the watermelon.
\ No newline at end of file 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 diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj index fd67c6e..01f000d 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj @@ -141,6 +141,10 @@ <ItemGroup> <ClCompile Include="CST116F2021-Lab9.cpp" /> </ItemGroup> + <ItemGroup> + <Text Include="1114_2_datafile.txt" /> + <Text Include="1114_3_datafile.txt" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters index bb090d3..979188d 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters @@ -19,4 +19,8 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <Text Include="1114_2_datafile.txt" /> + <Text Include="1114_3_datafile.txt" /> + </ItemGroup> </Project>
\ No newline at end of file |