Hi I need help with this here are the insctructions Instruct

Hi I need help with this, here are the insctructions.

*****Instructions*********

you will be creating a class definition for a Contact, like one that you would add to your phone. Each Contact will have a first name, last name, phone number, and email. Within the class definition, there will be an accessor and mutator function for each member variable. Also, inputContact and displayContact. Main will behave like the previous homework assignment, which will be a menu based program that will display options to add a new contact, display all contacts, search for a contact by first name, and exit.

Contact

Member Variables

cstring member variables for first name, last name, phone number, and email. Each of these member variables will be private and have a static size of 32.

public member functions

Each member function will be declared (prototype) within the class definition and defined outside the class definition (scopeResolution::operator)

bool setFirstName - this function will pass in a const cstring and assign the passed parameter to the first name member variable and return true

bool setLastName - this function will pass in a const cstring and assign the passed parameter to the last name member variable and return true

bool setPhoneNumber - this function will pass in a const cstring and assign the passed parameter to the phone number member variable and return true

bool setEmail - this function will pass in a const cstring and assign the passed parameter to the email member variable and return true

char* getFirstName - this function will return the cstring member variable first name

char* getLastName - this function will return the cstring member variable last name

char* getPhoneNumber - this function will return the cstring member variable phone number

char* getEmail - this function will return the cstring member variable email

void inputContact - this function will create a cstring called temp with static size 32. For each member variable, prompt the user for input and call the corresponding mutator function passing the temp cstring

void displayContact - this function will print each member variable of the Contact calling the corresponding accessor function.

Default Constructor

The default constructor will initialize the each cstring member variable to an empty string. The definition will be outside the class definition

Destructor

The destructor will assign \'\\0\' to the first subscript of each member variable. The definition will be outside the class definition

Global Functions

void addContact - this function will pass an array of Contact Objects and an integer by reference for the current count of Contact Objects within the array. This function will call inputContact member function for the array at index count. Increment count then return.

void displayContacts - this function will pass a const array of Contact Objects and a const integer by value for the current count of Contact Objects within the array. This function will traverse the array, calling each objects member function displayContact.

int searchContacts - this function will pass a const array of Contact Objects and a const integer by value for the current count of Contact Objects within the array. This function will create a temporary cstring of size 32, prompt the user for a first name value to search for and input into the temporary cstring. The function will then traverse array of Contacts searching for first name that matches the user\'s input. If a Contact\'s first name matches the inputed value, return the index at which the Contact was found. If there was no match, return -1.

void displayMenu - this function will print the menu with options to \'Add New Contact\', \'Display All Contacts\', \'Search Contacts\', and \'Exit\'

*****This is what I have so far*******

5 #include <iostream>
6 #include <cstring>
7 using namespace std;
8
9 #define SIZE 32
10
11 // Contact Class Defnition
12 class Contact{
13     private:
14         char fName[SIZE];
15         int lName [SIZE];
16         int phone[SIZE];
17         int email [SIZE];
18     public:
19         bool setFirstName(char []);
20         bool setLastName(char[]);
21         bool setphoneNumber(char[]);
22         bool setEmail(char[]);
23
24         const char* getFirstName();
25         const char* getLastName();
26         const char* getPhoneNumber();
27         const char* getEmail();
28
29         void inputContact();
30         void displayContact();
31 }
32
33
34
35
36
37 // Global Functions Prototypes
38 //
39 //
40 //
41

42 int main() {
43
44     int choice; // user\'s choice
45     int searchResult; // the result from searchContacts
46
47     Contact contacts[SIZE]; // array of Contact Objects
48     int count=0; // current count of Contact Objects in contacts
49
50
51     do{
52         displayMenu(); // display menu
53         cin >> choice; // get choice
54         cin.ignore();   // remove \'\ \' from input buffer
55
56         switch(choice) {
57             case 1:
58                 addContact(contacts, count);
59                 break;
60             case 2:
61                 if(count>0)
62                     displayContacts(contacts, count);
63                 else
64                     cout << \"You must enter a contact first\ \";
65                 break;
66             case 3:
67                 if(count>0){
68                     searchResult = searchContacts(contacts, count);
69                     if(searchResult != -1) {
70                         cout << \"Contact was found at index \"
71                             << searchResult << endl;
72                     }
73                     else
74                         cout << \"Contact was NOT found\ \";
75                 }
76                 else
77                     cout << \"You must enter a contact first\ \";
78                 break;
79             case 0:
80                 cout << \"Good Bye\ \";
81                 break;
82             default:
83                 cout << \"Invalid option\ \";
84                 break;
85
86         }
87     }while(choice!=0);
88
89     return(0);

90 }
91
92 // Contact Member Function Definitions
93 //
94 //
95
96 // Global Function Definitions
97 //
98 //

Solution

#include <iostream>
#include <cstring>
using namespace std;
//Defines constant size
#define SIZE 32

// Contact Class Defnition
class Contact
{
    private:
    //Declaration of private data memeber
    char fName[SIZE];
    char lName [SIZE];
    char phone[SIZE];
    char email [SIZE];
    public:
    //Declaration of member function
    Contact();
    ~Contact();
    bool setFirstName(char []);
    bool setLastName(char[]);
    bool setphoneNumber(char[]);
    bool setEmail(char[]);

    const char* getFirstName();
    const char* getLastName();
    const char* getPhoneNumber();
    const char* getEmail();

    void inputContact();
    void displayContact();
};

// Global Functions Prototypes
void addContact(Contact [], int &);
void displayContacts (Contact [], const int );
int searchContacts (Contact [], const int );
void displayMenu();

