diff options
| author | BensProgramma <[email protected]> | 2021-12-07 15:10:17 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-07 15:10:17 -0800 |
| commit | 2848fb6be02d8235583dce48b8b202aef73ce033 (patch) | |
| tree | a4120ae59965bb0fc751710ce2cfb8152a99fe13 | |
| parent | Update CST116F2021-Lab9_Schroeder.cpp (diff) | |
| download | cst116-lab9-bensprogramma-2848fb6be02d8235583dce48b8b202aef73ce033.tar.xz cst116-lab9-bensprogramma-2848fb6be02d8235583dce48b8b202aef73ce033.zip | |
Final Update
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp index 6aac72e..0ac4b01 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp @@ -86,6 +86,7 @@ int main() + // /// 11.14 Programming Exercises pp 337 - 338 #4 /////////////////////////////////////////////////////////////////////// #include <iostream> #include <fstream> @@ -123,6 +124,7 @@ int main() >> bd[num_records]; num_records++; } + fin.close(); DisplayMenu(); @@ -144,36 +146,35 @@ void DisplayMenu() switch (menuChoice) { - case 1: - { - Find(); - break; - } - case 2: - { - Add(); - break; - } - case 3: - { - Edit(); - break; - } - case 4: - { - Display(); - break; - } - case 5: - { - Update(); - cout << "\tThank you, Goodbye!"; - break; - } + case 1: + { + Find(); + break; + } + case 2: + { + Add(); + break; + } + case 3: + { + Edit(); + break; + } + case 4: + { + Display(); + break; + } + case 5: + { + Update(); + cout << "\tThank you, Goodbye!"; + break; + } } } - void Find() { string temp = " "; @@ -199,8 +200,6 @@ void Find() } - - void Add() { cout << "Last Name: "; @@ -212,17 +211,16 @@ void Add() cout << "Date Of Birth: "; cin >> bd[num_records]; num_records++; - + cout << "\n\n"; DisplayMenu(); - } void Edit() { Sort(); - cout << "\nAll of the current records:\n"; + cout << "\nAll of the current records:\n"; for (int k = 0; k <= num_records - 1; k++) { cout << k + 1 << ".\t" << first[k] << " " << last[k] << "\t\tph: " << ph[k] << "\tDOB: " << bd[k] << "\n"; @@ -245,13 +243,13 @@ void Edit() void Display() -{ +{ Sort(); - + cout << "\nAll of the current records:\n"; //sorted alphabetically by last name - for (int k = 0; k <= num_records - 1; k++) + for (int k=0;k<=num_records-1;k++) { - cout << k + 1 << ".\t" << first[k] << " " << last[k] << "\t\tph: " << ph[k] << "\tDOB: " << bd[k] << "\n"; + cout << k + 1 << ".\t" << first[k]<<" "<< last[k]<<"\t\tph: "<<ph[k]<<"\tDOB: "<<bd[k]<<"\n"; } cout << "\n\n"; @@ -272,8 +270,9 @@ void Sort() { swapped = false; j++; - for (int i = 0; i < num_records - 1; i++) + for (int i = 0; i < num_records-1; i++) { + //if (last[i]!=null) if (last[i] > (last[i + 1])) { tmp1 = last[i]; tmp2 = first[i]; tmp3 = ph[i]; tmp4 = bd[i]; @@ -291,12 +290,11 @@ void Update() Sort(); 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"; - + for (int i = 0; i <=num_records-2; i++) + fout << first[i] << " " << last[i] << " " << ph[i] <<" "<< bd[i] << endl; + //fout << first[i] << "\n" << last[i] << "\n" << ph[i] << "\n" << bd[i] << "\n"; + fout << first[num_records-1] << " " << last[num_records - 1] << " " << ph[num_records - 1] << " " << bd[num_records - 1]; fout.close(); - } |