Question: C++ Programing Project converting to UML Diagram (no code needed) C++ Programming Rolodex Program, ***************** Must have user interaction to: 1. Add new contacts 2.

C++ Programing Project converting to UML Diagram (no code needed)

C++ Programming Rolodex Program,

*****************

Must have user interaction to:

1. Add new contacts

2. Edit Existing contacts

3. Remove Existing Contacts

4. List All Contacts

5. Add three phone numbers for Contacts

6. Remove Phone From Contact

7. Quit Application

Code provided in body:

1. ContactRecord.h Each contact can have more than one phone numbers (up to 3 to be exact). The phone numbers to be stored are for HOME, WORK, or MOBILE.

2. ContactRecord.cpp Look for all methods that have TODO markers since I don't know what to code there.

3. ContactDataManager.h To support multiple phone numbers per contact, the ContactDataManager class is now expanded to include new methods to handle/manage the list of phone numbers per contact.

4. ContactDataManager.cpp Look for all methods that have TODO markersince I don't know what to code there.

5. ContactDataInputManager.h The ContactDataInputManager class drives all the user interactions which allow him/her to add, edit, remove contacts as well as their phone numbers.

6. ContactDataInputManager.cpp Look for all methods that have TODO markersince I don't know what to code there.

7. PhoneRecord.h - No work needed, this is part of the project to better understand

8. Main.cpp - No work needed, this is part of the project to better understand

***************************

1. ContactRecord.h Each contact can have more than one phone numbers (up to 3 to be exact). The phone numbers to be stored are for HOME, WORK, or MOBILE.

***************************

#pragma once

#include

#include

#include

#include "PhoneRecord.h"

using namespace std;

class ContactRecord

{

private:

int ContactID;

string FirstName;

string LastName;

string MiddleName;

vector PhoneNumberList;

private:

inline string FromPhoneTypeToString(PHONE_TYPE phoneType) const

{

switch (phoneType)

{

case HOME: return "HOME";

case WORK: return "WORK";

case MOBILE: return "MOBILE";

default: return "HOME";

}

}

private:

void CopyData(const ContactRecord & src);

public:

int GetContactID() { return this->ContactID; }

string GetFirstName() { return this->FirstName; }

string GetLastName() { return this->LastName; }

string GetMiddleName() { return this->MiddleName; }

void SetContactID(int v) { this->ContactID = v;}

void SetFirstName(string v) { this->FirstName = v; }

void SetLastName(string v) { this->LastName = v; }

void SetMiddleName(string v) { this->MiddleName = v; }

vector GetPhoneNumberList() const;

bool GetPhoneNumberByType(PHONE_TYPE phoneType, PhoneRecord & phoneInfo) const;

bool AddPhoneNumber(PHONE_TYPE phoneType, string phoneNumber);

bool UpdatePhoneNumber(PHONE_TYPE phoneType, string phoneNumber);

bool DeletePhoneNumber(PHONE_TYPE phoneType);

public:

void Print() const;

public:

ContactRecord();

ContactRecord(string firstName, string lastName, string middleName);

ContactRecord(const ContactRecord & src);

public:

const ContactRecord & operator=(const ContactRecord & src);

bool operator==(const ContactRecord & src);

};

***************************

2. ContactRecord.cpp Look for all methods that have TODO markers since I don't know what to code there.

***************************

#include "ContactRecord.h"

bool ContactRecord::AddPhoneNumber(PHONE_TYPE phoneType, string phoneNumber)

{

// TODO: Need to implement this method.

}

bool ContactRecord::UpdatePhoneNumber(PHONE_TYPE phoneType, string phoneNumber)

{

// TODO: Need to implement this method.

}

bool ContactRecord::DeletePhoneNumber(PHONE_TYPE phoneType)

{

// TODO: Need to implement this method.

}

void ContactRecord::Print() const

{

cout << "ID: " << this->ContactID << ", "

<< "Last Name: " << this->LastName << ", "

<< "First Name: " << this->FirstName << ", "

<< "Middle Name: " << this->MiddleName << endl

<< "Phone Numbers: " << endl;

for (size_t i = 0; i < this->PhoneNumberList.size(); i++)

{

cout << " - (" << FromPhoneTypeToString(this->PhoneNumberList[i].Type) << ") "

<< this->PhoneNumberList[i].PhoneNumber

<< endl;

}

}

