diff options
| author | Benjamin Schroeder <[email protected]> | 2021-12-03 17:05:08 -0800 |
|---|---|---|
| committer | Benjamin Schroeder <[email protected]> | 2021-12-03 17:05:08 -0800 |
| commit | dbca20d27a4bfef40ae18882bcde8284ebd31673 (patch) | |
| tree | 4de81c195245a6d436f333f09a5d63ee7a22a6aa | |
| parent | Initial commit WITH CODE (diff) | |
| download | cst116-lab9-bensprogramma-dbca20d27a4bfef40ae18882bcde8284ebd31673.tar.xz cst116-lab9-bensprogramma-dbca20d27a4bfef40ae18882bcde8284ebd31673.zip | |
Push with txt files
| -rw-r--r-- | CST116F2021-Lab9/INFO.txt | 12 | ||||
| -rw-r--r-- | CST116F2021-Lab9/INFO2.txt | 13 | ||||
| -rw-r--r-- | CST116F2021-Lab9/RUNS.txt | 443 | ||||
| -rw-r--r-- | CST116F2021-Lab9/integers.txt | 1 | ||||
| -rw-r--r-- | CST116F2021-Lab9/linesOfText.txt | 5 |
5 files changed, 474 insertions, 0 deletions
diff --git a/CST116F2021-Lab9/INFO.txt b/CST116F2021-Lab9/INFO.txt new file mode 100644 index 0000000..0e07038 --- /dev/null +++ b/CST116F2021-Lab9/INFO.txt @@ -0,0 +1,12 @@ +Kevin Ashes 765-949-7343 06/25/1995 +Billy Bobson 951-652-3625 12/12/1912 +Molly Brown 432-489-7654 12/12/1912 +David Cackroche 317-981-2527 12/25/1928 +Kim Cares 343-117-2222 11/30/2005 +Trish Dish 798-654-9844 06/12/2001 +Will Kusick 232-451-2322 01/01/2001 +Anthony Lei 934-433-9843 07/23/1982 +Cheryl Prince 983-554-9000 04/12/1988 +John Smith 123-209-9765 11/12/1975 +Keel Water 762-848-6543 03/25/1997 +Tim Wheeler 239-349-3458 01/01/1999
\ No newline at end of file diff --git a/CST116F2021-Lab9/INFO2.txt b/CST116F2021-Lab9/INFO2.txt new file mode 100644 index 0000000..c2e8d2d --- /dev/null +++ b/CST116F2021-Lab9/INFO2.txt @@ -0,0 +1,13 @@ +Kevin Ashes 765-949-7343 06/25/1995 +Billy Bobson 951-652-3625 12/12/1912 +Molly Brown 432-489-7654 12/12/1912 +David Cackroche 317-981-2527 12/25/1928 +Kim Cares 343-117-2222 11/30/2005 +Prince Cheryl 983-554-9000 04/12/1988 +Trish Dish 798-654-9844 06/12/2001 +Will Kusick 232-451-2322 01/01/2001 +Anthony Lei 934-433-9843 07/23/1982 +John Smith 123-209-9765 11/12/1975 +John Smith 812-445-9867 02-29-1984 +Keel Water 762-848-6543 03/25/1997 +Tim Wheeler 239-349-3458 01/01/1999 diff --git a/CST116F2021-Lab9/RUNS.txt b/CST116F2021-Lab9/RUNS.txt new file mode 100644 index 0000000..03ceb73 --- /dev/null +++ b/CST116F2021-Lab9/RUNS.txt @@ -0,0 +1,443 @@ +Lab 9 CST116 Benjamin Schroeder +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//// 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"; + } + +} + +// ///// Run ///// +Enter the the name of the file you want to open: integers.txt +The integers in this file range from 23 to 2021 + +Sorted list of integers from the file: +23 +33 +44 +120 +234 +340 +501 +530 +567 +2021 + +C:\Users\Lenovo\source\repos\Lab9_Schroeder\Debug\Lab9_Schroeder.exe (process 13476) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +// /// 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++; + } + +} + +// /////////////// ////////// RUN ////////////////////// + +Enter the the name of the file you want to open: linesOfText.txt +1. The C++ getline() is a standard library function that is used to read a string or a line from an input stream. (110 characters) +2. It is a part of the <string> header. (36 characters) +3. The getline() function extracts characters from the input stream and appends it to the string object until the delimiting character is encountered. (147 characters) +4. While doing so the previously stored value in the string object str will be replaced by the input string if any. (112 characters) +5. The getline() function can be represented in two ways: (54 characters) + +C:\Users\Lenovo\source\repos\Lab9_Schroeder\Debug\Lab9_Schroeder.exe (process 3156) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + + +// /// 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(); + +} + + +// ///////////////////// RUNS /////////////////////// + +**************************************************************************** +// Original File: +1. Kevin Ashes ph: 765-949-7343 DOB: 06/25/1995 +2. Billy Bobson ph: 951-652-3625 DOB: 12/12/1912 +3. Molly Brown ph: 432-489-7654 DOB: 12/12/1912 +4. David Cackroche ph: 317-981-2527 DOB: 12/25/1928 +5. Kim Cares ph: 343-117-2222 DOB: 11/30/2005 +6. Trish Dish ph: 798-654-9844 DOB: 06/12/2001 +7. Will Kusick ph: 232-451-2322 DOB: 01/01/2001 +8. Anthony Lei ph: 934-433-9843 DOB: 07/23/1982 +9. Cheryl Prince ph: 983-554-9000 DOB: 04/12/1988 +10. John Smith ph: 123-209-9765 DOB: 11/12/1975 +11. Keel Water ph: 762-848-6543 DOB: 03/25/1997 +12. Tim Wheeler ph: 239-349-3458 DOB: 01/01/1999 +***************************************************************************** + + + Menu Driven Database +************************************************ + 1) Find a person's information + 2) Add a person to the database + 3) Edit a person's information + 4) Display all records to the screen + 5) Quit +************************************************** +Enter the number of the option you desire: 2 +Last Name: Smith +First Name: John +ph #: 812-445-9867 +Date Of Birth: 02-29-1984 + + + Menu Driven Database +************************************************ + 1) Find a person's information + 2) Add a person to the database + 3) Edit a person's information + 4) Display all records to the screen + 5) Quit +************************************************** +Enter the number of the option you desire: 4 + +All of the current records: +1. Kevin Ashes ph: 765-949-7343 DOB: 06/25/1995 +2. Billy Bobson ph: 951-652-3625 DOB: 12/12/1912 +3. Molly Brown ph: 432-489-7654 DOB: 12/12/1912 +4. David Cackroche ph: 317-981-2527 DOB: 12/25/1928 +5. Kim Cares ph: 343-117-2222 DOB: 11/30/2005 +6. Trish Dish ph: 798-654-9844 DOB: 06/12/2001 +7. Will Kusick ph: 232-451-2322 DOB: 01/01/2001 +8. Anthony Lei ph: 934-433-9843 DOB: 07/23/1982 +9. Cheryl Prince ph: 983-554-9000 DOB: 04/12/1988 +10. John Smith ph: 123-209-9765 DOB: 11/12/1975 +11. John Smith ph: 812-445-9867 DOB: 02-29-1984 +12. Keel Water ph: 762-848-6543 DOB: 03/25/1997 +13. Tim Wheeler ph: 239-349-3458 DOB: 01/01/1999 + + + Menu Driven Database +************************************************ + 1) Find a person's information + 2) Add a person to the database + 3) Edit a person's information + 4) Display all records to the screen + 5) Quit +************************************************** +Enter the number of the option you desire: 3 + +All of the current records: +1. Kevin Ashes ph: 765-949-7343 DOB: 06/25/1995 +2. Billy Bobson ph: 951-652-3625 DOB: 12/12/1912 +3. Molly Brown ph: 432-489-7654 DOB: 12/12/1912 +4. David Cackroche ph: 317-981-2527 DOB: 12/25/1928 +5. Kim Cares ph: 343-117-2222 DOB: 11/30/2005 +6. Trish Dish ph: 798-654-9844 DOB: 06/12/2001 +7. Will Kusick ph: 232-451-2322 DOB: 01/01/2001 +8. Anthony Lei ph: 934-433-9843 DOB: 07/23/1982 +9. Cheryl Prince ph: 983-554-9000 DOB: 04/12/1988 +10. John Smith ph: 123-209-9765 DOB: 11/12/1975 +11. John Smith ph: 812-445-9867 DOB: 02-29-1984 +12. Keel Water ph: 762-848-6543 DOB: 03/25/1997 +13. Tim Wheeler ph: 239-349-3458 DOB: 01/01/1999 + + +Enter the # of the record you would like to edit: 9 +Last Name: Cheryl +First Name: Prince +ph #: 983-554-9000 +Date Of Birth: 04/12/1988 + + + Menu Driven Database +************************************************ + 1) Find a person's information + 2) Add a person to the database + 3) Edit a person's information + 4) Display all records to the screen + 5) Quit +************************************************** +Enter the number of the option you desire: 4 + +All of the current records: +1. Kevin Ashes ph: 765-949-7343 DOB: 06/25/1995 +2. Billy Bobson ph: 951-652-3625 DOB: 12/12/1912 +3. Molly Brown ph: 432-489-7654 DOB: 12/12/1912 +4. David Cackroche ph: 317-981-2527 DOB: 12/25/1928 +5. Kim Cares ph: 343-117-2222 DOB: 11/30/2005 +6. Prince Cheryl ph: 983-554-9000 DOB: 04/12/1988 +7. Trish Dish ph: 798-654-9844 DOB: 06/12/2001 +8. Will Kusick ph: 232-451-2322 DOB: 01/01/2001 +9. Anthony Lei ph: 934-433-9843 DOB: 07/23/1982 +10. John Smith ph: 123-209-9765 DOB: 11/12/1975 +11. John Smith ph: 812-445-9867 DOB: 02-29-1984 +12. Keel Water ph: 762-848-6543 DOB: 03/25/1997 +13. Tim Wheeler ph: 239-349-3458 DOB: 01/01/1999 + + + Menu Driven Database +************************************************ + 1) Find a person's information + 2) Add a person to the database + 3) Edit a person's information + 4) Display all records to the screen + 5) Quit +************************************************** +Enter the number of the option you desire: 5 + Thank you, Goodbye! +C:\Users\Lenovo\source\repos\Lab9_Schroeder\Debug\Lab9_Schroeder.exe (process 14904) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . diff --git a/CST116F2021-Lab9/integers.txt b/CST116F2021-Lab9/integers.txt new file mode 100644 index 0000000..08b6693 --- /dev/null +++ b/CST116F2021-Lab9/integers.txt @@ -0,0 +1 @@ +120 234 33 2021 44 23 530 567 340 501
\ No newline at end of file diff --git a/CST116F2021-Lab9/linesOfText.txt b/CST116F2021-Lab9/linesOfText.txt new file mode 100644 index 0000000..7ad3748 --- /dev/null +++ b/CST116F2021-Lab9/linesOfText.txt @@ -0,0 +1,5 @@ +The C++ getline() is a standard library function that is used to read a string or a line from an input stream. +It is a part of the <string> header. +The getline() function extracts characters from the input stream and appends it to the string object until the delimiting character is encountered. +While doing so the previously stored value in the string object str will be replaced by the input string if any. +The getline() function can be represented in two ways:
\ No newline at end of file |