Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions PhoneDirectory/Array_Based_PD.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions PhoneDirectory/Array_Based_PD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions PhoneDirectory/PD_Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand Down