ContactRecord::ContactRecord()

{

this->FirstName = "";

this->LastName = "";

this->MiddleName = "";

this->ContactID = 0;

}

ContactRecord::ContactRecord(string firstName, string lastName, string middleName) :

FirstName(firstName),

LastName(lastName),

MiddleName(middleName),

ContactID(0)

{

}

ContactRecord::ContactRecord(const ContactRecord & src)

{

CopyData(src);

}

void ContactRecord::CopyData(const ContactRecord & src)

{

// TODO: Need to implement this method.

}

vector ContactRecord::GetPhoneNumberList() const

{

// TODO: Need to implement this method.

}

bool ContactRecord::GetPhoneNumberByType(PHONE_TYPE phoneType, PhoneRecord & phoneInfo) const

{

// TODO: Need to implement this method.

}

const ContactRecord & ContactRecord::operator=(const ContactRecord & src)

{

CopyData(src);

return *this;

}

bool ContactRecord::operator==(const ContactRecord & src)

{

return (this->ContactID == src.ContactID);

}

***************************

3. ContactDataManager.h To support multiple phone numbers per contact, the ContactDataManager class is now expanded to include new methods to handle/manage the list of phone numbers per contact.

***************************

#pragma once

#include

#include "ContactRecord.h"

class ContactDataManager

{

private:

static int NextContactID;

private:

vector ContactList;

private:

void CopyData(const ContactDataManager & src);

ContactRecord * FindContactByID(int nContactID);

public:

ContactDataManager();

ContactDataManager(const ContactDataManager & src);

public:

size_t GetContactCount();

int AddContact(string firstName, string lastName, string middleName);

bool EditContact(int nContactID, string firstName, string lastName, string middleName);

bool AddPhoneNumber(int nContactID, PHONE_TYPE phoneType, string phoneNumber);

bool UpdatePhoneNumber(int nContactID, PHONE_TYPE phoneType, string phoneNumber);

bool RemovePhoneNumber(int nContactID, PHONE_TYPE phoneType);

vector GetPhoneNumberList(int nContactID);

bool RemoveContact(int nContactID);

bool RetrieveContact(int nContactID, ContactRecord & contact);

vector GetContactIDs();

public:

const ContactDataManager & operator=(const ContactDataManager & src);

};

***************************

4. ContactDataManager.cpp Look for all methods that have TODO markersince I don't know what to code there.

***************************

#include "ContactDataManager.h"

int ContactDataManager::NextContactID = 0;

void ContactDataManager::CopyData(const ContactDataManager & src)

{

this->ContactList.clear();

for (size_t i = 0; i < src.ContactList.size(); i++)

{

this->ContactList.push_back(src.ContactList[i]);

}

}

ContactRecord * ContactDataManager::FindContactByID(int nContactID)

{

for (size_t i = 0; i < this->ContactList.size(); i++)

{

if (this->ContactList[i].GetContactID() == nContactID)

return &this->ContactList[i];

}

return NULL;

}

ContactDataManager::ContactDataManager()

{

}

ContactDataManager::ContactDataManager(const ContactDataManager & src)

{

CopyData(src);

}

size_t ContactDataManager::GetContactCount()

{

return this->ContactList.size();

}

int ContactDataManager::AddContact(string firstName, string lastName, string middleName)

{

ContactRecord rec(firstName, lastName, middleName);

rec.SetContactID(++ContactDataManager::NextContactID);

this->ContactList.push_back(rec);

return rec.GetContactID();

}

bool ContactDataManager::EditContact(int nContactID, string firstName, string lastName, string middleName)

{

for (size_t i = 0; i < this->ContactList.size(); i++)

{

ContactRecord & rec = this->ContactList[i];

if (rec.GetContactID() == nContactID)

{

rec.SetFirstName(firstName);

rec.SetLastName(lastName);

rec.SetMiddleName(middleName);

return true;

}

}

return false;

}

bool ContactDataManager::AddPhoneNumber(int nContactID, PHONE_TYPE phoneType, string phoneNumber)

{

// TODO: Need to implement this method.

}

bool ContactDataManager::UpdatePhoneNumber(int nContactID, PHONE_TYPE phoneType, string phoneNumber)

{

// TODO: Need to implement this method.

}

