can anyone kindly help me in writing a program for creating an address book. Its kinda urgent and I ll be really grateful.
program description:
develop a program for an address book.single entry in an address book is called a contact, which can have any of the following fields,
1. first name 2. last name 3. nickname 4. email1 5. email2 7. phone1 8. phone2 9. address 10.website 11.birthday 12.notes
a contact must have at least one of the first four fields to be valid.in the address book the user should be able to
1.add a contact
2.display all contacts sorted by a chosen field
3.display details of a single contact
4.remove a contact
5.find all contacts matching a keyword in a given field
6.modify a contact
7.export the address book to csv format file
8.exit the program
when the program is executed it takes a single command line argument:the name of the input file from which it reads an address book. all the modifications should be saved to the same original file on exit.

[A] add user shd be prompted for fields one by one. if any one of first 4 fields not there error: Invalid entry: the contact could not be created
[D] display sorted by first name last name nickname email
[C] display details of contact preview of address book shown and user prompted for the index of the contact whose details to be displayed.
[R] remove contact preview of address book shown and user prompted for the index of the contact whose details to be removed.
[M] modify contact
[F] find contacts matching
[E] export to csv format
[Q] exit

What kind of help do you want? Simply posting an assignment verbatim without any evidence of thought or effort on your part is against Daniweb's rules. But I'll give you the benefit of the doubt and kindly request that you ask a specific question and prove that you've made some kind of attempt at doing this assignment.

I have been able to write a program to add names in the address book, remove names, print names and exit from the address book. but do not know how to go about using the other functions like sort, modify,find all contacts matching a keyword in a given field, export the address book to the csv format. also cannot figure out how to put the condition that one out of the first four fields is mandatory for entering details in the address book. can you help.

 #include <iostream>
 #include <iostream>
 #include <string>
 #include <sstream>
 #include <fstream>

using namespace std;

// contact structure
 struct Contact {
    string name, street, city, email, phone, birthdate;
 };

// global array
 const int size = 20;
 Contact entry[size];

// contacts database file
 ofstream database;

// function prototypes
 int addContact(const int);
 void writeContactsToFile(void);

int main (int argc, char *argv[]) {
    int menuChoice;
    char response;
    string line;
    stringstream ss;
    bool done = false;
    int numContacts = 0;

   while (done == false) {
       // call loadContacts();
       // display menu
       cout << endl << endl 
           << "Welcome to your address book! What would you like to do?"
            << endl << endl
            << "1. Print my contacts to the screen." << endl
            << "2. Add a contact." << endl
            << "3. Remove a contact." << endl
            << "4. Quit program." << endl << endl
            << "Choose 1, 2, 3, or 4: ";
       getline(cin,line);
       ss.clear(); ss.str(line);
       if (!(ss >> menuChoice)) menuChoice = 0;

      switch (menuChoice) {
       case 1:
          // call printContacts();
          break;
       case 2:
          numContacts = addContact(numContacts);
          cout << "Would you like to save your changes to contacts.txt? (y/n) : ";
          getline(cin,line);
          if ((ss >> response) && (response == 'y')) {
             writeContactsToFile();
          }
          break;
       case 3:
          // call removeContact();
          cout << "Would you like to save your changes to contacts.txt? (y/n) : ";
          getline(cin,line);
          if ((ss >> response) && (response == 'y')) {
             writeContactsToFile();
          }
          break;
       case 4:
          cout << "\nHave a nice day!";
          done = true;
          break;
       default:
          cout << endl << "You did not enter a valid option." << endl;
          break;
       } // end case of menuChoice
    } // end while not done
    return 0;
 } 

// addContact function
 int addContact(int n) {
    // get information from user
    cout << endl << "You wish to add a new contact." << endl;
    cout << "Name? (Lastname, Firstname) : ";
    getline(cin,entry[n].name); 
   cout << "Address? (9999 Boardwalk Ave.) : ";
    getline(cin,entry[n].street); 
   cout << "City, state, & zip code? (City, State, Zip) : ";
    getline(cin,entry[n].city); 
   cout << "e-mail address? (name@gmail.com) : ";
    getline(cin,entry[n].email); 
   cout << "Phone number? (xxx-xxx-xxxx) : ";
    getline(cin,entry[n].phone); 
   cout << "Birth date? (MM/DD/YYYY) : ";
    getline(cin,entry[n].birthdate); 

   // tell user that contact was added
    // add 1 to the number of contacts and return the number
    // [ cja's comment: this can be a good thing to do if 
   // a contact may fail to be added, in which case you
    // would not increment n; as it is now, with no error 
   // checking, we'll just return n+1. ]
    return n+1;
 }

void writeContactsToFile() {
    // open contacts.txt database to store user's input
    database.open("contacts.txt", ios::out | ios::app);

   // write to contacts.txt
    // ...

   // close contacts.txt database
    database.close();
 }

Ok, that's a lot of stuff you haven't done. How about picking just one feature to work on? Taking an overwhelming project and breaking it down into manageable pieces is one of the skills a developer needs to learn. It's especially easy to do when there are multiple largely independent features.

Let's start by working on the find feature, since modify depends on it. Do you know how to loop through an array of objects and test for a matching data member? The basic algorithm is like so for names:

int find_entry(string const& search_key)
{
    for (int x = 0; x < size; ++x)
    {
        if (entry[x].name == search_key)
        {
            return x;
        }
    }

    return -1;
}

As you can probably imagine, it's kind of tedious like that when there are many possible data members. There's a way to get around that, but it's somewhat advanced. In case you're interested, the solution is a pointer to member:

#include <iostream>
#include <string>

using namespace std;

struct Contact
{
    string name;
    string address;
};

int find_entry(Contact entry[], int size, string Contact::*field, string const& search_key)
{
    for (int x = 0; x < size; ++x)
    {
        if (entry[x].*field == search_key)
        {
            return x;
        }
    }

    return -1;
}

int main()
{
    Contact entry[] =
    {
        {"a", "b"},
        {"c", "d"}
    };

    cout << find_entry(entry, 2, &Contact::name, "c") << '\n';
    cout << find_entry(entry, 2, &Contact::name, "a") << '\n';
    cout << find_entry(entry, 2, &Contact::name, "q") << '\n';

    cout << find_entry(entry, 2, &Contact::address, "b") << '\n';
    cout << find_entry(entry, 2, &Contact::address, "d") << '\n';
    cout << find_entry(entry, 2, &Contact::address, "q") << '\n';
}

Once you have an index for the matching element, you can write the driver code to incorporate the feature into your address book. That's your task. :)

This article has been dead for over six months. Start a new discussion instead.