Assignment 6

Extend the C++ program Assignment6 that you will be given.

Assignment6 includes 3 classes and a Main routine. The classes are Customer, CustomerAddress, and Utils. The first two classes have been defined for you. We will discuss them in class. Your work for this assignment is to write some of the methods in the Utils class.

Utils Class

The Utils class is made up primarily of static methods, as shown below You will implement the methods findCustomerAddress, linkCustomersToAddresses, and readCustomerAddresses.

classUtils {

public:

// The files the program reads to build the customer and customer

// address vectors; values assigned in .cpp file

conststatic std::stringCUSTOMER_INPUT_FILE;

conststatic std::stringCUSTOMER_ADDRESS_INPUT_FILE;

Utils();

staticCustomerAddress* findCustomerAddress (Customer *,

std::vectorCustomerAddress *>) ;

staticvoidlinkCustomersToAddresses (std::vectorCustomer *>,

std::vectorCustomerAddress*>);

static std::vectorCustomer *> readCustomerData ();

static std::vectorCustomerAddress *> readCustomerAddresses ();

virtual~Utils();

Method findCustomerAddress

This method takes two arguments:

  • A Customer instance that holds the id (an int) of the CustomerAddress in the vector of CustomerAddresses.
  • A vector of CustomerAddress pointers, one of which points to the object that is this customer’s address.

Your implementation should search the vector of CustomerAddress values to find the right address object. Your code should use a binary search to perform the search operation. Note: the values in the vector are in sorted ascending order by id.

This method returns the following:

  • A pointer to the correct address object or nullptr if no correct object exists.

Method linkCustomersToAddresses

This method returns the following:

  • A vector of Customerpointers

This method performs the following:

  • Links each Customer instance to the unique CustomerAddress object that is its address. That is,the code should set the pointer in Customer to point to the CustomerAddress object whose id is stored in the Customer instance

Method readCustomerData

This method performs the following:

  • Reads data from a comma delimited file of customer information; this file has a header which should be read but ignored. The data on the file was extracted from a spreadsheet and has the typical CSV format as noted in the samples that follow.

customer_id,first_name,last_name,email,address_id \n

The implementation should mimic that in readCustomerAddresses, but be specialized to read values for Customer and not addresses.

This method returns the following:

  • A vector of Customerpointers

The “Starter Pack”

Your starting point for this assignment is an Eclipse project with most of the classes already implemented. This project will be available on TRACS as a .zip archive. Download the project, unzip it, and import it into the Eclipse IDE.

Your mission is to modify the three methods in Utils so those methods meet the requirements described. The places in the code where your modifications should occur are clearly marked.

When complete, create a .zip archive of the completed Eclipse project and submit it via TRACS.

CustomerAddress * Utils:: findCustomerAddress (Customer *customer, std::vectorCustomerAddress *> addresses) {

int customerAddressId = customer->getCustomerAddressId();

int lowerBound = 0;

int upperBound = addresses.size() - 1;

int middle = upperBound / 2;

CustomerAddress *address = nullptr;

//****************************

//

// Write the code that will perform the binary search and return

// the matching address

//

//****************************

return address;

}

voidUtils:: linkCustomersToAddresses (std::vectorCustomer *> customers, std::vectorCustomerAddress*> addresses) {

//****************************

//

// Write the code that will link customers to their addresses

//

//****************************

}

std::vectorCustomer *> Utils::readCustomerData() {

//****************************

//

// Replace the code here with code that will read Customer

// data off the appropriate file and create a vector of Customer

// pointers

//

//****************************

std::vectorCustomer *> emptyVector;

return emptyVector;

}