// CST116F2021-Lab9.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include 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() { 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; } 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 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 //#include //#include // //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 //#include //#include //#include // //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++; // } //}