diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index 4f3ee7a..c6b95e7 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -1,4 +1,4 @@ -/** Implementation of the Phone_Directory using an array +/** Implementation of the Phone_Directory using an array of entries @author Koffman and Wolfgang */ @@ -115,12 +115,33 @@ void Phone_Directory::save() */ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please complete the remove_entry() method - Ed/Kent { + // calling function find to return me the index of array where the name the user wants to delete is located + int index = find(name); + // Checks to see if that name is not in the directory else if the name is in the directory the next step is to delete it + if (index == -1) { + return ""; + } + else { + // Gets the full number on directory from index for example xxx-xxx-xxxx + string usernumber = the_directory[index].get_number(); + for (int i = index; i < size - 1; i++) { + //shifts the directory and rewrites the shifted directory to the same one + the_directory[i] = the_directory[i + 1]; + //reduces the size of the directory by one each time it goes throught the loop + size--; + // returns the number + return usernumber; + } + + } + + - // Hint: you can use the code below to shift names down in the directory to remove the selected entry specified by "index" - // for (int i = index; i < size - 1; i++) + // Hint: you can use the code below to shift names down in the directory to remove the selected entry specified by "index" + // for (int i = index; i < size - 1; i++) // the_directory[i] = the_directory[i + 1]; - return ""; + //return ""; } // Private method implementation diff --git a/PhoneDirectory/Array_Based_PD.h b/PhoneDirectory/Array_Based_PD.h index 663a9c5..6e114d2 100644 --- a/PhoneDirectory/Array_Based_PD.h +++ b/PhoneDirectory/Array_Based_PD.h @@ -55,10 +55,26 @@ class Phone_Directory private: class Directory_Entry /* Exercise 1.6: Please complete the definition of the Directory_Entry class here. - Ed/Kent */ { - public: + public: + Directory_Entry() {} // Default no-argument constructor + Directory_Entry(std::string the_name, std::string the_number) { + name = the_name; + number = the_number; + // constructor not implemented yet + } + std::string get_name() const { + return name; // method not implemented yet + } + std::string get_number() const { + return number; // method not implemented yet + } + void set_number(const std::string& new_number) { + number = new_number; // method not implemented yet + } private: - + std::string name; + std::string number; }; // Private Functions diff --git a/PhoneDirectory/PD_Application.cpp b/PhoneDirectory/PD_Application.cpp index d0bbda9..4cc33f5 100644 --- a/PhoneDirectory/PD_Application.cpp +++ b/PhoneDirectory/PD_Application.cpp @@ -90,6 +90,9 @@ void do_remove_entry(Phone_Directory& the_directory) // Exercise 1.8: please com string name; cout << "Enter name: "; getline(cin, name); + string deletednum = the_directory.remove_entry(name); + cout << deletednum << "has been deleted" << endl; + // Complete the rest of this function }