diff options
| author | James Lawrance <[email protected]> | 2021-11-23 21:29:11 -0800 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-11-23 21:29:11 -0800 |
| commit | ea93e6d7dbe2ef6e8bfc58b6feeb07ba3809ec3f (patch) | |
| tree | 7eba8abd196d77a6387556e7054967298c6e0d09 /CST116F2021-Lab8/Functions.cpp | |
| parent | Add online IDE url (diff) | |
| download | cst115-lab8-jemersonlawrance-master.tar.xz cst115-lab8-jemersonlawrance-master.zip | |
Diffstat (limited to 'CST116F2021-Lab8/Functions.cpp')
| -rw-r--r-- | CST116F2021-Lab8/Functions.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/CST116F2021-Lab8/Functions.cpp b/CST116F2021-Lab8/Functions.cpp new file mode 100644 index 0000000..0070aef --- /dev/null +++ b/CST116F2021-Lab8/Functions.cpp @@ -0,0 +1,156 @@ +#include "Header.h" + +//13b + +void getInput(int valuesList[], int& VALUE) +{ + while (valuesList[VALUE] != '\0') + { + VALUE++; + + cout << "\nEnter value #" << VALUE + 1 << ". Enter 0 to stop input and display median.\n"; + cin >> valuesList[VALUE]; + if (valuesList[VALUE] == 0) + { + valuesList[VALUE] = '\0'; + } + } + + VALUE = 0; +} + +void calculateLength(int valuesList[], int& VALUE, int& valuesTotal) +{ + while (valuesList[VALUE] != '\0') + { + valuesTotal++; + VALUE++; + } + + VALUE = 0; +} + +void lowestToHighest(int valuesList[], int& VALUE, int& valuesTotal, int reorderList[], int& reorderTotal) +{ + while (reorderTotal < valuesTotal) + { + int mostBig = 0; + int mostBigPos = 0; + VALUE = 0; + + while (VALUE < valuesTotal) + { + if (valuesList[VALUE] > mostBig) + { + mostBig = valuesList[VALUE]; + mostBigPos = VALUE; + } + VALUE++; + } + + reorderList[((valuesTotal)-reorderTotal) - 1] = mostBig; + valuesList[mostBigPos] = 0; + + reorderTotal++; + } + + VALUE = 0; + + while (VALUE < valuesTotal) + { + valuesList[VALUE] = reorderList[VALUE]; + + VALUE++; + } + + VALUE = 0; +} + +void calculateMedian(int valuesList[], int& VALUE, int& valuesTotal) +{ + if (valuesTotal % 2 == 0) + { + int mid1 = 0; + int mid2 = 0; + + while (VALUE <= (valuesTotal / 2)) + { + + if (VALUE == ((valuesTotal / 2) - 1)) + { + mid1 = valuesList[VALUE]; + } + + if (VALUE == ((valuesTotal / 2))) + { + mid2 = valuesList[VALUE]; + } + + VALUE++; + } + + cout << "\nThe median of your input is: " << (mid1 + mid2) / 2 + << endl; + + } + else + { + int mid = 0; + + VALUE = ((valuesTotal / 2)); + mid = valuesList[VALUE]; + + cout << "\nThe median of your input is: " << mid + << endl; + } +} + +//13c + +int checkFile() +{ + ifstream inFile; + inFile.open("employee data.txt"); + + if (!inFile) + { + return 0; + } + else + { + return 1; + } +} + +void createFile() +{ + ofstream newFile; + newFile.open("employee data.txt"); + newFile.close(); + + cout << "No file detected. " + << "A new file has been created. " + << "Please input data into the file and restart the program.\n"; +} + +void formatData() +{ + int wage[100] = {}; + string text; + + //if the file is detected + cout << "File detected. Formatting data...\n" + << endl; + + ifstream readFile; + readFile.open("employee data.txt"); + + while (readFile) + { + getline(readFile, text); + cout << text << endl; + } + + cout << "\nAll data has been read. The program will now end." + << endl; +}
\ No newline at end of file |