diff options
Diffstat (limited to 'CST116F2021-Lab9/CST116F2021-Lab9.cpp')
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp index 1372506..f923ec5 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9.cpp @@ -24,7 +24,7 @@ int main(void) int length = 0, data[MV_1]; bool fileValid = false; - do + do //Ask the user for the file name until a valid filename is entered { cout << "Enter name of data file: "; @@ -46,12 +46,12 @@ int main(void) dataFile.close(); - bubiSort(data, length); + bubiSort(data, length); //Sort the array in assending order 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++) + for (int idx = 0; idx < length; idx++) //Print all of the data { cout << data[idx] << " "; } @@ -61,6 +61,7 @@ int main(void) return (0); } +//Load an array with data from a filestream int loadFileData(ifstream& inData, int arr[MV_1]) { int entries = 0; @@ -74,6 +75,7 @@ int loadFileData(ifstream& inData, int arr[MV_1]) return (--entries); } +//My poor implementation of bubblesort void bubiSort(int arr[MV_1], int len) { int pass = 0, hold = 0; @@ -106,7 +108,7 @@ int main(void) bool fileFailed = false; int lineNumber = 0; - do + do //Ask the user for the file name until a valid filename is entered { cout << "Enter name of data file: "; @@ -123,11 +125,13 @@ int main(void) } while (fileFailed); - while (!dataFile.eof()) + cout << endl; + + while (!dataFile.eof()) //Repeat until EOF { getline(dataFile, currentLine); - cout << 1 + lineNumber++ << ")\t" << currentLine << "\t(" << currentLine.length() << " chars)" << endl; + cout << 1 + lineNumber++ << ")\t" << currentLine << "\t(" << currentLine.length() << " chars)" << endl; //Use the .length class to display the number of chars } dataFile.close(); @@ -152,7 +156,7 @@ void displayEntry(string[4][MV_3], int); int main(void) { int menuChoice = 0, numEntries = 0, metaData[2][MV_3]{ 0 }, select = 0; - string fileLoc = "C:\\Users\\jorda\\source\\repos\\cst116-lab9-JordanHT-OIT\\CST116F2021-Lab9\\1114_4_datafile.txt"; + string fileLoc = "C:\\Users\\jorda\\source\\repos\\cst116-lab9-JordanHT-OIT\\CST116F2021-Lab9\\1114_4_datafile.txt"; //Hardcoded file path because flexibility was not required string mainData[4][MV_3]; if (!populateDataArray(fileLoc, mainData, numEntries)) @@ -222,7 +226,7 @@ int main(void) cout << "Invalid input; enter again: "; } - if (menuChoice == 1) + if (menuChoice == 1) //Direct index imput { cout << "Enter index: "; @@ -231,12 +235,12 @@ int main(void) cout << "Invalid index"; } } - else + else //Lookup if the user does not know the index of the entry { select = findPerson(mainData, numEntries); } - do + do //Let the user change any amount of params until they exit { cout << "Select element to change:\n1)\tFirst name\n2)\tLast name\n3)\tPhone number\n4)\tDate of birth\n5)\tExit\n"; @@ -278,25 +282,25 @@ int main(void) } while (menuChoice != 5); - menuChoice = -1; + menuChoice = -1; //Reset menu value to avoid program exit break; - case(4): //Displays all available information + case(4): //Displays all available information using metaData as a map + cout << left; + cout << endl << setw(25) << "First name" << setw(25) << "Last name" << setw(25) << "Phone number" << setw(25) << "Date of birth" << endl; + for (int idx = 0; idx < (25 * 4); idx++) + { + cout << char(205); + } cout << endl; for (int idx = 0; idx <= numEntries; idx++) { - for (int idy = 0; idy <= numEntries; idy++) - { - if (metaData[0][idy] == idx) - { - displayEntry(mainData, idy); + displayEntry(mainData, metaData[0][idx]); - cout << endl; - } - } + cout << endl; } cout << endl; @@ -349,7 +353,7 @@ void bubiSortIndex(int map[MV_3], int dataArray[MV_3], int len) } } -//Swaps the dataArray using a map for a specified number of entries (unused) +//Swaps the dataArray using a map for a specified number of entries (UNUSED) void swapDataArray(string dataArray[4][MV_3], int meta[MV_3], int &entries) { string swapValue[4]; @@ -504,4 +508,4 @@ void displayEntry(string dataArray[4][MV_3], int entry) { cout << left; cout << setw(25) << dataArray[0][entry] << setw(25) << dataArray[1][entry] << setw(25) << dataArray[2][entry] << setw(25) << dataArray[3][entry]; -}
\ No newline at end of file +} |