Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include PhoneBook.h #include Contact.h #include // constructor ----------- PhoneBook::PhoneBook(Contact * contacts, int _numContacts){ if (_numContacts){ numContacts = _numContacts; contactList = new Contact [numContacts]; for (int

#include "PhoneBook.h"

#include "Contact.h"

#include

// constructor -----------

PhoneBook::PhoneBook(Contact * contacts, int _numContacts){

if (_numContacts){

numContacts = _numContacts;

contactList = new Contact [numContacts];

for (int i = 0; i < numContacts; i++){

contactList[i] = Contact((contacts+i)->getName(),

(contacts+i)->getPhoneNumber(),

*(contacts+i)->getEmergencyContact());

}

}

}

// accessors ---------------------

int PhoneBook::getNumberByName(const string _name) const {

// steps through the list of contacts and compares each name to the

// parameter _name and returns the phone number if found.

// if not found, return -1.

// NOTE: remember that '==' is not sufficient for string compare.

//

// CODE HERE

return -1; // None found

}

string PhoneBook::getNameByNumber(const int _number) const {

// steps through the list of contacts and compares each number to the

// parameter _number and returns the name if found.

// if not found, return NULL.

//

// CODE HERE

return NULL; // None found

}

// call to print all Contacts from the given PhoneBook

// print format is a different contact on each line, and each

// line contains:

// name phoneNumber emergencyContact

void PhoneBook::printAllContacts() const {

std::cout << " num contacts: " << numContacts << std::endl;

for (int i = 0; i < numContacts; i++){

std::cout << contactList[i].getName() << " " <<

contactList[i].getPhoneNumber() << " " <<

contactList[i].getEmergencyContact() << std::endl;

}

}

void PhoneBook::verifyAllContacts(){

// From the given PhoneBook object, call the verifyPhoneNumber()

// from each of the Contacts contained in the private variable

// contactList, and also on the emergency contacts from each of

// the contacts.

// Remove all Contacts that do not have a valid phoneNumber from the

// array (and just remove invalid emergencyContacts from valid Contacts,

// do not remove entire Contact from array) and resize the array so

// that there are no gaps after removing the Contacts.

// HINT: resizing an array is hard... it is sometimes easier to simply

// make a new one.

//

// CODE GOES HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Is this investment worthwhile? Why or why not?

Answered: 1 week ago