diff options
| author | Benjamin Schroeder <[email protected]> | 2021-12-03 16:58:12 -0800 |
|---|---|---|
| committer | Benjamin Schroeder <[email protected]> | 2021-12-03 16:58:12 -0800 |
| commit | 41d31d37ee78cb4f1b6f993eb137e56b86b3e77b (patch) | |
| tree | b95c81f461abcdca2bdfbe71234208d3fc5f846b /CST116F2021-Lab9 | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab9-bensprogramma-41d31d37ee78cb4f1b6f993eb137e56b86b3e77b.tar.xz cst116-lab9-bensprogramma-41d31d37ee78cb4f1b6f993eb137e56b86b3e77b.zip | |
Initial commit WITH CODE
Diffstat (limited to 'CST116F2021-Lab9')
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 20 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj | 2 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters | 2 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp | 282 |
4 files changed, 284 insertions, 22 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp deleted file mode 100644 index d7b3cce..0000000 --- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// CST116F2021-Lab9.cpp : This file contains the 'main' function. Program execution begins and ends there. -// - -#include <iostream> - -int main() -{ - std::cout << "Hello World!\n"; -} - -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu - -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj index fd67c6e..850d5a9 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj @@ -139,7 +139,7 @@ </Link> </ItemDefinitionGroup> <ItemGroup> - <ClCompile Include="CST116F2021-Lab9.cpp" /> + <ClCompile Include="CST116F2021-Lab9_Schroeder.cpp" /> </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 bb090d3..f8daf6d 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters @@ -15,7 +15,7 @@ </Filter> </ItemGroup> <ItemGroup> - <ClCompile Include="CST116F2021-Lab9.cpp"> + <ClCompile Include="CST116F2021-Lab9_Schroeder.cpp"> <Filter>Source Files</Filter> </ClCompile> </ItemGroup> diff --git a/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp new file mode 100644 index 0000000..e90e0b7 --- /dev/null +++ b/CST116F2021-Lab9/CST116F2021-Lab9_Schroeder.cpp @@ -0,0 +1,282 @@ +// CST116F2021-Lab9_Schroeder.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +/* +//// 11.14 Programming Exercises pp 337 - 338 #2 ////////////////////////////////////////////////////////////////// +#include <iostream> +#include <fstream> +#include <string> +#include <iomanip> +using namespace std; + +char fileName[200]; +int inputIntegers[10]{}; +ifstream fin; + +int main() +{ + + + cout << "Enter the the name of the file you want to open: "; + cin >> fileName; + + + fin.open(fileName); + while (fin && !fin.eof()) + { + for (int i = 0; i < 10; i++) + fin >> inputIntegers[i]; + } + + int j = 0, k = 0, temp = 0; + for (j = 0; j < 10; j++) + { + for (k = 0; k < 10 - 1; k++) + { + if (inputIntegers[k] > inputIntegers[k + 1]) + { + temp = inputIntegers[k]; + inputIntegers[k] = inputIntegers[k + 1]; + inputIntegers[k + 1] = temp; + } + } + } + + cout << "The integers in this file range from " << inputIntegers[0] << " to " << inputIntegers[9]<< "\n"; + cout << "\nSorted list of integers from the file:\n"; + for (int l = 0; l < 10; l++) + { + cout << inputIntegers[l]<< "\n"; + } +*/ + + + +/* +// /// 11.14 Programming Exercises pp 337 - 338 #3 ///////////////////////////////////////////////////////////////////////// +#include <iostream> +#include <fstream> +#include <string> +#include <iomanip> +using namespace std; + +char fileName[200]; +int inputIntegers[10]{}; +string lines[1000]; +int num_records = 0; + +ifstream fin; + +int main() +{ + cout << "Enter the the name of the file you want to open: "; + cin >> fileName; + + fin.open(fileName); + while (fin && !fin.eof()) + { + getline(fin, lines[num_records]); + + cout << num_records+1 << ". " << lines[num_records] << " (" << lines[num_records].length() << " characters)\n"; + num_records++; + } + fin.close(); +} +*/ + + + +// /// 11.14 Programming Exercises pp 337 - 338 #4 /////////////////////////////////////////////////////////////////////// +#include <iostream> +#include <fstream> +#include <string> +#include <iomanip> +using namespace std; + +string first[100]{}; +string last[100]{}; +string ph[100]{}; +string bd[100]{}; + +int num_records = 0; +ifstream fin; +ofstream fout; + +void DisplayMenu(); +void Find(); +void Add(); +void Edit(); +void Display(); +void Sort(); +void Update(); + + +int main() +{ + // READ THE FILE IN + fin.open("INFO2.txt"); + while (fin && !fin.eof()) + { + fin >> first[num_records] + >> last[num_records] + >> ph[num_records] + >> bd[num_records]; + num_records++; + } + fin.close(); + + DisplayMenu(); + +} + +void DisplayMenu() +{ + int menuChoice = 0; + cout << "\t Menu Driven Database\n"; + cout << "************************************************\n"; + cout << "\t1) Find a person's information\n"; + cout << "\t2) Add a person to the database\n"; + cout << "\t3) Edit a person's information\n"; + cout << "\t4) Display all records to the screen\n"; + cout << "\t5) Quit\n**************************************************\n"; + cout << "Enter the number of the option you desire: "; + cin >> menuChoice; + + 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; + } + } +} + +void Find() +{ + +} + + +void Add() +{ + cout << "Last Name: "; + cin >> last[num_records]; + cout << "First Name: "; + cin >> first[num_records]; + cout << "ph #: "; + cin >> ph[num_records]; + cout << "Date Of Birth: "; + cin >> bd[num_records]; + num_records++; + + cout << "\n\n"; + + DisplayMenu(); + +} +void Edit() +{ + Sort(); + + 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"; + } + int choice = 0; + cout << "\n\nEnter the # of the record you would like to edit: "; + cin >> choice; + cout << "Last Name: "; + cin >> last[choice - 1]; + cout << "First Name: "; + cin >> first[choice - 1]; + cout << "ph #: "; + cin >> ph[choice - 1]; + cout << "Date Of Birth: "; + cin >> bd[choice - 1]; + cout << "\n\n"; + + DisplayMenu(); +} + + +void Display() +{ + Sort(); + + cout << "\nAll of the current records:\n"; //sorted alphabetically by last name + 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 << "\n\n"; + + DisplayMenu(); +} + +void Sort() +{ + // Sort the records by last name + bool swapped = true; + int j = 0; + string tmp1; + string tmp2; + string tmp3; + string tmp4; + + while (swapped) + { + swapped = false; + j++; + for (int i = 0; i < num_records - 1; i++) + { + if (last[i] > (last[i + 1])) + { + tmp1 = last[i]; tmp2 = first[i]; tmp3 = ph[i]; tmp4 = bd[i]; + last[i] = last[i + 1]; first[i] = first[i + 1]; ph[i] = ph[i + 1]; bd[i] = bd[i + 1]; + last[i + 1] = tmp1; first[i + 1] = tmp2; ph[i + 1] = tmp3; bd[i + 1] = tmp4; + swapped = true; + } + } + } + +} + +void Update() +{ + Sort(); + + fout.open("INFO2.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"; + + fout.close(); + +} + + + + |