So here is the code from the previous assignment that we need to extend just follow the
instructions above.
main.cpp
#include
#include "Contact.h"
int main()
{
// create Contact object using parameterized constructor
Contact c1("Barbara", "Liskov", "Huberman", "404 Ridgeway Dr", "NC", "27403", "336-274-
3344");
// show contact details
c1.showContact();
cout << endl;
// create Contact object using default constructor
Contact c2;
// test the overloaded input and output operators
cin >> c2;
cout << endl;
cout << c2;
return 0;
}
Address.h
#ifndef ADDRESS_H
#define ADDRESS_H
#include
using namespace std;
// create a class named Address
class Address
{
private:
// private instance variables
string streetAddress, state, zip;
public:
// default constructor
Address()
{
// initialize instance variables with empty strings
streetAddress = "";
state = "";
zip = "";
}
// parameterized constructor
Address(string streetAddress, string state, string zip)
{
// initialize instance variables to given parameters
this->streetAddress = streetAddress;
this->state = state;
this->zip = zip;
}
// copy constructor
Address(const Address &a)
{
streetAddress = a.streetAddress;
state = a.state;
zip = a.zip;
}
// setters for all instance variables
void setStreetAddress(string streetAddress) { this->streetAddress = streetAddress; }
void setState(string state) { this->state = state; }
void setZip(string zip) { this->zip = zip; }
// getters for all instance variables
string getStreetAddress() { return streetAddress; }
string getState() { return state; }
string getZip() { return zip; }
// method to display the address
void showAddress()
{
cout << streetAddress << "n"
<< state << " " << zip << endl;
}
// declare the overloaded input and output operators
friend ostream &operator<<(ostream &out, const Address &a);
friend istream &operator>>(istream &in, Address &a);
};
// define the overloaded output operator
ostream &operator<<(ostream &out, const Address &a)
{
out << a.streetAddress << "n"
<< a.state << " " << a.zip << endl;
return out;
}
// define the overloaded input operator
istream &operator>>(istream &in, Address &a)
{
cout << "Enter street address: ";
getline(in, a.streetAddress);
cout << "Enter state: ";
getline(in, a.state);
cout << "Enter zip: ";
getline(in, a.zip);
return in;
}
#endif
Contact.h
#ifndef CONTACT_H
#define CONTACT_H
#include
#include "Name.h"
#include "Address.h"
using namespace std;
// create a class named Contact
class Contact
{
private:
// private instance variables
Name name;
Address address;
string phone;
public:
// default constructor
Contact()
{
// initialize phone with empty string
phone = "";
}
// parameterized constructor
Contact(string first_name, string last_name, string middle_name, string streetAddress, string
state, string zip, string phone)
{
// initialize name and address to given strings
setName(first_name, last_name, middle_name);
setAddress(streetAddress, state, zip);
// initialize phone to the given parameter
this->phone = phone;
}
// copy constructor
Contact(const Contact &c)
{
name = c.name;
address = c.address;
phone = c.phone;
}
// setters for all instance variables
void setName(string first_name, string last_name, string middle_name)
{
this->name.setFirst_Name(first_name);
this->name.setLast_Name(last_name);
this->name.setMiddle_Name(middle_name);
}
void setAddress(string streetAddress, string state, string zip)
{
this->address.setStreetAddress(streetAddress);
this->address.setState(state);
this->address.setZip(zip);
}
void setPhone(string phone) { this->phone = phone; }
// getters for all instance variables
string getName()
{
return name.getFirst_Name() + " " + name.getMiddle_Name() + " " + name.getMiddle_Name();
}
string getAddress()
{
return address.getStreetAddress() + ", " + address.getState() + " - " + address.getZip();
}
string getPhone() { return phone; }
// method to display the contact details
void showContact()
{
name.showName();
address.showAddress();
cout << phone << endl;
}
// declare the overloaded input and output operators
friend ostream &operator<<(ostream &out, const Contact &c);
friend istream &operator>>(istream &in, Contact &c);
};
// define the overloaded output operator
ostream &operator<<(ostream &out, const Contact &c)
{
out << c.name;
out << c.address;
out << c.phone << endl;
return out;
}
// define the overloaded input operator
istream &operator>>(istream &in, Contact &c)
{
in >> c.name;
in >> c.address;
cout << "Enter phone number: ";
getline(in, c.phone);
return in;
}
#endif
Name.h
#ifndef NAME_H
#define NAME_H
#include
using namespace std;
// create a class named Name
class Name
{
private:
// private instance variables
string first_name, last_name, middle_name;
public:
// default constructor
Name()
{
// initialize instance variables with empty strings
first_name = "";
last_name = "";
middle_name = "";
}
// parameterized constructor
Name(string first_name, string last_name, string middle_name)
{
// initialize instance variables to given parameters
this->first_name = first_name;
this->last_name = last_name;
this->middle_name = middle_name;
}
// copy constructor
Name(const Name &n)
{
first_name = n.first_name;
last_name = n.last_name;
middle_name = n.middle_name;
}
// setters for all instance variables
void setFirst_Name(string first_name) { this->first_name = first_name; }
void setLast_Name(string last_name) { this->last_name = last_name; }
void setMiddle_Name(string middle_name) { this->middle_name = middle_name; }
// getters for all instance variables
string getFirst_Name() { return first_name; }
string getLast_Name() { return last_name; }
string getMiddle_Name() { return middle_name; }
// method to display the name
void showName()
{
cout << last_name << ", " << first_name << " " << middle_name[0] << "." << endl;
}
// declare the overloaded input and output operators
friend ostream &operator<<(ostream &out, const Name &n);
friend istream &operator>>(istream &in, Name &n);
};
// define the overloaded output operator
ostream &operator<<(ostream &out, const Name &n)
{
out << n.last_name << ", " << n.first_name << " " << n.middle_name[0] << "." << endl;
return out;
}
// define the overloaded input operator
istream &operator>>(istream &in, Name &n)
{
cout << "Enter first name: ";
getline(in, n.first_name);
cout << "Enter last name: ";
getline(in, n.last_name);
cout << "Enter middle name: ";
getline(in, n.middle_name);
return in;
}
#endif The purpose of this assignment is to assess your ability to do the following: - Implement
a class with static data. - Implement classes utilizing aggregating relationships. - Utilize
aggregate objects in a software solution. - Utilize file input/output in a C++ program. For this
assignment, you will extend the Contact Management System 1 by creating a ContactManager
class to manage a collection of Contact objects. Before starting your assignment, ensure that your
Name, Address, and Contact class are error free. Step 1: Add a public static integer variable
called total Ct to the Contact class. Add a private integer instance variable called identifier and a
private member function, setIdentifier (), to the Contact class as shown below. Initialize totalct in
your .cpp file and implement setIdentifier() as shown here:
Declare a ContactManager class according to the given UML design. Implement the functions
according to the following specification: - The constructor needs an empty body. The job of the
constructor is to initialize the instance variables in the class. The instance variable here is a
vector that is initialized by the vector class constructor. There are no additional steps needed in
the ContactManager constructor. - getContact () takes an integer id and searches contacts to find
a Contact with a matching identifier. The matching Contact is returned. If no matching Contact is
found, return a default Contact object. - getContacts () takes a string l_name and searches the
contacts to find all Contact objects with a matching last name. The function returns a vector of
all matching Contact objects. - addContact() prompts the user for a new contact data, creates a
Contact object, and adds the contact to contacts. - showContact() displays the contacts in a
formatted output. - saveContacts() writes all of the contact data to the output source out. -
loadContacts() loads raw contact data from the input source in, assigns each Contact object an
identifier, and adds each Contact to contacts.

So here is the code from the previous assignment that we need to ext.pdf

  • 1.
    So here isthe code from the previous assignment that we need to extend just follow the instructions above. main.cpp #include #include "Contact.h" int main() { // create Contact object using parameterized constructor Contact c1("Barbara", "Liskov", "Huberman", "404 Ridgeway Dr", "NC", "27403", "336-274- 3344"); // show contact details c1.showContact(); cout << endl; // create Contact object using default constructor Contact c2; // test the overloaded input and output operators cin >> c2; cout << endl; cout << c2; return 0; } Address.h #ifndef ADDRESS_H #define ADDRESS_H #include using namespace std; // create a class named Address class Address { private: // private instance variables string streetAddress, state, zip;
  • 2.
    public: // default constructor Address() { //initialize instance variables with empty strings streetAddress = ""; state = ""; zip = ""; } // parameterized constructor Address(string streetAddress, string state, string zip) { // initialize instance variables to given parameters this->streetAddress = streetAddress; this->state = state; this->zip = zip; } // copy constructor Address(const Address &a) { streetAddress = a.streetAddress; state = a.state; zip = a.zip; } // setters for all instance variables void setStreetAddress(string streetAddress) { this->streetAddress = streetAddress; } void setState(string state) { this->state = state; } void setZip(string zip) { this->zip = zip; } // getters for all instance variables string getStreetAddress() { return streetAddress; } string getState() { return state; } string getZip() { return zip; } // method to display the address void showAddress() { cout << streetAddress << "n"
  • 3.
    << state <<" " << zip << endl; } // declare the overloaded input and output operators friend ostream &operator<<(ostream &out, const Address &a); friend istream &operator>>(istream &in, Address &a); }; // define the overloaded output operator ostream &operator<<(ostream &out, const Address &a) { out << a.streetAddress << "n" << a.state << " " << a.zip << endl; return out; } // define the overloaded input operator istream &operator>>(istream &in, Address &a) { cout << "Enter street address: "; getline(in, a.streetAddress); cout << "Enter state: "; getline(in, a.state); cout << "Enter zip: "; getline(in, a.zip); return in; } #endif Contact.h #ifndef CONTACT_H #define CONTACT_H #include #include "Name.h" #include "Address.h" using namespace std; // create a class named Contact class Contact
  • 4.
    { private: // private instancevariables Name name; Address address; string phone; public: // default constructor Contact() { // initialize phone with empty string phone = ""; } // parameterized constructor Contact(string first_name, string last_name, string middle_name, string streetAddress, string state, string zip, string phone) { // initialize name and address to given strings setName(first_name, last_name, middle_name); setAddress(streetAddress, state, zip); // initialize phone to the given parameter this->phone = phone; } // copy constructor Contact(const Contact &c) { name = c.name; address = c.address; phone = c.phone; } // setters for all instance variables void setName(string first_name, string last_name, string middle_name) { this->name.setFirst_Name(first_name); this->name.setLast_Name(last_name); this->name.setMiddle_Name(middle_name);
  • 5.
    } void setAddress(string streetAddress,string state, string zip) { this->address.setStreetAddress(streetAddress); this->address.setState(state); this->address.setZip(zip); } void setPhone(string phone) { this->phone = phone; } // getters for all instance variables string getName() { return name.getFirst_Name() + " " + name.getMiddle_Name() + " " + name.getMiddle_Name(); } string getAddress() { return address.getStreetAddress() + ", " + address.getState() + " - " + address.getZip(); } string getPhone() { return phone; } // method to display the contact details void showContact() { name.showName(); address.showAddress(); cout << phone << endl; } // declare the overloaded input and output operators friend ostream &operator<<(ostream &out, const Contact &c); friend istream &operator>>(istream &in, Contact &c); }; // define the overloaded output operator ostream &operator<<(ostream &out, const Contact &c) { out << c.name; out << c.address; out << c.phone << endl; return out;
  • 6.
    } // define theoverloaded input operator istream &operator>>(istream &in, Contact &c) { in >> c.name; in >> c.address; cout << "Enter phone number: "; getline(in, c.phone); return in; } #endif Name.h #ifndef NAME_H #define NAME_H #include using namespace std; // create a class named Name class Name { private: // private instance variables string first_name, last_name, middle_name; public: // default constructor Name() { // initialize instance variables with empty strings first_name = ""; last_name = ""; middle_name = ""; } // parameterized constructor Name(string first_name, string last_name, string middle_name) { // initialize instance variables to given parameters
  • 7.
    this->first_name = first_name; this->last_name= last_name; this->middle_name = middle_name; } // copy constructor Name(const Name &n) { first_name = n.first_name; last_name = n.last_name; middle_name = n.middle_name; } // setters for all instance variables void setFirst_Name(string first_name) { this->first_name = first_name; } void setLast_Name(string last_name) { this->last_name = last_name; } void setMiddle_Name(string middle_name) { this->middle_name = middle_name; } // getters for all instance variables string getFirst_Name() { return first_name; } string getLast_Name() { return last_name; } string getMiddle_Name() { return middle_name; } // method to display the name void showName() { cout << last_name << ", " << first_name << " " << middle_name[0] << "." << endl; } // declare the overloaded input and output operators friend ostream &operator<<(ostream &out, const Name &n); friend istream &operator>>(istream &in, Name &n); }; // define the overloaded output operator ostream &operator<<(ostream &out, const Name &n) { out << n.last_name << ", " << n.first_name << " " << n.middle_name[0] << "." << endl; return out; } // define the overloaded input operator
  • 8.
    istream &operator>>(istream &in,Name &n) { cout << "Enter first name: "; getline(in, n.first_name); cout << "Enter last name: "; getline(in, n.last_name); cout << "Enter middle name: "; getline(in, n.middle_name); return in; } #endif The purpose of this assignment is to assess your ability to do the following: - Implement a class with static data. - Implement classes utilizing aggregating relationships. - Utilize aggregate objects in a software solution. - Utilize file input/output in a C++ program. For this assignment, you will extend the Contact Management System 1 by creating a ContactManager class to manage a collection of Contact objects. Before starting your assignment, ensure that your Name, Address, and Contact class are error free. Step 1: Add a public static integer variable called total Ct to the Contact class. Add a private integer instance variable called identifier and a private member function, setIdentifier (), to the Contact class as shown below. Initialize totalct in your .cpp file and implement setIdentifier() as shown here: Declare a ContactManager class according to the given UML design. Implement the functions according to the following specification: - The constructor needs an empty body. The job of the constructor is to initialize the instance variables in the class. The instance variable here is a vector that is initialized by the vector class constructor. There are no additional steps needed in the ContactManager constructor. - getContact () takes an integer id and searches contacts to find a Contact with a matching identifier. The matching Contact is returned. If no matching Contact is found, return a default Contact object. - getContacts () takes a string l_name and searches the contacts to find all Contact objects with a matching last name. The function returns a vector of all matching Contact objects. - addContact() prompts the user for a new contact data, creates a Contact object, and adds the contact to contacts. - showContact() displays the contacts in a formatted output. - saveContacts() writes all of the contact data to the output source out. - loadContacts() loads raw contact data from the input source in, assigns each Contact object an identifier, and adds each Contact to contacts.