Can you please help me out on my project?, its like a phonebook on cellphone it should be display the ADD CONTACTS, DELETE, EDIT, SAVE, VIEW, SEARCH. I sunno how to edit and delete the contacts can you help me on this.. i came out on this,..

#include<iostream.h>
 #include<conio.h>


   void main(void)
   {
    struct contact_info{
    char lname[15];
    char fname[20];
    char e_add[25];
    int num;
   };
   clrscr();
    const MAX_CONTACTS=101;
    struct contact_info contacts[MAX_CONTACTS];
    int num_contacts=0;
    int index;
    int command;
    char extraline[40];
    gotoxy(30,1);cout<<"Phonebook System"<<endl
    <<endl;
    do{
    gotoxy(20,2);cout<<"1)ADD CONTACT"<<endl;
    gotoxy(20,3);cout<<"2)VIEW"<<endl;
    gotoxy(20,4);cout<<"3)SAVE"<<endl;
    gotoxy(20,5);cout<<"4)DELETE"<<endl;
    gotoxy(20,6);cout<<"5)SEARCH"<<endl;
    gotoxy(20,7);cout<<"6)EDIT"<<endl;
    cout<<"Enter your choice: ";
     cin>>command;
     cin.ignore(1);
    if(command==1){
     num_contacts++;
     cout<<"Enter new last name: ";
     cin. getline(contacts[num_contacts].lname,
     sizeof(contacts[num_contacts].lname));
     cout<<"Enter first name: ";
     cin.getline(contacts[num_contacts].fname,
     sizeof(contacts[num_contacts].fname));
     cout<<"Enter new email address: ";
     cin.getline(contacts[num_contacts].e_add,
     sizeof(contacts[num_contacts].e_add));
     cout<<"Enter number:";
     cin>>(contacts[num_contacts].num);
      cout<<endl;
      }
    else
      if(command==2){
      for(index=1;index<=num_contacts;index++){
      cout<<"Contact #: "<<index<<"is"<<endl;
      cout<<"First name: "<<contacts[index].fname<<endl;
      cout<<"Last name: "<<contacts[index].lname<<endl;
      cout<<"Email address: "<<contacts[index].e_add<<endl;
      cout<<","<<contacts[index].num<<endl;}
     }
     else
      if(command==3){
      for(index=1;index<+num_contacts;index++){
      cout<<"Contact #: "<<index<<endl;
      cout
      if(command!=3){
      cout<<"Please type 1, 2, 3, 4, 5, 6"<<endl;
      cout<<"Press enter to continue"<<endl;
      cin.clear();
      cin.getline(extraline, sizeof(extraline));}
     }while(command!=3);
     }

Edited 3 Years Ago by Dani: Formatting fixed

To edit you merely overwrite data usually (output the old data, input the new) to delete you usually remove the element by shifting all those after it back by one. I would suggest that an std::vector would be extremely useful in this situation.

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