diff options
| author | tylr <[email protected]> | 2021-12-07 00:47:03 -0800 |
|---|---|---|
| committer | tylr <[email protected]> | 2021-12-07 00:47:03 -0800 |
| commit | fb289cc22036eec4aff473ef39441c2194def6ad (patch) | |
| tree | 0e3ef99fc937f9e27446fddf459eb608dd8a637d | |
| parent | Num 4 in progress. (diff) | |
| download | cst116-lab9-till-t-fb289cc22036eec4aff473ef39441c2194def6ad.tar.xz cst116-lab9-till-t-fb289cc22036eec4aff473ef39441c2194def6ad.zip | |
Everything working but editing database.
| -rw-r--r-- | num2/num2.cpp | 1 | ||||
| -rwxr-xr-x | num4/a.out | bin | 77314 -> 98562 bytes | |||
| -rw-r--r-- | num4/data.txt | 9 | ||||
| -rw-r--r-- | num4/main.cpp | 167 |
4 files changed, 124 insertions, 53 deletions
diff --git a/num2/num2.cpp b/num2/num2.cpp index 274acac..8b12e96 100644 --- a/num2/num2.cpp +++ b/num2/num2.cpp @@ -80,7 +80,6 @@ int main() } return 0; - } diff --git a/num4/data.txt b/num4/data.txt index 157d902..7e6bb63 100644 --- a/num4/data.txt +++ b/num4/data.txt @@ -1,3 +1,10 @@ -tyler taormina 714-808-2056 05/17/1994 +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 +mark wallace 234-234-2344 23/23/2333 +mark washington 833-234-4321 23/23/2111 +ryan zebra 712-323-2332 02/33/2355 diff --git a/num4/main.cpp b/num4/main.cpp index 00b63bc..0ce7c61 100644 --- a/num4/main.cpp +++ b/num4/main.cpp @@ -18,6 +18,8 @@ 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 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); @@ -25,14 +27,14 @@ int ReadData (ifstream & inFile, std::string first[MAX], std::string last[MAX], void OutData(ofstream & outFile, string first[], string last[], string phone[], string bday[], int record_counter ); -int main() -{ - std::string f_name[MAX]; - std::string l_name[MAX]; - std::string phone[MAX]; - std::string bday[MAX]; +std::string f_name[MAX]; +std::string l_name[MAX]; +std::string phone[MAX]; +std::string bday[MAX]; +int main() +{ int record_counter = 0; int menu_choice; int flag = 1; @@ -56,10 +58,14 @@ int main() } //User interacts with program here. + + SortData(record_counter, f_name, l_name, phone, bday); while (flag != 0) { DisplayMenu(menu_choice); ProcessMenuChoice(menu_choice, flag, record_counter, f_name, l_name, phone, bday); + SortData(record_counter, f_name, l_name, phone, bday); + ClearBuffer(); } //Writes changes to the data.txt file ofstream outFile ( "data.txt" ); @@ -79,6 +85,57 @@ 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; + string temp_bday; + + for (i = 0; i < record_counter - 1; i++) + { + transform(last[i].begin(), last[i].end(), last[i].begin(), ::tolower); + transform(first[i].begin(), first[i].end(), first[i].begin(), ::tolower); + + for (j = i + 1; j < record_counter; j++) + { + transform(first[j].begin(), first[j].end(), first[j].begin(), ::tolower); + + for (k = 0; k < last[i].length(); k++) + { + if (last[i][k] > last[j][k]) + { + temp_last = last[j]; + last[j] = last[i]; + last[i] = temp_last; + + temp_first = first[j]; + first[j] = first[i]; + first[i] = temp_first; + + temp_phone = phone[j]; + phone[j] = phone[i]; + phone[i] = temp_phone; + + temp_bday = bday[j]; + bday[j] = bday[i]; + bday[i] = temp_bday; + + k = last[i].length(); + } + + else if (last[i][k] < last[j][k]) + { + k = last[i].length(); + } + } + } + } +} + + int ReadData ( ifstream & inFile, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]) { int counter = 0; @@ -89,49 +146,55 @@ int ReadData ( ifstream & inFile, string first[MAX], string last[MAX], string ph counter++; inFile >> first[counter] >> last[counter] >> phone[counter] >> bday[counter]; } - return counter; } -/* void FindString(string first[], int limit) */ -/* { */ -/* // 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 sub; */ -/* int i, j; */ -/* int reset = 0; */ -/* ClearBuffer(); */ - -/* cout << "Lets look for a substring..." << endl; */ -/* cout << "Please enter a substring to look for: \n" << endl; */ -/* getline(cin, sub); */ - -/* for (i = 0; i < limit; i++) { */ -/* if (arr[i].size() < sub.size()) */ -/* i = limit; */ -/* for (j = 0; j < arr[i].size(); j++) { */ -/* int k = 0; */ -/* if (arr[i][j] == sub[k]) { */ -/* reset = j; */ -/* while (arr[i][j] == sub[k] && k < sub.size()) { */ -/* j++; */ -/* k++; */ -/* } */ - -/* if (k == sub.size()){ */ -/* cout << "We found it at index: " << i+1 << endl; */ -/* cout << "The string was: " << arr[i] << endl; */ -/* } */ -/* else */ -/* j = reset; */ -/* } */ -/* } */ -/* } */ -/* } */ +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. + // 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; + flag = 1; + } + + else if(search > last[mid]) + { + left = mid + 1; + } + + else + { + right = mid - 1; + } + } + + 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; */ + +} void PrintData(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]) @@ -145,26 +208,27 @@ void PrintData(int record_counter, string first[MAX], string last[MAX], string p while (i < record_counter) { cout << i+1 << ") " << first[i] << " " << last[i] << " " << phone[i] << " " << bday[i] << endl; - i += 1; + i++; } } void AddPerson(int record_counter, string first[MAX], string last[MAX], string phone[MAX], string bday[MAX]) { + int i = record_counter - 1; std::string temp; cout << "Enter the first name of the person you'd like to add: " << endl; cin >> temp; - first[record_counter] = temp; + first[i] = temp; cout << "Enter the last name of the person you'd like to add: " << endl; cin >> temp; - last[record_counter] = temp; + last[i] = temp; cout << "Enter the phone number of the person you'd like to add: " << endl; cin >> temp; - phone[record_counter] = temp; + phone[i] = temp; cout << "Enter the birthday of the person you'd like to add: " << endl; cin >> temp; - bday[record_counter] = temp; + bday[i] = temp; } /* void RmString(string arr[], int limit) */ @@ -243,12 +307,13 @@ void ProcessMenuChoice (int& menu_choice, int& flag, int& record_counter, std:: switch(menu_choice) { case 1: - // FindString(FNAME, LNAME, PHONE, BDAY, limit); + FindName(record_counter, first, last, phone, bday); break; case 2: record_counter++; AddPerson(record_counter, first, last, phone, bday); + SortData(record_counter, first, last, phone, bday); break; case 3: |