Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the following UML diagram, write a class named AddressBook that stores a l

ID: 3585527 • Letter: U

Question

Using the following UML diagram, write a class named AddressBook that stores a list of names and phone numbers.

Submit your solution in it's own header file named AddressBook.h. It should be a plain text file.

Class Attributes:

1 Contact - a nested struct that stores the name and number of a contact.

name - stores the name of the contact.

phone - stores the phone number.

used is set to true if this record is currently being used, false otherwise

2 list - a Contact pointer, used to store the memory address for an array of dynamically allocated Contact structures.

3 cap - stores the number of elements in the array.

4 Constructor - dynamically allocates an array of Contacts, using it's argument to size the array. Initializes cap with it's argument. Initializes all Contact used fields to false.

5 Destructor - frees the dynamically allocated memory.

6 isEmpty - returns true of all used fields are set to false, true otherwise.

7 isFull - returns true if all used fields are set to true, false otherwise.

8 add - accepts the name and number of a contact as it's only arguments. Stores the information in one of the unused elements.

9 remove - accepts the name of a contact as it's only argument. Removes the first matching Contact from the array by marking it's used field to false.

10 clear - "empties" the array by setting all the element's used fields to false.

11 find - accepts the name of a contact as it's only argument. Returns the phone number of the first match it finds, "NO MATCH" otherwise.

Hints:

- Use the attached header file to get you started.

- Use the attached driver program to test your solution.

Here are the attached file given

1. AddressBook.h

2. testDriver.cpp

Please i need help with this question due in two days. Thanks

Explanation / Answer

#include<iostream>
#include "AddressBook.h"
using namespace std;
AddressBook::AddressBook(int a){
    list = new Contact[a];
    cap = a;
    for (int i = 0; i<a; i++){
         list[i].used = false;
         list[i].phone = "";
         list[i].name = "";
    }
}
AddressBook::~AddressBook(){
   delete[] list;
}
bool AddressBook::isEmpty() const{
   
    for (int i = 0; i<cap; i++){
       if (list[i].used)
          return false;
    }
    return true;
}
bool AddressBook::isFull() const{
   
    for (int i = 0; i<cap; i++){
       if (!list[i].used)
          return false;
    }
    return true;
}
void AddressBook::add(string a, string b){
   
    for (int i = 0; i<cap; i++){
       if (!list[i].used){
          list[i].name = a;
          list[i].phone = b;
          list[i].used = true;
          return;
       }
    }
}
void AddressBook::remove(string a){
   
    for (int i = 0; i<cap; i++){
       if (list[i].name == a){
          list[i].name = "";
          list[i].used = false;
       }
    }
}
void AddressBook::clear(){
   
    for (int i = 0; i<cap; i++){
          list[i].used = false;
          list[i].name = "";
          list[i].phone = "";
    }
}
string AddressBook::find(string a) const{
   
    for (int i = 0; i<cap; i++){
        if (list[i].name == a && list[i].used){
          return list[i].phone;
        }     
    }
    return "NO MATCH";
}