Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help!! Develop a C++ application. The application defines and uses two cl

ID: 671890 • Letter: P

Question


Please help!!

Develop a C++ application. The application defines and uses two classes: Customer and Contact. The Customer class has a vector of Contact as a one of the data members.
Requirements:
1. The class Customer should be implemented based on the class diagram shown below:
Customer
-CompanyName: String
-Address: String
-City: String
-State: String
-Zip: String
-Contacts: vector <Contact>
«constructor»+ Customer()
«constructor»+ Customer(companyname:String, address:String, city:String state:String, zip: String)
+setCompanyName(company_name: String)
+getCompanyName(): String
+setAddress(address: String)
+setCity(city: String)
+setState(state: String)
+setZip(zip: String)
+getAddress(): String
+getCity(): String
+getState(): String
+getZip(): String
+getFullAddress(): String
+addContact(contact: Contact)
+RemoveContact(contact: Contact): bool
+listContacts(): String
2. The class Contact should be implemented based on the class diagram shown below:
Contact;
-FirstName: String
-LastName: String
-Phone: String
«constructor»+ Contact()
«constructor»+ Contact(firstname:String, lastname: String, phone: String)
+setFirstName(firstname: String)
+setLastName(lastname: String)
+getFirstName(): String
+getLastName(): String
+setPhone(phone: String)
+getPhone(): String
+getContactInfo(): String
3. Description of the member functions for class Customer
*Customer() This constructor initializes CompanyName, Address, City, Zip to a zero-length string ("").
*Customer(address: String, city: String, state: String, zip: String) This constructor initializes CompanyName, Address, City, State and Zip using the arguments passed in.
*setCompanyName(), setAddres(address:String), setCit(city:String), setZip(zip:String) These setter functions update corresponding data members.
*getCompanyName(), getAddress(), getCity(), getZip() These getter functions returns corresponding data members.
*getFullAddress() returns the combined address with this format: <address>,<City>,<State>,<Zip>
*addContact(contact: Contact) Add a contact to the vector of Contact
*removeContact(contact: Contact) Compare the argument with the contacts in the vector of Contact, if the first name, last name and phone number match, remove the contact from the vector
*listContacts() Return a String that contains information of all contacts. The information of each contact is obtained by calling the getContactInfo of the Contact class.
Note: The word "return" in the description above means the "return" keyword in C++, rather than display on screen.
4. Description of the member functions for class Contact
*Contact() This default constructor initializes FirstName, LastName and Phone to zero-length string ("").
*Contact(firstname:String, lastname: String, phone: String) This constructor initializes FirstName, LastName and Phone using the arguments passed in.
*setFirstName(firstname: String) setLastName(lastname: String) setPhone(phone: String) These setter functions update corresponding data members.
*getFirstName(): String getLastName(): String getPhone(): String These getter functions returns corresponding data members.
*getContactInfo(): String returns a String with this format: <First Name> <Last Name> < Phone>
Note: The word "return" in the description above means the "return" keyword in C++, rather than display on screen.
5. Write a driver program as the client of the Customer class. It should instantiate an object of the Cusotmer class; then it should demonstrate the use of all member functions. However, only one constructor should be used.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void menu(void);
void writeData(void);
void readData(void);
string * split(string, char);
const char FileName[] = "c://TestAddress/TestAddress.txt";
ifstream myAddress(FileName);
string name = " ";
string address = " ";
string street= " ";
string city = " ";
string state = " ";
string zipCode = " ";
int record = 0;
ofstream outMyAddress(FileName, ios::out);
int main ()
{

menu();
return 0;
} //end main
void menu(void)
{

char userChoice = ' ';
//Display Menu
system("cls");
cout << " Name and Address database:" << endl;
cout << endl;
cout << " (A)ppend record, (S)how Record, (E)xit:";
cin >> userChoice;
//Users Choice
switch (userChoice)
{
case 'a':
case 'A':
myAddress.open (FileName, ios::app);
if (myAddress.is_open())
           {
               writeData();
           }
break;
case 's':
case 'S':
myAddress.open (FileName, ios:: in);
if (myAddress.is_open())
           {
               readData();
           }

break;
case 'e':
case 'E':
myAddress.close();
break;
default:
cout << "Invalid choice" << endl;
cout << endl << endl << endl;
break;

}
return;

}
void writeData(void)
{

char answer = ' ';
char response = ' ';
   if(myAddress.is_open())
   {
       //entering loop
while (answer != 'n' || answer != 'N')
{
cout << endl;
getline(cin, name);
cout << " Enter name: ";
getline(cin, name);
cout << " Enter Street: ";
getline(cin, street);
cout << " Enter City: ";
getline(cin, city);
cout << " Enter State: ";
getline(cin, state);
cout << " Enter Zip Code: ";
getline(cin, zipCode);
cout << endl;
outMyAddress << name << ", " << street << " ," << city << ", " << state << " ," << zipCode << endl;
record++;
  
cout << " Would you like to enter another record? (Y/N)" << endl;
cin >> response;


if (response == 'n' || response == 'N')
{
return menu();
}
}
   }
myAddress.close();

}
void readData(void)
{
ifstream inMyAddress(FileName, ios::in);
   if(myAddress.is_open())
   {
string firstLine;
inMyAddress >> firstLine;
getline (myAddress, firstLine, ' ');
cout << endl;
cout << "Reading the file(s)..." << endl;
cout << endl;

cout << "Record #: " << record << endl;
string *theField = split(firstLine, ',');
cout << "Name......" << theField[0] << endl;
cout << "Street......" << theField[1] << endl;
cout << "City......" << theField[2] << endl;
cout << "State......" << theField[3] << endl;
cout << "Zip Code......" << theField[4] << endl;
   }
inMyAddress.close();
system("pause");
return menu();

}
string * split(string theLine, char theDeliminator){

int splitCount = 0;
for(int i = 0; i < ((int)theLine.size()); i++){
if (theLine[i] == theDeliminator)
splitCount++;
return 0;
}
splitCount++; //add one more to the count because there is not an ending comma
//create an array to hold the fields
string* theFieldArray;
theFieldArray = new string[splitCount];

string theField = "";
int commaCount = 0;
for(int i = 0; i < ((int)theLine.size()); i++){ //read each character and look for the deliminator
if (theLine[i] != theDeliminator) {
theField += theLine[i]; //build the field
}
else { //the deliminator was hit so save to the field to the array
theFieldArray[commaCount] = theField; //save the field to the array
theField = "";
commaCount++;
}
}
theFieldArray[commaCount] = theField; //the last field is not marked with a comma...
return theFieldArray;
}