Question: Why will my code not compile, I am looking for a correction to my code not a whole new code? #include #include using namespace std;

Why will my code not compile, I am
looking for a correction to my code not a whole new code?
#include
#include
using namespace std;
class Contact {
public:
Contact(const string &name, const string &phoneNumber, const string &email):
name(name), phoneNumber(phoneNumber), email(email){}
void PrintContacts(Contact *contacts[], int size);
void SelectionSortContacts(Contact *contacts[], int size);
private:
string name;
string email;
string phoneNumber;
};
void Contact::PrintContacts(Contact *contacts[], int size){//displays contact with name, phone number, and email
for (int j =0; j <3; ++j){
cout << name[j]<<"-"<< phoneNumber[j]<<"-"<< email[j]<< endl;
}
}
void Contact::SelectionSortContacts(Contact *contacts[], int size){//sorts contacts in alphabetical order within the array
for (int i =0; i <3; ++i){
string tempName;
string tempNumber;
string tempEmail;
if (name[i]> name[i+1]){
//sorts name
tempName = contacts[i]->name;
contacts[i]->name = contacts[i+1]->name;
contacts[i+1]->name = tempName;
//sorts phone number based of off name being sorted
tempNumber = contacts[i]->phoneNumber;
contacts[i]->phoneNumber = contacts[i+1]->phoneNumber;
contacts[i+1]->phoneNumber = tempNumber;
//sorts email based of off name being sorted
tempEmail = contacts[i]->email;
contacts[i]->email = contacts[i+1]->email;
contacts[i+1]->email = tempEmail;
}
}
}
int main()
{
Contact *contacts[]{//hard codes the three contacts per assignemnt
new Contact("John Doe", "555-1234", "john@mail.com"),
new Contact("Jane Smith", "555-5678", "jane@mail.com"),
new Contact("Bob Williams", "555-9101", "bob@mail.com"),
};
cout << "Contacts:" << endl;
contacts.PrintContacts(contacts,3); //prints contacts in order of input
contacts.SelectionSortContacts(contacts,3); //sorts contacts alphabetically
cout << "Contacts after sorting:" << endl;
contacts.PrintContacts(contacts,3); //reprints contacts in new order
for (int i =0; i <3; ++i){//releases allocated memory
delete contacts[i];
}
return 0;
}
main.cpp: In function int main():
main.cpp:62:18: error: request for member PrintContacts in contacts, which is of non-class type Contact*[3]
62| contacts.PrintContacts(contacts,3); //prints contacts in order of input
|^~~~~~~~~~~~~
main.cpp:64:18: error: request for member SelectionSortContacts in contacts, which is of non-class type Contact*[3]
64| contacts.SelectionSortContacts(contacts,3); //sorts contacts alphabetically
|^~~~~~~~~~~~~~~~~~~~~
main.cpp:67:18: error: request for member PrintContacts in contacts, which is of non-class type Contact*[3]
67| contacts.PrintContacts(contacts,3); //reprints contacts in new order
|^~~~~~~~~~~~~

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!