So here is the code from the previous assignment that we need to ext.pdf
1. 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;
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 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);
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.