diff options
| author | WiserJ <[email protected]> | 2021-12-07 16:48:40 -0800 |
|---|---|---|
| committer | WiserJ <[email protected]> | 2021-12-07 16:48:40 -0800 |
| commit | d27f2c138505069856f9e42e951aee157afe1ff1 (patch) | |
| tree | 5403cb7c57b7037027f54930d3f1f720320b49c3 /CST116F2021-Lab9 | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab9-jeffwoit-d27f2c138505069856f9e42e951aee157afe1ff1.tar.xz cst116-lab9-jeffwoit-d27f2c138505069856f9e42e951aee157afe1ff1.zip | |
h
Diffstat (limited to 'CST116F2021-Lab9')
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.cpp | 386 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj | 5 | ||||
| -rw-r--r-- | CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters | 5 |
3 files changed, 386 insertions, 10 deletions
diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.cpp b/CST116F2021-Lab9/CST116F2021-Lab9.cpp index d7b3cce..3499469 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.cpp +++ b/CST116F2021-Lab9/CST116F2021-Lab9.cpp @@ -2,19 +2,385 @@ // #include <iostream> +#include <fstream> +#include <string> +#include <iomanip> + +using namespace std; + +const int ARRAY_SIZE = 4; +const int NUM_RECORDS = 100; +const int NAME_SIZE = 100; + +int menuSelect(int); +void getInput(char[NAME_SIZE]); +void readFile(char[NAME_SIZE], string[][ARRAY_SIZE]); +void findData(string[][ARRAY_SIZE]); +void addData(string[][ARRAY_SIZE]); +void sortData(string[][ARRAY_SIZE]); +void editData(string[][ARRAY_SIZE]); +void dispData(string[][ARRAY_SIZE]); int main() { - std::cout << "Hello World!\n"; + int menu = 0; + char file_name[NAME_SIZE]{}; + string info[NUM_RECORDS][ARRAY_SIZE]; + + getInput(file_name); + readFile(file_name); + + while (menu != 5) + menuSelect(menu); + + switch (menu) + { + default: + { + cout << "Invalid menu selection." << endl; + break; + } + case 1: + { + findData(info); + break; + } + case 2: + { + addData(info); + break; + } + case 3: + { + editData(info); + break; + } + case 4: + { + dispData(info); + break; + } + case 5: + break; + } + //Before program closes, files must be updated with the new database stored in 'info' + cout << "Exiting Program." << endl; + return 0; +} + +void getInput(char inputFileName[]) +{ + cout << "Please enter the file name: "; + cin >> inputFileName; } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu +void readFile(char readFileName[], string readArray[][ARRAY_SIZE]) +{ + int i = 0, j = 0; + string temp; + + ifstream inFile; + inFile.open(readFileName); + + if (inFile.is_open()) + { + cout << "File is opened." << endl; + while (!inFile.eof()) + { + //add a counter i for the number of lines in the inFile + while (j < ARRAY_SIZE) + { + getline(inFile, temp, ' '); + readArray[i][j] = temp; + j++; + } + } + } + inFile.close(); //going to be editting the inFile so don't close yet + return; +} + +int menuSelect(int inputMenu) +{ + cout << "Please select from the following options:" << endl << "\t1) Find a person's information" << endl << "\t2) Add a person to the database" << endl << "\t3) Edit a person's information" << endl << "\t4) Display all records to the screen" << endl << "\t5) Quit" << endl; + cin >> inputMenu; + + return inputMenu; +} + +void findData(string findArray[][ARRAY_SIZE]) +{ + string name; + int found = false, left = 0, right = sizeof(findArray), mid = 0; + + + cout << "Please enter the last name of the user you are looking for: "; + cin >> name; + + while (!found && left <= right) + { + + } + //Find function needs to specify the location of the user for edit function +} + +void addData(string addArray[][ARRAY_SIZE]) +{ + int i = 0; + + while (i < NUM_RECORDS) + { + if (addArray[i][0] == "\0") //Should stop at the first empty entry + { + cout << "Please enter the last name: "; + cin >> addArray[i][0]; + + cout << "Please enter the first name: "; + cin >> addArray[i][1]; + + cout << "Please enter the phone number in format ###-###-####: "; + cin >> addArray[i][2]; + + cout << "Please enter the birthday in format mm-dd-yyyy: "; + cin >> addArray[i][3]; + break; + } + else + i++; + } + sortData(addArray); +} + +void sortData(string sortArray[][ARRAY_SIZE]) +{ + +} + +void editData(string editArray[][ARRAY_SIZE]) +{ + int select = 0, i = 0; + findData(editArray); + //Find function needs to give a value for i so the program correctly edits the specified user -// 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 + + cout << "Please select from the following options:" << endl << "\t1) Change Last Name" << endl << "\t2) Change First Name" << endl << "\t3) Change Phone Number" << endl << "\t4) Change Birthday" << endl << "\t5) Quit" << endl; + cin >> select; + + switch (select) + { + default: + { + cout << "Invalid selection." << endl; + break; + } + case 1: + { + cout << "Please enter the last name: "; + cin >> editArray[i][0]; + break; + } + case 2: + { + cout << "Please enter the first name: "; + cin >> editArray[i][1]; + break; + } + case 3: + { + cout << "Please enter the phone number in format ###-###-####: "; + cin >> editArray[i][2]; + break; + } + case 4: + { + cout << "Please enter the birthday in format mm-dd-yyyy: "; + cin >> editArray[i][3]; + break; + } + case 5: + { + cout << "No changes made." << endl; + break; + } + } + if (select > 0 && select <= 4) + sortData(editArray); +} + +void dispData(string dispArray[][ARRAY_SIZE]) +{ + cout << setw(20) << "Entry Number" << setw(20) << "Last Name" << setw(20) << "First Name" << setw(20) << "Phone Number" << setw(20) << "Birthday" << endl; + for (int i = 0; i < sizeof(dispArray); i++) //Should only display filled entries + { + cout << setw(20) << i; + for (int j = 0; j < ARRAY_SIZE; j++) + { + cout << setw(20) << dispArray[i][j]; + } + cout << endl; + } +} + + +//PROGRAM 2 +//#include <iostream> +//#include <fstream> +//#include <string> +// +//using namespace std; +// +//#define ARRAY_SIZE 100 +// +//void getInput(char[ARRAY_SIZE]); +//void readFile(char[ARRAY_SIZE]); +// +//int main() +//{ +// char file_name[ARRAY_SIZE]; +// string sentences[ARRAY_SIZE]; +// +// getInput(file_name); +// readFile(file_name); +// +// return 0; +//} +// +//void getInput(char inputFileName[]) +//{ +// cout << "Please enter the file name: "; +// cin >> inputFileName; +//} +// +//void readFile(char readFileName[]) +//{ +// int i = 1, num_char = 0; +// string temp; +// +// +// ifstream inFile; +// inFile.open(readFileName); +// +// if (inFile.is_open()) +// { +// cout << "File is opened." << endl; +// while (!inFile.eof()) +// { +// getline(inFile, temp, '\n'); +// num_char = temp.length(); +// cout << i << ' ' << temp << ' ' << num_char << " characters in this string." << endl; +// i++; +// } +// } +// inFile.close(); +// return; +//} + + +//PROGRAM 1 +//#include <iostream> +//#include <string> +//#include <fstream> +//#include <stdio.h> +// +//using namespace std; +// +//#define ARRAY_SIZE 100 +//#define MAX_VALUES 10 +// +//void getInput(char[ARRAY_SIZE]); +//void readFile(int[MAX_VALUES], char[ARRAY_SIZE]); +//void findHiLo(int[MAX_VALUES]); +//void sortAscending(int[MAX_VALUES]); +// +//int main() +//{ +// +// +// char file_name[ARRAY_SIZE]{'\0'}; +// int integers[MAX_VALUES]{}; +// +// getInput(file_name); +// readFile(integers, file_name); +// findHiLo(integers); +// sortAscending(integers); +// return 0; +// +//} +// +//void getInput(char inputFileName[]) +//{ +// cout << "Please enter the file name: "; +// cin >> inputFileName; +//} +// +//void readFile(int readArray[], char readFileName[]) +//{ +// int i = 0; +// string temp_s; +// int temp_i = 0; +// +// ifstream inFile; +// inFile.open(readFileName); +// +// if (inFile.is_open()) +// { +// cout << "File is opened." << endl; +// while (!inFile.eof()) +// { +// while (i < MAX_VALUES) +// { +// getline(inFile, temp_s, ' '); +// temp_i = stoi(temp_s); +// readArray[i] = temp_i; +// i++; +// } +// } +// } +// inFile.close(); +// return; +//} +// +//void findHiLo(int findArray[]) +//{ +// int i = 1, high = 0, low = 0; +// low = findArray[0]; +// high = findArray[0]; +// while (i < MAX_VALUES) +// { +// if (low > findArray[i]) +// low = findArray[i]; +// if (high < findArray[i]) +// high = findArray[i]; +// i++; +// } +// +// cout << "The largest number is " << high << " and the smallest number is " << low << endl; +//} +// +//void sortAscending(int sortArray[]) +//{ +// int i = 0, j = 0, temp = 0; +// +// while (i < MAX_VALUES) +// { +// j = i + 1; +// while (j < MAX_VALUES) +// { +// if (sortArray[i] > sortArray[j]) +// { +// temp = sortArray[i]; +// sortArray[i] = sortArray[j]; +// sortArray[j] = temp; +// } +// j++; +// } +// i++; +// } +// +// i = 0; +// while (i < MAX_VALUES) +// { +// cout << sortArray[i] << endl; +// i++; +// } +//}
\ No newline at end of file diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj index fd67c6e..97d7b76 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj @@ -141,6 +141,11 @@ <ItemGroup> <ClCompile Include="CST116F2021-Lab9.cpp" /> </ItemGroup> + <ItemGroup> + <Text Include="..\337_Integers.txt" /> + <Text Include="..\337_Sentences.txt" /> + <Text Include="..\Runs.txt" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters index bb090d3..6d88e60 100644 --- a/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters +++ b/CST116F2021-Lab9/CST116F2021-Lab9.vcxproj.filters @@ -19,4 +19,9 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <Text Include="..\337_Integers.txt" /> + <Text Include="..\Runs.txt" /> + <Text Include="..\337_Sentences.txt" /> + </ItemGroup> </Project>
\ No newline at end of file |