Create a BusinessPartner class that contains a first name, company name, and a t
ID: 3554676 • Letter: C
Question
Create a BusinessPartner class that contains a first name, company name, and a telephone number. Create a Contacts class that contains a dynamically allocated array of BusinessPartners as well as the owner's name and cell phone number.
Write a program that creates a Contacts object. The Business Partner array should be filled with data from the BusPhNum.txt file. Your program should then create a menu for the user to do the following: (Note: This is an example of aggregation - you must use aggregation for full credit)
1) display all the Business Partners in the contacts object as well as the owner and phone number of the owner.
2) look up a particular name in the contacts object and retrieve the phone number of the Business Partner
3) look up a particular name in the contact object and retrieve the Business Partner's company
4) Quit the program Upload ONE file with all your code in it as well as a screenshot of your program doing one of the menu actions.
Attached Files:
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
class BusinessPartner
{
public:
char firstname[15],company[15],telephone[12];
};
class contacts
{
public:
BusinessPartner *b=new BusinessPartner[15];
void display()
{
for(int i=0;b[i]!='';i++)
{
cout<<" "<<b[i].firstname;
cout<<" "<<b[i].company;
cout<<" "<<b[i].telephone;
}
}
void serach2()
{
char a[15];
cout<<"enter the name to be searched: ";
cin>>a;
for(int i=0;b[i]!='';i++)
{
if(strcmp(a,b[i].firstname)==0)
cout<<b[i].telephone;
}
}
void serach3()
{
char a[15];
cout<<"enter the name to be searched: ";
cin>>a;
for(int i=0;b[i]!='';i++)
{
if(strcmp(a,b[i].firstname)==0)
cout<<b[i].company;
}
}
};
contacts::contacts(void)
{
int i=0;
ifstream file;
file.open("BusPhNum.txt");
while(!file.eof());
{
file>>b[i].firstname;
file>>b[i].company;
file>>b[i].telephone;
i++;
}
}
int main()
{
int choice;
contacts c;
c.phncontacts();
while(choice!=4)
{
cout << "1. display all the Business Partners in the contacts object as well as the owner and phone number of the owner" << endl;
cout << "2. look up a particular name in the contacts object and retrieve the phone number of the Business Partner" << endl;
cout << "3. look up a particular name in the contact object and retrieve the Business Partner's company" << endl;
cout << "4. quit";
cin >> choice;
if(choice!=4)
{
if (choice==1)
{
display();
}
if(choice==2)
{
search2();
}
if(choice==3)
{
search3();
}
}
return 0;
}