int main()
{
    int choice; // user\'s choice
    int searchResult; // the result from searchContacts

    Contact contacts[SIZE]; // array of Contact Objects
    int count = 0; // current count of Contact Objects in contacts
    //Loops till 0 is entered
    do
    {
        displayMenu(); // display menu
        cin >> choice; // get choice
        cin.ignore();   // remove \'\ \' from input buffer

        switch(choice)
        {
            case 1:
              addContact(contacts, count);
              break;
            case 2:
              if(count > 0)
                    displayContacts(contacts, count);
                else
                      cout << \"You must enter a contact first \ \";
                  break;
              case 3:
                  if(count>0)
                  {
                      searchResult = searchContacts(contacts, count);
                      if(searchResult != -1)
                      {
                          cout << \"Contact was found at index \"
                              << searchResult << endl;
                      }
                      else
                          cout << \"Contact was NOT found\ \";
                  }
                  else
                      cout << \"You must enter a contact first\ \";
                  break;
              case 0:
                  cout << \"Good Bye\ \";
                  break;
              default:
                  cout << \"Invalid option\ \";
                  break;

          }
      }while(choice!=0);

      return(0);

}

// Contact Member Function Definitions

//Display contact information
void Contact::displayContact()
    {
        cout<<\"\ Firt Name: \"<<getFirstName();
        cout<<\"\ Last Name: \"<<getLastName();
        cout<<\"\ Phone Number: \"<<getPhoneNumber();
        cout<<\"\ Email ID: \"<<getEmail();
    }
    //Accept contact information
    void Contact::inputContact()
    {
        char temp[SIZE];
        cout<<\"\ Enter the First Name: \";
        gets(temp);
        setFirstName(temp);
        cout<<\"\ Enter the Last Name: \";
        gets(temp);
        setLastName(temp);
        cout<<\"\ Enter the Phone Number: \";
        gets(temp);
        setphoneNumber(temp);
        cout<<\"\ Enter the Email Id: \";
        gets(temp);
        setEmail(temp);
    }
    //returns mail id
    const char* Contact::getEmail()
    {
        return email;
    }
    //returns phone number
    const char* Contact::getPhoneNumber()
    {
        return phone;
    }
    //retunrs last name
    const char* Contact::getLastName()
    {
        return lName;
    }
    //returns first name
    const char* Contact::getFirstName()
    {
        return fName;
    }
    //sets email id
    bool Contact::setEmail(char t[])
    {
        strcpy(email, t);
        return true;
    }
    //sets phone number
    bool Contact::setphoneNumber(char t[])
    {
        strcpy(phone, t);
        return true;
    }
    //sets last name
    bool Contact::setLastName(char t[])
    {
        strcpy(lName, t);
        return true;
    }
    //sets first name
    bool Contact::setFirstName(char t[])
    {
        strcpy(fName, t);
        return true;
    }
    //Default Constructor
    Contact::~Contact()
    {
        fName[0] = \'\\0\';
        lName [0] = \'\\0\';
        phone[0] = \'\\0\';
        email [0] = \'\\0\';
    }
    //Destructor
    Contact::Contact()
    {
        fName[0] = \'\\0\';
        lName [0] = \'\\0\';
        phone[0] = \'\\0\';
        email [0] = \'\\0\';
    }

// Global Function Definitions
    //Display menu
    void displayMenu()
    {
        cout<<\"\ 0 - Exit\";
        cout<<\"\ 1 - Add New Contact\";
        cout<<\"\ 2 - Display All Contacts\";
        cout<<\"\ 3 - Search Contacts\";
    }
    //Addas a contact
void addContact(Contact c[], int &n)
{
        c[n].inputContact();
        n++;
}
    //Display contact
    void displayContacts (Contact c[], const int n)
    {
        for(int co = 0; co < n; co++)
            c[co].displayContact();
    }
    //Searches a contact and returns the index position
    int searchContacts (Contact c[], const int n)
    {
        char temp[SIZE];
        int co, re = -1;
        cout<<\"\ Enter the first name to search: \";
        gets(temp);
        for(co = 0; co < n; co++)
        {
            if(strcmp(c[co].getFirstName(), temp) == 0)
                re = co;
        }
        if(re == -1)
           return -1;
        else
            return re;
    }


Output:


0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 2
You must enter a contact first

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 1

Enter the First Name: Pyari

Enter the Last Name: Sahu

Enter the Phone Number: 123456

Enter the Email Id: abc@12

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 1

Enter the First Name: Mohan

Enter the Last Name: Padhy

Enter the Phone Number: 235648

Enter the Email Id: pya@22

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 1

Enter the First Name: Suresh

Enter the Last Name: sahu

Enter the Phone Number: 56485

Enter the Email Id: ui@33

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 2

Firt Name: Pyari
Last Name: Sahu
Phone Number: 123456
Email ID: abc@12
Firt Name: Mohan
Last Name: Padhy
Phone Number: 235648
Email ID: pya@22
Firt Name: Suresh
Last Name: sahu
Phone Number: 56485
Email ID: ui@33
0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 3

Enter the first name to search: mohan
Contact was NOT found

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 3

Enter the first name to search: Mohan
Contact was found at index 1

0 - Exit
1 - Add New Contact
2 - Display All Contacts
3 - Search Contacts
Enter your choice: 0
Good Bye

Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would
Hi I need help with this, here are the insctructions. *****Instructions********* you will be creating a class definition for a Contact, like one that you would

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site