aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortylr <[email protected]>2021-12-07 16:16:46 -0800
committertylr <[email protected]>2021-12-07 16:16:46 -0800
commit35e95316a1f10473016491cd1f85ce4786579931 (patch)
treeb905669e478a2c9bf4e76858223e52ec6f72703c
parentEverything working but editing database. (diff)
downloadcst116-lab9-till-t-35e95316a1f10473016491cd1f85ce4786579931.tar.xz
cst116-lab9-till-t-35e95316a1f10473016491cd1f85ce4786579931.zip
Completed Num4.
-rwxr-xr-xnum4/a.outbin98562 -> 99362 bytes
-rw-r--r--num4/data.txt18
-rw-r--r--num4/main.cpp190
3 files changed, 148 insertions, 60 deletions
diff --git a/num4/a.out b/num4/a.out
index 4e00763..889b6b0 100755
--- a/num4/a.out
+++ b/num4/a.out
Binary files differ
diff --git a/num4/data.txt b/num4/data.txt
index 7e6bb63..9c7da2a 100644
--- a/num4/data.txt
+++ b/num4/data.txt
@@ -1,10 +1,10 @@
-mark anthony 234-234-2344 23-23-2333
-mark applewood 234-234-2344 23.23.2333
-helena boom 234-234-2344 23/23/2332
-bobby filet 1112223333 22-22-2222
-taury hlinka 714-474-6185 07/21/1995
-tyler taormina 714-808-2056 05/17/1994
-ryan taormina 714-555-5555 03/31/1996
+benny applewood 02/29/1999 03/02/1933
+bobby filet 503-903-3322 02/23/1902
+big lebowski 867-5309 02/14/1902
+marky mark 503-334-9082 05/21/1994
+tom ram 903-332-2342 03/23/1889
mark wallace 234-234-2344 23/23/2333
-mark washington 833-234-4321 23/23/2111
-ryan zebra 712-323-2332 02/33/2355
+will washington 833-234-4321 23/23/2111
+oliver wood 503-203-4033 03/30/2000
+jon zebra 712-323-2332 05/22/1909
+helena zoom 234-234-2344 23/23/2002
diff --git a/num4/main.cpp b/num4/main.cpp
index 0ce7c61..1bb0616 100644
--- a/num4/main.cpp
+++ b/num4/main.cpp
@@ -11,15 +11,23 @@
#include <string>
using namespace std;
-const int MAX = 10;
+const int MAX = 20;
void RmString(string arr[], int);
void ClearBuffer();
void DisplayMenu(int&);
-void ProcessMenuChoice (int&, int&, int&, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX]);
+void ProcessMenuChoice (int&, int&, int&, int&, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX]);
+void DisplayEditMenu(int&);
+void FindIndex(int& index, int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
+
+void ProcessEditChoice (int edit_choice, int index, int& check, int record_counter, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX]);
+
+void Edit(int index, int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
void FindName(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
+
void SortData(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
+
void AddPerson(int, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
void PrintData(int, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]);
void FindString (string first[], string last[], string phone[], string bday[], int);
@@ -38,6 +46,7 @@ int main()
int record_counter = 0;
int menu_choice;
int flag = 1;
+ int index_flag;
ifstream inFile;
@@ -63,7 +72,7 @@ int main()
while (flag != 0)
{
DisplayMenu(menu_choice);
- ProcessMenuChoice(menu_choice, flag, record_counter, f_name, l_name, phone, bday);
+ ProcessMenuChoice(menu_choice, flag, record_counter, index_flag, f_name, l_name, phone, bday);
SortData(record_counter, f_name, l_name, phone, bday);
ClearBuffer();
}
@@ -88,7 +97,6 @@ int main()
void SortData(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX])
{
int i, j, k;
- int flag = 0;
string temp_first;
string temp_last;
string temp_phone;
@@ -150,6 +158,52 @@ int ReadData ( ifstream & inFile, string first[MAX], string last[MAX], string ph
}
+void FindIndex(int& index, int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX])
+{
+ // Check for a substring inside of one of the input strings.
+ // Prints whether or not the string was found. If found
+ // prints the index of the list where the string was found
+ // and what the string was that contained the substring.
+
+ string search;
+ int flag = 0;
+ int left = 0;
+ int right = record_counter;
+ int mid;
+
+ cout << "Enter the last name of the person you wish to find: ";
+ getline(cin, search);
+
+ transform(search.begin(), search.end(), search.begin(), ::tolower);
+
+ while (left <= right && flag == 0)
+ {
+ mid = (left + right) / 2;
+
+ if (search == last[mid])
+ {
+ cout << "WE FOUND IT!" << endl;
+ cout << first[mid] << " " << last[mid] << " " << phone[mid] << " " << bday[mid] << endl;
+ index = mid;
+ flag = 1;
+ }
+
+ else if(search > last[mid])
+ {
+ left = mid + 1;
+ }
+
+ else
+ {
+ right = mid - 1;
+ }
+ }
+
+ if (flag == 0)
+ cout << "The last name you entered doesn't exist in our database. Please check spelling and try again." << endl;
+
+}
+
void FindName(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX])
{
// Check for a substring inside of one of the input strings.
@@ -191,8 +245,7 @@ void FindName(int record_counter, string first[MAX], string last[MAX], string ph
}
if (flag == 0)
- cout << "Man, we ain't found shit." << endl;
- /* cout << "The name you entered doesn't exist in our database. Please check spelling and try again." << endl; */
+ cout << "The name you entered doesn't exist in our database. Please check spelling and try again." << endl;
}
@@ -231,49 +284,83 @@ void AddPerson(int record_counter, string first[MAX], string last[MAX], string p
bday[i] = temp;
}
-/* void RmString(string arr[], int limit) */
-/* { */
-/* // Finds string within array and removes the element. */
-/* // May need to use vector. */
-/* int i = 0, j = 0, k = 0; */
-/* int choice; */
-/* string deleted; */
-/* string copy[max]; */
-
-/* cout << "What data entry would you like to delete..." << endl; */
-/* PrintString(limit, arr); */
-/* cout << "Please enter the number for the string that you'd like to delte: " << endl; */
-/* cin >> choice; */
-/* choice -= 1; */
-/* cout << "Working...\n\n" << endl; */
-
-/* for (j = 0 ; j < limit + 1; j++) */
-/* { */
-/* if (k == choice) { */
-/* cout << "Deleting...\n\n" << endl; */
-/* deleted = arr[k]; */
-/* k++; */
-/* j--; */
-
-/* } */
-/* else { */
-/* copy[j] = arr[k]; */
-/* k++; */
-/* } */
-/* } */
-
-/* cout << "==================================================================\n"; */
-/* cout << "Here is our updated database..." << endl; */
-/* cout << "==================================================================\n"; */
-
-/* while (i < (limit - 1)) */
-/* { */
-/* cout << i+1 << ") " << copy[i] << endl; */
-/* i++; */
-/* } */
-
-/* cout << "We removed: " << deleted << endl; */
-/* } */
+
+void Edit(int index, int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX])
+{
+ int edit_choice;
+ int check = 1;
+ while (check != 0)
+ {
+ DisplayEditMenu(edit_choice);
+ ProcessEditChoice(edit_choice, index, check, record_counter, first, last, phone, bday);
+ }
+}
+
+
+void DisplayEditMenu(int& edit_choice)
+{
+ //Displays the menu of functions for the user to choose from.
+ edit_choice = 0;
+ cout << "==================================================================\n";
+ cout << " MENU" << endl;
+ cout << "==================================================================\n";
+
+ cout << "1) Edit First Name.\n";
+ cout << "2) Edit Last Name.\n";
+ cout << "3) Edit Phone Number.\n";
+ cout << "4) Edit Birth Date.\n";
+ cout << "Enter: ";
+ cin >> edit_choice;
+ if (edit_choice > 4 || edit_choice < 1)
+ {
+ cout << "Invalid Entry. Please enter a number from the options list provided.\n\n\n\n" << endl;
+ DisplayMenu(edit_choice);
+ }
+}
+
+
+void ProcessEditChoice (int edit_choice, int index, int& check, int record_counter, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX])
+{
+ //Takes in user input for menu choice and calls the appropriate function.
+ string temp;
+ ClearBuffer();
+ switch(edit_choice)
+ {
+ case 1:
+ cout << "Enter the updated First name: ";
+ cin >> temp;
+ first[index] = temp;
+ break;
+
+ case 2:
+ cout << "Enter the updated Last name: ";
+ cin >> temp;
+ last[index] = temp;
+ SortData(record_counter, f_name, l_name, phone, bday);
+ break;
+
+ case 3:
+ cout << "Enter the updated Phone Number: ";
+ cin >> temp;
+ phone[index] = temp;
+ break;
+
+
+ case 4:
+ cout << "Enter the updated Birthday: ";
+ cin >> temp;
+ bday[index] = temp;
+
+ break;
+
+
+ default:
+ break;
+ }
+ cout << "Enter 0 to end editing.\n" << endl;
+ cout << "Enter any other number to continue editing.\n" << endl;
+ cin >> check;
+}
void DisplayMenu(int& menu_choice)
@@ -299,7 +386,7 @@ void DisplayMenu(int& menu_choice)
}
-void ProcessMenuChoice (int& menu_choice, int& flag, int& record_counter, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX])
+void ProcessMenuChoice (int& menu_choice, int& flag, int& record_counter, int& index, std::string first[MAX], std::string last[MAX], std::string phone[MAX], std::string bday[MAX])
{
//Takes in user input for menu choice and calls the appropriate function.
ClearBuffer();
@@ -317,7 +404,8 @@ void ProcessMenuChoice (int& menu_choice, int& flag, int& record_counter, std::
break;
case 3:
- //Edit information for a certain person
+ FindIndex(index, record_counter, first, last, phone, bday);
+ Edit(index, record_counter, first, last, phone, bday);
break;