diff options
| author | JordanHT-OIT <[email protected]> | 2021-12-06 17:24:58 -0800 |
|---|---|---|
| committer | JordanHT-OIT <[email protected]> | 2021-12-06 17:24:58 -0800 |
| commit | 56aa3924706d82ffb25ce74dcec45bf0236e6645 (patch) | |
| tree | f5c62297d959e1bc5af3556adae997204a08bae6 | |
| parent | Intermediate push to save progress (diff) | |
| download | cst116-lab9-jordanht-oit-56aa3924706d82ffb25ce74dcec45bf0236e6645.tar.xz cst116-lab9-jordanht-oit-56aa3924706d82ffb25ce74dcec45bf0236e6645.zip | |
Temporary commint to save progress
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 126 |
1 files changed, 118 insertions, 8 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp index 1f32820..1372506 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9.cpp @@ -151,7 +151,7 @@ void displayEntry(string[4][MV_3], int); int main(void) { - int menuChoice = 0, numEntries = 0, metaData[2][MV_3]{ 0 }; + 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 mainData[4][MV_3]; @@ -163,9 +163,10 @@ int main(void) populateMetaData(metaData, mainData, numEntries); //Make fist map bubiSortIndex(metaData[0], metaData[1], numEntries); + cout << "Personnel manifest explorer MK1" << endl; + do { - cout << "Personnel manifest explorer MK1" << endl; cout << "Enter desired operation:\n" << "1)\tPersonnel lookup\n" << "2)\tAdd entry\n" << "3)\tEdit entry\n" << "4)\tDisplay all records\n" << "5)\tExit program" << endl; @@ -179,25 +180,126 @@ int main(void) { case(1): //Find personnel infomation by first name and last name, or by phone number + select = findPerson(mainData, numEntries); + + cout << endl; + if (select < 0) //Break out if a match was not found or the user quit + { + break; + } + + displayEntry(mainData, select); + + cout << endl << endl; break; case(2): //Add a person to the database + cout << "Enter the first name: "; + cin >> mainData[0][++numEntries]; + + cout << "Enter the last name: "; + cin >> mainData[1][numEntries]; + cout << "Enter the phone number (format: 012-345-6789): "; + cin >> mainData[2][numEntries]; + + cout << "Enter the date of birth (format: yyyy-mm-dd): "; + cin >> mainData[3][numEntries]; + + cout << endl; break; case(3): //Edit personnel infomation. Uses same logic as case 1 to find the entry to edit + cout << "Enter 1 if index is known, or 2 to find a person: "; + + while (!getInt(menuChoice) || (menuChoice > 2) || (menuChoice < 1)) + { + cout << "Invalid input; enter again: "; + } + + if (menuChoice == 1) + { + cout << "Enter index: "; + + if (!getInt(select)) + { + cout << "Invalid index"; + } + } + else + { + select = findPerson(mainData, numEntries); + } + + do + { + cout << "Select element to change:\n1)\tFirst name\n2)\tLast name\n3)\tPhone number\n4)\tDate of birth\n5)\tExit\n"; + + while (!getInt(menuChoice) || (menuChoice > 5) || (menuChoice < 1)) + { + cout << "Invalid input; enter again: "; + } + + switch (menuChoice) + { + case(1): + + cout << "Enter the first name: "; + cin >> mainData[0][select]; + + break; + + case(2): + + cout << "Enter the last name: "; + cin >> mainData[1][select]; + + break; + + case(3): + + cout << "Enter the phone number (format: 012-345-6789): "; + cin >> mainData[2][select]; + + break; + + case(4): + + cout << "Enter the date of birth (format: yyyy-mm-dd): "; + cin >> mainData[3][select]; + + break; + } + } + while (menuChoice != 5); + menuChoice = -1; break; case(4): //Displays all available information + cout << endl; + for (int idx = 0; idx <= numEntries; idx++) + { + for (int idy = 0; idy <= numEntries; idy++) + { + if (metaData[0][idy] == idx) + { + displayEntry(mainData, idy); + + cout << endl; + } + } + } + + cout << endl; break; } @@ -225,7 +327,7 @@ void bubiSortIndex(int map[MV_3], int dataArray[MV_3], int len) int pass = 0, hold = 0; while (pass <= len) { - for (int idx = 0; idx < (len - 1); idx++) + for (int idx = 0; idx < (len); idx++) { if (dataArray[idx] > dataArray[idx + 1]) { @@ -233,7 +335,9 @@ void bubiSortIndex(int map[MV_3], int dataArray[MV_3], int len) dataArray[idx + 1] = dataArray[idx]; dataArray[idx] = hold; - map[idx] = map[idx + 1]; + hold = map[idx + 1]; + map[idx + 1] = map[idx]; + map[idx] = hold; pass = 0; } @@ -269,7 +373,7 @@ void swapDataArray(string dataArray[4][MV_3], int meta[MV_3], int &entries) //Fills a metadata array with relevant data void populateMetaData(int meta[2][MV_3], string dataAray[4][MV_3], int entries) { - for (int idx = 0; idx < entries; idx++) + for (int idx = 0; idx <= entries; idx++) { meta[0][idx] = idx; meta[1][idx] = indexFistChar(dataAray[1][idx]); @@ -306,6 +410,8 @@ bool populateDataArray(string fileLoc, string dataArray[4][MV_3], int &numEntrie numEntries++; } + numEntries--; + inputFile.close(); return (isFileOpen); @@ -336,7 +442,7 @@ int findPerson(string dataArray[4][MV_3], int entries) int menuVal = 0; string first, last; - cout << "Chose search method: \n1)\tFirst name and last name\n2)\tPhone number\n3)\tCancel"; + cout << "Chose search method: \n1)\tFirst name and last name\n2)\tPhone number\n3)\tCancel" << endl; while (!getInt(menuVal) || (menuVal > 3) || (menuVal < 1)) { @@ -353,12 +459,14 @@ int findPerson(string dataArray[4][MV_3], int entries) cout << "Enter the last name (case sensitive): "; cin >> last; - for (int idx = 0; idx < entries; idx++) + for (int idx = 0; idx <= entries; idx++) { if (first == dataArray[0][idx]) { if (last == dataArray[1][idx]) { + cout << "Match found at index " << idx << ":"; + return (idx); } } @@ -373,10 +481,12 @@ int findPerson(string dataArray[4][MV_3], int entries) cout << "Enter the phone number in the format 012-345-6789: "; cin >> first; - for (int idx = 0; idx < entries; idx++) + for (int idx = 0; idx <= entries; idx++) { if (first == dataArray[2][idx]) { + cout << "Match found at index " << idx << ":"; + return (idx); } } |