aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Ten Eyck <[email protected]>2021-12-08 23:58:56 -0800
committerJoseph Ten Eyck <[email protected]>2021-12-08 23:58:56 -0800
commit98c48806582531ba7dd8b3684f78b958ca807f8c (patch)
treed9424c21d2f7550f46d69532beb114590d2834da
parentAdd online IDE url (diff)
downloadcst116-lab9-josephteneyck-98c48806582531ba7dd8b3684f78b958ca807f8c.tar.xz
cst116-lab9-josephteneyck-98c48806582531ba7dd8b3684f78b958ca807f8c.zip
I had a lot of troubles over the week with syntax errors while file reading/writing within my programs. Also, my number sorting algorithm has some syntax error I have not found yet. I have gotten this far with the code and I am pushing what I have before midnight. I am still making progress and I hope to have it all finished tonight sometime.
-rw-r--r--CST116F2021-Lab9/CST116F2021-Lab9 - Joseph Ten Eyck.cpp414
-rw-r--r--CST116F2021-Lab9/CST116F2021-Lab9.cpp20
-rw-r--r--CST116F2021-Lab9/CST116F2021-Lab9.vcxproj2
-rw-r--r--CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters2
-rw-r--r--CST116F2021-Lab9/Integers.txt1
-rw-r--r--CST116F2021-Lab9/RUNS.txt56
-rw-r--r--CST116F2021-Lab9/Records.txt5
-rw-r--r--CST116F2021-Lab9/TextFile.txt5
8 files changed, 483 insertions, 22 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9 - Joseph Ten Eyck.cpp b/CST116F2021-Lab9/CST116F2021-Lab9 - Joseph Ten Eyck.cpp
new file mode 100644
index 0000000..f186574
--- /dev/null
+++ b/CST116F2021-Lab9/CST116F2021-Lab9 - Joseph Ten Eyck.cpp
@@ -0,0 +1,414 @@
+/////////////////////////////////////////////
+// CODE FOR PROBLEM #2 ON PAGE 337 IS BELOW
+/////////////////////////////////////////////
+
+
+//#include <iostream>
+//#include <iomanip>
+//#include <fstream>
+//#include <string>
+//
+//using namespace std;
+//
+//const int MAX_INTEGERS = 10;
+//
+//void readData(string&, ifstream& inFile, int[]); //takes in user input filename, gets integers from file and puts them into an array
+//void sort(int[], int[]); //sorts the integers into another array (ascending order)
+//void displayInfo(int[]); //displays the smallest and greatest integers and then displays the list of sorted integers (ascending order)
+//
+//int main()
+//{
+// string fileName;
+// int originalList[MAX_INTEGERS];
+// int sortedList[MAX_INTEGERS];
+//
+// ifstream inFile;
+//
+// cout << "\n\t\t============================================";
+// cout << "\n\t\t Basic integer sorting from file";
+// cout << "\n\t\t (with smallest & greatest integer found)";
+// cout << "\n\t\t============================================";
+//
+// readData(fileName, inFile, originalList);
+// sort(originalList, sortedList);
+// displayInfo(sortedList);
+//
+//}
+//
+//void readData(string& fileName, ifstream& inFile, int originalList[]) //takes in user input filename, gets integers from file and puts them into an array
+//{
+// cout << "\n\n\tInput file name (including extension): ";
+// getline(cin, fileName);
+//
+// string filePath = "C:\\Users\\eclip\\source\\repos\\cst116-lab9-JosephTenEyck\\CST116F2021-Lab9\\" + fileName;
+//
+// inFile.open(filePath);
+//
+// if (inFile.is_open())
+// {
+// int i = 0;
+//
+// inFile >> originalList[i]; //priming read
+//
+// while (!inFile.eof()) //reads rest of file into array
+// {
+// i++;
+//
+// inFile >> originalList[i];
+// }
+// }
+// else
+// {
+// cout << "\n\nERROR: Unable to open file with name '" << fileName << "'" << endl;
+//
+// exit(1);
+// }
+//}
+//
+//void sort(int originalList[], int sortedList[]) //sorts the integers into another array (ascending order)
+//{
+// int tempList[MAX_INTEGERS];
+//
+// for (int i = 0; i < MAX_INTEGERS - 1; i++) //makes a copy of originalList to be used for sorting algorithm
+// {
+// tempList[i] = originalList[i];
+// }
+//
+// //sorting algorithm
+// for (int j = 0; j < MAX_INTEGERS - 1; j++) //each index of sortedList
+// {
+// if ((sizeof(tempList) / sizeof(tempList[0])) > 1)
+// {
+// int hold = tempList[0]; //value of current smallest found integer
+// int indexH = 0; //index of current smallest found integer
+//
+// for (int i = 0; i < (sizeof(tempList) / sizeof(tempList[0])) - 1; i++) //finds smallest number in the current version of tempList
+// {
+// if (hold < tempList[i + 1])
+// {
+// hold = hold;
+// }
+// else if (hold == tempList[i + 1])
+// {
+// hold = tempList[i + 1];
+// indexH++;
+// }
+// else
+// {
+// hold = tempList[i + 1];
+// indexH++;
+// }
+// }
+// sortedList[j] = hold; //writes currently found smallest integer to sortedList
+//
+// for (int k = 0; k < (sizeof(tempList) / sizeof(tempList[0])) - indexH + 1; k++) //removes current smallest found integer from tempList and compresses
+// {
+// tempList[indexH + k] = tempList[indexH + k + 1];
+// }
+// }
+// else if ((sizeof(tempList) / sizeof(tempList[0])) == 1)
+// {
+// sortedList[MAX_INTEGERS - 1] = tempList[0];
+// }
+// }
+//}
+//
+//void displayInfo(int sortedList[]) //displays the smallest and greatest integers and then displays the list of sorted integers (ascending order)
+//{
+// int smallest = sortedList[0];
+// int largest = sortedList[MAX_INTEGERS - 1];
+//
+// cout << "\n\n\tThe smallest number is: " << smallest;
+// cout << "\n\tThe largest number is: " << largest;
+//
+// cout << "\n\nThe numbers in order from smallest to largest are :";
+// cout << "\n\n";
+//
+// for (int i = 0; i < MAX_INTEGERS - 1; i++)
+// {
+// cout << sortedList[i] << ", ";
+// }
+//
+// cout << "\n" << endl;
+//}
+
+
+/////////////////////////////////////////////
+// CODE FOR PROBLEM #3 ON PAGE 337 IS BELOW
+/////////////////////////////////////////////
+
+
+//#include <iostream>
+//#include <iomanip>
+//#include <fstream>
+//#include <string>
+//#include <cstdio>
+//#include <cstring>
+//
+//using namespace std;
+//
+//const int MAX_CHARACTERS = 1000;
+//
+//
+//string readData(ifstream& inFile); //takes in user input filename, reads file, returns string
+//void displayText(char[]); // displays text along with line numbers and character counts
+//
+//int main()
+//{
+// ifstream inFile;
+//
+// string text;
+//
+// cout << "\n\t\t============================================";
+// cout << "\n\t\t Basic text file reader";
+// cout << "\n\t\t (with line counter and character counter)";
+// cout << "\n\t\t=============================================";
+//
+// text = readData(inFile);
+//
+// char textArray[MAX_CHARACTERS]{char(0)};
+//
+// for (int i = 0; i < text.size() - 1; i++) //writes string to char array
+// {
+// textArray[i] = text[i];
+// }
+//
+// displayText(textArray);
+//
+// return 0;
+//}
+//
+//string readData(ifstream& inFile) //takes in user input filename, reads file, returns string
+//{
+// string fileName;
+// string text;
+//
+// cout << "\n\n\tInput file name (including extension): ";
+// getline(cin, fileName);
+//
+// string filePath = "C:\\Users\\eclip\\source\\repos\\cst116-lab9-JosephTenEyck\\CST116F2021-Lab9\\" + fileName;
+//
+// inFile.open(filePath);
+//
+// if (inFile.is_open())
+// {
+// while (!inFile.eof())
+// {
+// getline(inFile, text, char(0)); //read from inFile, write to "text", until NUL character found
+// }
+// }
+// else
+// {
+// cout << "\n\nERROR: Unable to open file with name '" << fileName << "'" << endl;
+//
+// exit(1);
+// }
+// return text;
+//}
+//
+//void displayText(char textArray[]) // displays text along with line numbers and character counts
+//{
+// int lineNumber = 2;
+// int charCount = 0;
+//
+// cout << "\n1 ";
+//
+// for (int i = 0; i < MAX_CHARACTERS - 1; i++)
+// {
+// if (textArray[i] == '\n')
+// {
+// cout << " [" << charCount << "]" << endl;
+// cout << textArray[i] << lineNumber << " ";
+//
+// lineNumber++;
+// charCount = 0;
+// }
+// else if (textArray[i] == char(0))
+// {
+// cout << " [" << charCount << "]" << endl;
+// break;
+// }
+// else
+// {
+// cout << textArray[i];
+//
+// charCount++;
+// }
+// }
+//}
+
+
+/////////////////////////////////////////////
+// CODE FOR PROBLEM #3 ON PAGE 337 IS BELOW
+/////////////////////////////////////////////
+
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <string>
+#include <cstdio>
+#include <cstring>
+
+using namespace std;
+
+const int MAX_RECORDS = 5;
+
+void getData(ifstream& inFile, string[], string[], string[], string[]); //reads datafile into arrays
+void displayMenu(int&); //displays menu
+void findInfo(string[], string[], string[], string[]); //finds a person's info
+void addInfo(); //allows user to add a person to the database
+void editInfo(); //allows user to edit a person's info
+void displayRecords(); //displays all records
+
+int main()
+{
+ ifstream inFile;
+
+ int menuChoice = 0;
+
+ string firstNames[MAX_RECORDS];
+ string lastNames[MAX_RECORDS];
+ string phoneNumbers[MAX_RECORDS];
+ string birthdays[MAX_RECORDS];
+
+
+ cout << "\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~";
+ cout << "\n\t\t Basic database program";
+ cout << "\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
+
+ getData(inFile, firstNames, lastNames, phoneNumbers, birthdays);
+ displayMenu(menuChoice);
+
+ switch (menuChoice)
+ {
+ case 1:
+ {
+ findInfo(firstNames, lastNames, phoneNumbers, birthdays);
+ break;
+ }
+ case 2:
+ {
+ addInfo();
+ break;
+ }
+ case 3:
+ {
+ editInfo();
+ break;
+ }
+ case 4:
+ {
+ displayRecords();
+ break;
+ }
+ case 5:
+ {
+ cout << "\n\n\t\t~ Goodbye! ~" << endl;
+ exit(0);
+ break;
+ }
+ default:
+ {
+ cout << "\nERROR: Impossible menu value";
+ }
+ }
+}
+
+
+void getData(ifstream& inFile, string firstNames[], string lastNames[], string phoneNumbers[], string birthdays[])
+{
+ inFile.open("C:\\Users\\eclip\\source\\repos\\cst116-lab9-JosephTenEyck\\CST116F2021-Lab9\\Records.txt");
+
+ if (inFile.is_open())
+ {
+ int i = 0;
+
+ inFile >> firstNames[i] >> lastNames[i] >> phoneNumbers[i] >> birthdays[i]; //priming read
+
+ while (!inFile.eof()) //reads rest of file into array
+ {
+ i++;
+
+ inFile >> firstNames[i] >> lastNames[i] >> phoneNumbers[i] >> birthdays[i];
+ }
+ }
+ else
+ {
+ cout << "\n\nERROR: Unable to open file" << endl;
+
+ exit(1);
+ }
+}
+
+void displayMenu(int& menuChoice) //displays menu
+{
+ do
+ {
+ cout << "\n\t\t==============================";
+ cout << "\n\t\t What would you like to do?";
+ cout << "\n\t\t==============================" << endl;
+
+ cout << "\n\n\t1. Find person's info";
+ cout << "\n\t2. Add person's info";
+ cout << "\n\t3. Edit a person's info";
+ cout << "\n\t4. Display all records";
+ cout << "\n\t5. Exit";
+
+ cout << "\n\n\t\tMenu choice: ";
+ cin >> menuChoice;
+
+ if (menuChoice < 1 || menuChoice > 5)
+ {
+ cout << "\nERROR: Invalid menu choice";
+ }
+ } while (menuChoice < 1 || menuChoice > 5);
+}
+
+void findInfo(string firstNames[], string lastNames[], string phoneNumbers[], string birthdays[]) //finds and displays a person's info
+{
+ string searchFirst;
+ string searchLast;
+ int i = 0;
+
+ cout << "\n\tEnter the peron's first name (case sensitive): ";
+ cin >> searchFirst;
+
+ cout << "\n\tEnter the peron's last name (case sensitive): ";
+ cin >> searchLast;
+
+ do
+ {
+ if (searchFirst == firstNames[i] && searchLast == lastNames[i])
+ {
+ cout << "\n~~~~";
+ cout << "\n" << "First name: " << firstNames[i];
+ cout << "\n" << "Last name: " << lastNames[i];
+ cout << "\n" << "Phone number: " << phoneNumbers[i];
+ cout << "\n" << "Birthday: " << birthdays[i];
+ cout << "\n~~~~" << endl;
+
+ break;
+ }
+
+ i++;
+
+ } while (searchFirst != firstNames[i] && searchLast != lastNames[i]);
+
+ cout << "\n\n\t\tGOT HERE!!!!";
+}
+
+void addInfo() //allows user to add a person to the database
+{
+
+}
+
+void editInfo() //allows user to edit a person's info
+{
+
+}
+
+void displayRecords() //displays all records
+{
+
+} \ No newline at end of file
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..3464271 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 - Joseph Ten Eyck.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..4fc0ddc 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 - Joseph Ten Eyck.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
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/RUNS.txt b/CST116F2021-Lab9/RUNS.txt
new file mode 100644
index 0000000..f8fcf68
--- /dev/null
+++ b/CST116F2021-Lab9/RUNS.txt
@@ -0,0 +1,56 @@
+//////////////////////////////////////////////
+// RUNS FOR PROBLEM #2 ON PAGE 337 ARE BELOW
+//////////////////////////////////////////////
+
+
+//////////////////////////////////////////////
+// RUNs FOR PROBLEM #3 ON PAGE 337 ARE BELOW
+//////////////////////////////////////////////
+
+
+
+ ============================================
+ Basic text file reader
+ (with line counter and character counter)
+ =============================================
+
+ Input file name (including extension): TextFile.text
+
+
+ERROR: Unable to open file with name 'TextFile.text'
+
+C:\Users\eclip\Source\Repos\cst116-lab9-JosephTenEyck\Debug\CST116F2021-Lab9.exe (process 8816) exited with code 1.
+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 . . .
+
+
+
+
+ ============================================
+ Basic text file reader
+ (with line counter and character counter)
+ =============================================
+
+ Input file name (including extension): TextFile.txt
+
+1 This is the first sentence, hello. [34]
+
+2 This is the second sentence, awesome! [37]
+
+3 This is the third sentence, it's a doozy. [41]
+
+4 This is the fourth sentence, lovely? [36]
+
+5 This is the fifth sentence, bye [31]
+
+C:\Users\eclip\Source\Repos\cst116-lab9-JosephTenEyck\Debug\CST116F2021-Lab9.exe (process 11800) 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 . . .
+
+
+
+//////////////////////////////////////////////
+// RUNS FOR PROBLEM #4 ON PAGE 337 ARE BELOW
+//////////////////////////////////////////////
+
+
diff --git a/CST116F2021-Lab9/Records.txt b/CST116F2021-Lab9/Records.txt
new file mode 100644
index 0000000..5328244
--- /dev/null
+++ b/CST116F2021-Lab9/Records.txt
@@ -0,0 +1,5 @@
+Todd Megadude 5551234567 11/24/1990
+Breanna Strangelove 6663219856 6/18/1804
+Sherri Pies 3219876542 1/19/2005
+Clayton Clackin 6352541458 2/23/1999
+Scarlett Falcon 6369856742 10/17/1975 \ No newline at end of file
diff --git a/CST116F2021-Lab9/TextFile.txt b/CST116F2021-Lab9/TextFile.txt
new file mode 100644
index 0000000..b36a391
--- /dev/null
+++ b/CST116F2021-Lab9/TextFile.txt
@@ -0,0 +1,5 @@
+This is the first sentence, hello.
+This is the second sentence, awesome!
+This is the third sentence, it's a doozy.
+This is the fourth sentence, lovely?
+This is the fifth sentence, bye. \ No newline at end of file