1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<cstring>
using namespace std;
struct info
{
char name[20];
int number;
};
void addcontact(info a[],int );
void editcontact(info a[], int);
void deletecontact(info a[],int);
void showallcontact(info a[],int);
void exit();
void menue();
void main ()
{
menue();
}
void menue()
{
const int num=10;
info contactlist[num];
cout<<"_______________________\n";
cout<<" PHONE BOOK \n";
cout<<"_______________________\n";
cout<<"1-Add Contact\n";
cout<<"2-Edit Contact\n";
cout<<"3-Delete Contact\n";
cout<<"4-Show All Contacts\n";
cout<<"5-Exit\n";
int option;
cin>>option;
if(option==1)
{
addcontact(contactlist ,num);
}
else if(option==2)
editcontact(contactlist,num);
else if(option==3)
deletecontact(contactlist,num);
else if(option==4)
showallcontact(contactlist,num);
else if(option==5)
exit();
else
cout<<"Invalide option selected\n";
}
void addcontact(info a[],int i)
{
i=0;
system("CLS");
cout<<"Welcome to Add contact section\n";
cout<<"Enter name\n";
cin>>a[i].name;
cout<<"Enter number\n";
cin>>a[i].number;
cout<<"Contact Added\n";
i=i+1;
if(i==9)
{
cout<<"Contact limit reached\n";
}
menue();
}
void editcontact(info a[],int i)
{
int flag=0;
int k;
char name[20];
system("CLS");
cout<<"Welcome to Edit contact section\n";
cout<<"Enter name to edit\n";
cin>>name;
for(k=0;k<10;k++)
{
if(strcmp(name,a[k].name)==0);
{
flag=1;
break;
}
}
if (flag==1)
{
cout<<"Enter a new name\n";
cin>>a[k].name;
cout<<"Contact Edited\n";
menue();
}
else if(flag!=1)
{
cout<<"No record found\n";
menue();
}
}
void deletecontact(info a[],int i)
{
char name[20];
cout<<"Enter name of contact to be deleted"<<endl;
cin>>name;
for(int j=0;j<10;j++)
{
if(strcmp(name,a[j].name)==0)
{
strcpy(a[j].name," ");
cout<<"contact deleted\n"<<endl;
menue();
}
}
}
void showallcontacts(info a[],int i)
{
int l;
cout<<"details\n";
for (l=0;l<10;l++)
{
cout<<a[l].name<<endl;
cout<<a[l].number<<endl;
}
menue();
}
void exit()
{
exit(0);
}
|