diff options
| author | BensProgramma <[email protected]> | 2021-12-06 14:23:04 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-06 14:23:04 -0800 |
| commit | cdba5042cfaded9f2aeb28059fd3802ad4e87ff7 (patch) | |
| tree | cfbea2b2cf00df7783380f0d59aae3c09c31cf25 | |
| parent | Push with txt files (diff) | |
| download | cst116-lab9-bensprogramma-cdba5042cfaded9f2aeb28059fd3802ad4e87ff7.tar.xz cst116-lab9-bensprogramma-cdba5042cfaded9f2aeb28059fd3802ad4e87ff7.zip | |
Update CST116F2021-Lab9_Schroeder.cpp
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp index e90e0b7..37a80ee 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp @@ -114,7 +114,7 @@ void Update(); int main() { // READ THE FILE IN - fin.open("INFO2.txt"); + fin.open("INFO.txt"); while (fin && !fin.eof()) { fin >> first[num_records] @@ -173,12 +173,54 @@ void DisplayMenu() } } + void Find() + { + /*int SearchBy = 0; + cout << "1) Last Name: "; + cout << "2) First Name: "; + cout << "3) ph #: "; + cout << "4) Date Of Birth: "; + cout << "Which field would you like to search by? (Enter a # 1 thru 4)"; + cin >> SearchBy;*/ + + Sort(); + string subString = ""; + + cout << "Enter the Last Name of the person whose account you wish to see:"; + cin >> subString; + + bool found = false; + int left = 0; + int right = num_records; + int mid = 0; + + while (left <= right && found != true) + { + int mid = (left + right / 2); + + if (subString == last[mid]) + { + cout << "found: " << first[mid] << " " << last[mid] << "\t\tph: " << ph[mid] << "\tDOB: " << bd[mid] << "\n\n\n"; + found = true; + } + else if (subString > last[mid]) + left = mid + 1; + else + right = mid - 1; + + } + + if (found != true) + cout << "The account was not found.\n\n"; + + DisplayMenu(); } + void Add() { cout << "Last Name: "; @@ -268,7 +310,7 @@ void Update() { Sort(); - fout.open("INFO2.txt"); + fout.open("INFO.txt"); for (int i = 0; i <= num_records - 1; i++) fout << first[i] << " " << last[i] << " " << ph[i] << " " << bd[i] << endl; //fout << first[i] << "\n" << last[i] << "\n" << ph[i] << "\n" << bd[i] << "\n"; |