diff options
| author | JordanHT-OIT <[email protected]> | 2021-12-06 01:24:26 -0800 |
|---|---|---|
| committer | JordanHT-OIT <[email protected]> | 2021-12-06 01:24:26 -0800 |
| commit | 6fbcb8bd166bf9b7834bb3d6f57e68ef2892c7d6 (patch) | |
| tree | 0972b127a1d6b447f344f57a0d8dfaac1ca11b85 | |
| parent | Temporary commit to save progress (diff) | |
| download | cst116-lab9-jordanht-oit-6fbcb8bd166bf9b7834bb3d6f57e68ef2892c7d6.tar.xz cst116-lab9-jordanht-oit-6fbcb8bd166bf9b7834bb3d6f57e68ef2892c7d6.zip | |
Intermediate push to save progress
| -rw-r--r-- | CST116F2021-Lab9/1114_4_datafile.txt | 15 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 259 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj | 1 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters | 1 |
4 files changed, 276 insertions, 0 deletions
diff --git a/CST116F2021-Lab9/1114_4_datafile.txt b/CST116F2021-Lab9/1114_4_datafile.txt new file mode 100644 index 0000000..4db53f4 --- /dev/null +++ b/CST116F2021-Lab9/1114_4_datafile.txt @@ -0,0 +1,15 @@ +Romany Porter 225-261-7520 1966-05-20 +Julia Galloway 931-729-9938 1999-06-18 +Paisley Mccall 207-865-4000 1970-03-01 +Kaidan Smith 423-842-7402 1987-04-24 +Odin Obrien 321-783-2687 1983-01-19 +Aarav Corbett 586-468-0823 1991-12-14 +Benjamin Bullock 870-533-4082 1985-11-09 +Aniyah Davey 620-947-3956 2001-03-08 +Inigo Massey 253-835-0873 1983-09-28 +Dionne Arroyo 717-417-5576 1998-02-19 +Codey Whyte 615-672-4849 1990-06-10 +Ray Mccartney 425-788-2340 2002-09-03 +Jannat Kline 706-820-0848 1994-04-01 +Aaliyah Pittman 979-258-9565 1980-12-26 +Brady Merritt 871-869-7911 1993-09-13
\ No newline at end of file diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp index 259721c..1f32820 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9.cpp @@ -5,10 +5,12 @@ #include <string> #include <fstream> #include <iomanip> +#include <limits> using namespace std; #define MV_1 10 +#define MV_3 30 //16a - 11.14 Programming Exercises #2: /* @@ -136,3 +138,260 @@ int main(void) //16a - 11.14 Programming Exercises #4: +//Known issue: The code only indexes by the fist letter of the last names, so within the names of the same fist letter, their order will be as entered. + +bool getInt(int&); +int indexFistChar(string); +void bubiSortIndex(int[MV_3], int[MV_3], int); +void swapDataArray(string[4][MV_3], int[MV_3], int&); +void populateMetaData(int[2][MV_3], string[4][MV_3], int); +bool populateDataArray(string, string[4][MV_3], int&); +int findPerson(string[4][MV_3], int); +void displayEntry(string[4][MV_3], int); + +int main(void) +{ + int menuChoice = 0, numEntries = 0, metaData[2][MV_3]{ 0 }; + string fileLoc = "C:\\Users\\jorda\\source\\repos\\cst116-lab9-JordanHT-OIT\\CST116F2021-Lab9\\1114_4_datafile.txt"; + string mainData[4][MV_3]; + + if (!populateDataArray(fileLoc, mainData, numEntries)) + { + return (1); + } + + populateMetaData(metaData, mainData, numEntries); //Make fist map + bubiSortIndex(metaData[0], metaData[1], numEntries); + + 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; + + + while (!getInt(menuChoice) || (menuChoice > 5) || (menuChoice < 1)) //Get menu choice from user + { + cout << "Invalid input; enter again: "; + } + + switch (menuChoice) + { + case(1): //Find personnel infomation by first name and last name, or by phone number + + + + break; + + case(2): //Add a person to the database + + + + break; + + case(3): //Edit personnel infomation. Uses same logic as case 1 to find the entry to edit + + + + break; + + case(4): //Displays all available information + + + + break; + } + + populateMetaData(metaData, mainData, numEntries); //Regenerate map + bubiSortIndex(metaData[0], metaData[1], numEntries); + + } + while (menuChoice != 5); + + return (0); +} + +//Returns the ASCII value for the fist char (always as uperace) in the input string +int indexFistChar(string inputString) +{ + inputString[0] = toupper(inputString[0]); //Ensure the fist char of the string is uppercase + + return((int)inputString[0]); +} + +//Sorts an input array and creates a map of the changes (swap locations) for len number of entries +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++) + { + if (dataArray[idx] > dataArray[idx + 1]) + { + hold = dataArray[idx + 1]; + dataArray[idx + 1] = dataArray[idx]; + dataArray[idx] = hold; + + map[idx] = map[idx + 1]; + + pass = 0; + } + else + { + pass++; + } + } + } +} + +//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]; + + for (int idx = 0; idx < entries; idx++) + { + if(meta[idx] > 0) + { + for (int idy = 0; idy < 4; idy++) + { + swapValue[idy] = dataArray[idy][idx]; + + dataArray[idy][idx] = dataArray[idy][meta[idx]]; + + dataArray[idy][meta[idx]] = swapValue[idy]; + } + } + } +} + +//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++) + { + meta[0][idx] = idx; + meta[1][idx] = indexFistChar(dataAray[1][idx]); + } +} + +//Opens a file at the provied path, the enters its contents into an array. Returns false if there is an I/O error. +bool populateDataArray(string fileLoc, string dataArray[4][MV_3], int &numEntries) +{ + ifstream inputFile; + bool isFileOpen = false; + int index = 0; + + inputFile.open(fileLoc); //Open datafile and check if opening was successful. If not, diplay error and exit + isFileOpen = !inputFile.fail(); + + if (!isFileOpen) + { + cout << "File read error: Cannot open" << endl; + return (isFileOpen); + } + else + { + isFileOpen = true; + } + + inputFile >> dataArray[0][index] >> dataArray[1][index] >> dataArray[2][index] >> dataArray[3][index]; //Priming read + numEntries = 1; + + while (!inputFile.eof()) + { + index++; + inputFile >> dataArray[0][index] >> dataArray[1][index] >> dataArray[2][index] >> dataArray[3][index]; + numEntries++; + } + + inputFile.close(); + + return (isFileOpen); +} + +//Gets input from user. Returns false and sets input to 0 if entry is not an int. +bool getInt(int& innum) +{ + bool valid = true; + + cin >> innum; + + if (!cin.good()) + { + cin.clear(); + cin.ignore(numeric_limits<streamsize>::max(), '\n'); + + valid = false; + innum = 0; + } + + return valid; +} + +//Find personnel infomation by first name and last name, or by phone number. Returns array location of match (-1 if no match) +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"; + + while (!getInt(menuVal) || (menuVal > 3) || (menuVal < 1)) + { + cout << "Invalid input; enter again: "; + } + + switch (menuVal) + { + case (1): + + cout << "Enter the first name (case sensitive): "; + cin >> first; + + cout << "Enter the last name (case sensitive): "; + cin >> last; + + for (int idx = 0; idx < entries; idx++) + { + if (first == dataArray[0][idx]) + { + if (last == dataArray[1][idx]) + { + return (idx); + } + } + } + + cout << "Person not found"; + + break; + + case (2): + + cout << "Enter the phone number in the format 012-345-6789: "; + cin >> first; + + for (int idx = 0; idx < entries; idx++) + { + if (first == dataArray[2][idx]) + { + return (idx); + } + } + + cout << "Person not found"; + + break; + } + + return (-1); +} + +//Displays information about selected person +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 diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj index 01f000d..a1a93b0 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj @@ -144,6 +144,7 @@ <ItemGroup> <Text Include="1114_2_datafile.txt" /> <Text Include="1114_3_datafile.txt" /> + <Text Include="1114_4_datafile.txt" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters index 979188d..2f9f8f6 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters @@ -22,5 +22,6 @@ <ItemGroup> <Text Include="1114_2_datafile.txt" /> <Text Include="1114_3_datafile.txt" /> + <Text Include="1114_4_datafile.txt" /> </ItemGroup> </Project>
\ No newline at end of file |