From 1eced3ec265cbfdae8c28af1f77bf73a105066e4 Mon Sep 17 00:00:00 2001 From: joronia Date: Wed, 11 Feb 2015 13:43:28 -0800 Subject: [PATCH 1/9] Class Array_based_PD.h description class --- PhoneDirectory/Array_Based_PD.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PhoneDirectory/Array_Based_PD.h b/PhoneDirectory/Array_Based_PD.h index 663a9c5..57845bb 100644 --- a/PhoneDirectory/Array_Based_PD.h +++ b/PhoneDirectory/Array_Based_PD.h @@ -56,7 +56,19 @@ class Phone_Directory class Directory_Entry /* Exercise 1.6: Please complete the definition of the Directory_Entry class here. - Ed/Kent */ { public: - + Directory_Entry() {} // Default no-argument constructor + Directory_Entry(std::string the_name, std::string the_number) { + // constructor not implemented yet + } + std::string get_name() const { + return ""; // method not implemented yet + } + std::string get_number() const { + return ""; // method not implemented yet + } + void set_number(const std::string& new_number) { + // method not implemented yet + } private: }; From 4873a5192a828d5e71f7f364e7a4079158764b2a Mon Sep 17 00:00:00 2001 From: joronia Date: Fri, 13 Feb 2015 18:30:40 -0800 Subject: [PATCH 2/9] Fixed class --- PhoneDirectory/Array_Based_PD.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PhoneDirectory/Array_Based_PD.h b/PhoneDirectory/Array_Based_PD.h index 57845bb..6e114d2 100644 --- a/PhoneDirectory/Array_Based_PD.h +++ b/PhoneDirectory/Array_Based_PD.h @@ -55,22 +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: 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 ""; // method not implemented yet + return name; // method not implemented yet } std::string get_number() const { - return ""; // method not implemented yet + return number; // method not implemented yet } void set_number(const std::string& new_number) { - // method not implemented yet + number = new_number; // method not implemented yet } private: - + std::string name; + std::string number; }; // Private Functions From 5e19c7e62dde915e22c125228de61e73c0de6295 Mon Sep 17 00:00:00 2001 From: joronia Date: Fri, 13 Feb 2015 19:28:07 -0800 Subject: [PATCH 3/9] Fix --- PhoneDirectory/Array_Based_PD.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index 4f3ee7a..de05f63 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -115,12 +115,22 @@ void Phone_Directory::save() */ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please complete the remove_entry() method - Ed/Kent { - + int index = find(name); + if (the_directory[index].get_name() == name) { + for(int i = index; i < size - 1; i++) { + the_directory[i] = the_directory[i + 1]; + } + } + else { + return "This name is not in the directory."; + } + + // 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 From 693696c1989112922b974bd946fb0af987c61d99 Mon Sep 17 00:00:00 2001 From: joronia Date: Fri, 13 Feb 2015 19:43:20 -0800 Subject: [PATCH 4/9] Finished HW Assignment --- PhoneDirectory/PD_Application.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PhoneDirectory/PD_Application.cpp b/PhoneDirectory/PD_Application.cpp index d0bbda9..46ed88a 100644 --- a/PhoneDirectory/PD_Application.cpp +++ b/PhoneDirectory/PD_Application.cpp @@ -90,6 +90,7 @@ void do_remove_entry(Phone_Directory& the_directory) // Exercise 1.8: please com string name; cout << "Enter name: "; getline(cin, name); + the_directory.remove_entry(name); // Complete the rest of this function } From b5922816b03470c173aee9c8262c29d890b9a09d Mon Sep 17 00:00:00 2001 From: joronia Date: Mon, 16 Feb 2015 14:00:30 -0800 Subject: [PATCH 5/9] fix --- PhoneDirectory/Array_Based_PD.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index de05f63..dd521d5 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -115,7 +115,9 @@ void Phone_Directory::save() */ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please complete the remove_entry() method - Ed/Kent { + int index = find(name); + if (index == -1) if (the_directory[index].get_name() == name) { for(int i = index; i < size - 1; i++) { the_directory[i] = the_directory[i + 1]; From 90fec467f5a4f4f607aade46dbecbaf957a6cd12 Mon Sep 17 00:00:00 2001 From: joronia Date: Mon, 16 Feb 2015 17:22:58 -0800 Subject: [PATCH 6/9] Fixed HW problem --- PhoneDirectory/Array_Based_PD.cpp | 38 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index dd521d5..24b840c 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,24 +115,30 @@ void Phone_Directory::save() */ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please complete the remove_entry() method - Ed/Kent { - - int index = find(name); - if (index == -1) - if (the_directory[index].get_name() == name) { - for(int i = index; i < size - 1; i++) { - the_directory[i] = the_directory[i + 1]; + int index = find(name); + if (index == -1) { + return ""; } - } - else { - return "This name is not in the directory."; - } - - - // 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++) + else { + modified = true; + Directory_Entry* new_directory = new Directory_Entry[capacity]; + for (int i = index; i < size - 1; i++) { + new_directory[i] = the_directory[i + 1]; + return ""; + } + delete[] the_directory; + the_directory = new_directory; + return ""; + + } + + + + // 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 From 13b18d9609f22d154d769e723d24a055fffe969d Mon Sep 17 00:00:00 2001 From: joronia Date: Mon, 16 Feb 2015 17:23:45 -0800 Subject: [PATCH 7/9] Fixed HW Problem --- PhoneDirectory/Array_Based_PD.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index 24b840c..6ca9759 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -128,8 +128,7 @@ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please } delete[] the_directory; the_directory = new_directory; - return ""; - + } @@ -138,7 +137,7 @@ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please // for (int i = index; i < size - 1; i++) // the_directory[i] = the_directory[i + 1]; - //return ""; + return ""; } // Private method implementation From b7f14ddf63cdc342cf7ac6fdf8bc545077e98d14 Mon Sep 17 00:00:00 2001 From: joronia Date: Mon, 16 Feb 2015 17:48:18 -0800 Subject: [PATCH 8/9] Fixed HW problems --- PhoneDirectory/Array_Based_PD.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index 6ca9759..6117bea 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -115,18 +115,25 @@ 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 { + // Is going to be modified modified = true; + // new directory to hold the updated directory with out the person you dont want in the directory. Directory_Entry* new_directory = new Directory_Entry[capacity]; for (int i = index; i < size - 1; i++) { + // shifting the directory over 1 spot and copying the index all of them minus the one the user deleted to new_directory new_directory[i] = the_directory[i + 1]; return ""; } + // delete the old directory given delete[] the_directory; + // copy the new_directory array to the main the_directory the_directory = new_directory; } From 5a53e3c66e7826a39b30bde2131b4ffad52c3005 Mon Sep 17 00:00:00 2001 From: joronia Date: Mon, 16 Feb 2015 18:14:41 -0800 Subject: [PATCH 9/9] Finished Product --- PhoneDirectory/Array_Based_PD.cpp | 23 ++++++++++------------- PhoneDirectory/PD_Application.cpp | 4 +++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/PhoneDirectory/Array_Based_PD.cpp b/PhoneDirectory/Array_Based_PD.cpp index 6117bea..c6b95e7 100644 --- a/PhoneDirectory/Array_Based_PD.cpp +++ b/PhoneDirectory/Array_Based_PD.cpp @@ -122,21 +122,18 @@ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please return ""; } else { - // Is going to be modified - modified = true; - // new directory to hold the updated directory with out the person you dont want in the directory. - Directory_Entry* new_directory = new Directory_Entry[capacity]; + // 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++) { - // shifting the directory over 1 spot and copying the index all of them minus the one the user deleted to new_directory - new_directory[i] = the_directory[i + 1]; - return ""; + //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; } - // delete the old directory given - delete[] the_directory; - // copy the new_directory array to the main the_directory - the_directory = new_directory; - } + } @@ -144,7 +141,7 @@ string Phone_Directory::remove_entry(const string& name) // Exercise 1.7: please // for (int i = index; i < size - 1; i++) // the_directory[i] = the_directory[i + 1]; - return ""; + //return ""; } // Private method implementation diff --git a/PhoneDirectory/PD_Application.cpp b/PhoneDirectory/PD_Application.cpp index 46ed88a..4cc33f5 100644 --- a/PhoneDirectory/PD_Application.cpp +++ b/PhoneDirectory/PD_Application.cpp @@ -90,7 +90,9 @@ void do_remove_entry(Phone_Directory& the_directory) // Exercise 1.8: please com string name; cout << "Enter name: "; getline(cin, name); - the_directory.remove_entry(name); + string deletednum = the_directory.remove_entry(name); + cout << deletednum << "has been deleted" << endl; + // Complete the rest of this function }