bool ContactDataManager::RemovePhoneNumber(int nContactID, PHONE_TYPE phoneType)

{

// TODO: Need to implement this method.

}

vector ContactDataManager::GetPhoneNumberList(int nContactID)

{

// TODO: Need to implement this method.

}

bool ContactDataManager::RemoveContact(int nContactID)

{

for (std::vector::iterator it = this->ContactList.begin(); it != this->ContactList.end(); ++it)

{

ContactRecord & rec = *it;

if (rec.GetContactID() == nContactID)

{

this->ContactList.erase(it);

return true;

}

}

return false;

}

bool ContactDataManager::RetrieveContact(int nContactID, ContactRecord & contact)

{

ContactRecord * pRec = FindContactByID(nContactID);

if (!pRec)

return false;

contact = *pRec;

return true;

}

vector ContactDataManager::GetContactIDs()

{

vector contactIds;

for (std::vector::iterator it = this->ContactList.begin(); it != this->ContactList.end(); ++it)

{

ContactRecord & rec = *it;

contactIds.push_back(rec.GetContactID());

}

return contactIds;

}

const ContactDataManager & ContactDataManager::operator=(const ContactDataManager & src)

{

CopyData(src);

return *this;

}

***************************

5. ContactDataInputManager.h The ContactDataInputManager class drives all the user interactions which allow him/her to add, edit, remove contacts as well as their phone numbers.

***************************

#pragma once

#include

#include "ContactDataManager.h"

class ContactDataInputManager

{

private:

ContactDataManager * pContactDataManager;

private:

string WaitForDataLine();

int WaitForNumericValue();

int WaitForNumericSelection();

int WaitForMainOptionSelection();

PHONE_TYPE FromStringToPhoneType(string type) const;

private:

void AddNewContact();

void EditExistingContact();

void RemoveExistingContact();

void DisplayAllExistingContacts();

void AddPhoneNumberForContact();

void RemovePhoneFromContact();

public:

ContactDataInputManager(ContactDataManager & contactDataManager);

public:

void Run();

private:

// Prevent from copying and assigning.

ContactDataInputManager(const ContactDataInputManager & src);

const ContactDataInputManager & operator=(const ContactDataInputManager & src);

};

***************************

6. ContactDataInputManager.cpp Look for all methods that have TODO markersince I don't know what to code there.

***************************

#include

#include

#include

#include

#include

#include "ContactDataInputManager.h"

string ContactDataInputManager::WaitForDataLine()

{

// Get data line.

string dataLine;

std::getline(cin, dataLine);

// Left trim for spaces.

dataLine.erase(dataLine.begin(), std::find_if(dataLine.begin(), dataLine.end(), std::not1(std::ptr_fun(std::isspace))));

// Right trim for spaces.

dataLine.erase(std::find_if(dataLine.rbegin(), dataLine.rend(), std::not1(std::ptr_fun(std::isspace))).base(), dataLine.end());

return dataLine;

}

int ContactDataInputManager::WaitForNumericValue()

{

try

{

string dataLine = WaitForDataLine();

return atoi(dataLine.c_str());

}

catch (...)

{

return -1;

}

}

int ContactDataInputManager::WaitForNumericSelection()

{

// First character will be the actual selection.

int selection = std::getchar();

if (selection == EOF)

return -1;

// The second character is the newline (caused by pressing the ENTER button).

int newline = std::getchar();

// Return the selection;

if ((selection >= '0') && (selection <= '9'))

return (selection - '0');

return -1;

}

int ContactDataInputManager::WaitForMainOptionSelection()

{

cout << "[MAIN MENU]" << endl

<< "Select the one of the below options:" << endl

<< " (1) Add new contact" << endl

<< " (2) Edit existing contact" << endl

<< " (3) Remove existing contact" << endl

<< " (4) List all contacts" << endl

<< " (5) Add phone number for contact" << endl

<< " (6) Remove phone from contact" << endl

<< " (7) Quit application" << endl

<< "==> ";

return WaitForNumericSelection();

}

PHONE_TYPE ContactDataInputManager::FromStringToPhoneType(string type) const

{

if (type.length() == 0)

return HOME;

transform(type.begin(), type.end(), type.begin(), ::toupper);

if (type == "HOME")

return HOME;

if (type == "WORK")

return WORK;

if (type == "MOBILE")

return MOBILE;

return HOME;

}

