In C I am being asked to create and maintain a list of conta
In C++, I am being asked to create and maintain a list of contact information for your friends and family. Include the following functionality:
1) add a new contact
2) delete a contact
3) update contact info
4) display contacts in ascending order by last name
5) find the contact info for a particular person
For each person you should store name, phone number, and email address.
You must chose an appropriate data structure to use to implement this system, and design and implement a contactType class.
Solution
/*
 * ContactInformation.cpp
 *
 * Created on: 24-Nov-2016
 * Author: kasturi
 */
 #include <iostream>
 #include <algorithm>
 using namespace std;
struct contact
 {
    string name;
    long phoneNumber;
    string email;
 };
contact * c1[20];
 int numberOfContacts = 0;
void addContact()
 {
    string name, email;
    long number;
    cout<<\"\ Enter name: \";
    cin>>name;
    cout<<\"\ Enter Phone Number: \";
    cin>>number;
    cout<<\"\ Enter email\";
    cin>>email;
    c1[numberOfContacts] = new contact;
    c1[numberOfContacts]->name = name;
    c1[numberOfContacts]->phoneNumber = number;
    c1[numberOfContacts]->email = email;
    numberOfContacts++;
 }
void deleteContact()
 {
    string name;
    cout<<\"\ Enter the contact name to delete: \";
    cin>>name;
    for(int i=0; i<numberOfContacts; i++)
    {
        if(c1[i] != NULL)
        {
            if(c1[i]->name == name)
            {
                c1[i] = NULL;
                break;
            }
        }
    }
 }
void updateContactInfo()
 {
    cout<<\"\ Enter the name of the contact to update: \";
    string nameToUpdate, name, email;
    long phone;
    int choice, index = 0;
    cin>>nameToUpdate;
    contact *c = new contact;
    for(int i=0; i<numberOfContacts; i++)
    {
        if(c1[i] != NULL)
        {
            if(c1[i]->name == name)
            {
                c = c1[i];
                index = i;
                break;
            }
        }
    }
    cout<<\"\ 1. Name\ 2. Phone Number\ 3. Email\ Enter the option to update: \";
    cin>>choice;
    switch(choice)
    {
    case 1: cout<<\"\ Enter the updated name: \";
            cin>>name;
            c->name = name;
            break;
    case 2: cout<<\"\ Enter the updated phone number: \";
            cin>>phone;
            c->phoneNumber = phone;
            break;
    case 3: cout<<\"\ Enter the updated email: \";
            cin>>email;
            c->email = email;
    }
    c1[index] = c;
 }
void findContact(string name)
 {
    for(int i=0; i<numberOfContacts; i++)
    {
        if(c1[i] != NULL)
        {
            if(c1[i]->name == name)
            {
                cout<<\"Name: \"<<c1[i]->name<<endl;
                cout<<\"Phone Number: \"<<c1[i]->phoneNumber<<endl;
                cout<<\"Email: \"<<c1[i]->email<<endl;
            }
        }
    }
 }
void displayContacts()
 {
    //contact *c2 = new contact[numberOfContacts];
    string names[20] ;
    int count = 0;
    for(int i=0; i<numberOfContacts; i++)
    {
        if(c1[i] != NULL)
        {
            names[count] = c1[i]->name;
            count++;
        }
    }
    int z = sizeof(names)/sizeof(names[0]); //Get the array size
   sort(names,names+z);
    for(int i=0; i<z; i++)
    {
        cout<<names[i]<<endl;
    }
 }
int main()
 {
    return 0;
 }
more coming...