void ContactDataInputManager::AddNewContact()

{

cout << endl;

cout << "[ADD NEW CONTACT]" << endl;

cout << "Enter first name: ";

string firstName = WaitForDataLine();

cout << "Enter last name: ";

string lastName = WaitForDataLine();

cout << "Enter middle name: ";

string middleName = WaitForDataLine();

// TODO: Need to provide additional code to complete this method.

}

void ContactDataInputManager::EditExistingContact()

{

cout << endl;

cout << "[EDIT EXISTING CONTACT]" << endl;

cout << "Enter contact ID: ";

int contactID = WaitForNumericValue();

cout << "Enter first name: ";

string firstName = WaitForDataLine();

cout << "Enter last name: ";

string lastName = WaitForDataLine();

cout << "Enter middle name: ";

string middleName = WaitForDataLine();

// TODO: Need to provide additional code to complete this method.

}

void ContactDataInputManager::RemoveExistingContact()

{

cout << endl;

cout << "[REMOVE EXISTING CONTACT]" << endl;

cout << "Enter contact ID: ";

int contactID = WaitForNumericValue();

// TODO: Need to provide additional code to complete this method.

}

void ContactDataInputManager::DisplayAllExistingContacts()

{

cout << endl;

cout << "[AVAILABLE CONTACTS]" << endl;

// TODO: Need to provide additional code to complete this method.

}

void ContactDataInputManager::AddPhoneNumberForContact()

{

cout << endl;

cout << "[ADD PHONE NUMBER FOR CONTACT]" << endl;

cout << "Enter contact ID: ";

int contactID = WaitForNumericValue();

cout << "Enter phone number: ";

string phoneNumber = WaitForDataLine();

cout << "Enter phone type (HOME, WORK, MOBILE): ";

string phoneTypeText = WaitForDataLine();

PHONE_TYPE phoneTypeEnum = FromStringToPhoneType(phoneTypeText);

// TODO: Need to provide additional code to complete this method.

}

void ContactDataInputManager::RemovePhoneFromContact()

{

cout << endl;

cout << "[REMOVE PHONE FROM CONTACT]" << endl;

cout << "Enter contact ID: ";

int contactID = WaitForNumericValue();

cout << "Enter phone type (HOME, WORK, MOBILE): ";

string phoneTypeText = WaitForDataLine();

PHONE_TYPE phoneTypeEnum = FromStringToPhoneType(phoneTypeText);

// TODO: Need to provide additional code to complete this method.

}

ContactDataInputManager::ContactDataInputManager(ContactDataManager & contactDataManager)

{

this->pContactDataManager = &contactDataManager;

}

void ContactDataInputManager::Run()

{

bool loop = true;

while (loop)

{

int mainSelection = WaitForMainOptionSelection();

switch (mainSelection)

{

case 1:

AddNewContact();

break;

case 2:

EditExistingContact();

break;

case 3:

RemoveExistingContact();

break;

case 4:

DisplayAllExistingContacts();

break;

case 5:

AddPhoneNumberForContact();

break;

case 6:

RemovePhoneFromContact();

break;

case 7:

loop = false;

break;

default:

break;

}

}

}

ContactDataInputManager::ContactDataInputManager(const ContactDataInputManager & src)

{

throw new exception("The ContactDataInputManager object cannot be assigned or copied!");

}

const ContactDataInputManager & ContactDataInputManager::operator=(const ContactDataInputManager & src)

{

throw new exception("The ContactDataInputManager object cannot be assigned or copied!");

}

***************************

7. PhoneRecord.h - No work needed, this is part of the project to better understand

***************************

#pragma once

#include

#include

using namespace std;

typedef enum

{

HOME,

WORK,

MOBILE

} PHONE_TYPE;

struct PhoneRecord

{

PHONE_TYPE Type;

string PhoneNumber;

};

***************************

8. Main.cpp - No work needed, this is part of the project to better understand

***************************

#include "ContactRecord.h"

#include "ContactDataManager.h"

#include "ContactDataInputManager.h"

int main(int argc, char *argv[], char *envp[])

{

ContactDataManager contactDataManager;

ContactDataInputManager ContactDataInputManager(contactDataManager);

ContactDataInputManager.Run();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!