برنامه دفترچه تلفن ++c
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
int x=1;
struct tell{
char name[20];
char family[20];
int phone;
} list[100];
void add()
{if (x>=100)
cout<<"sory. the fhone book is complete"<<endl;
else
cout<<"input first name :";
cin>>list[x].name;
cout<<"input last name :";
cin>>list[x].family;
cout<<"input phone number :";
cin>>list[x].phone;
clrscr();
x++;}
void search()
{int i,num,p;
char text[20];
cout<<"search by name(1) or tell number(2):";
cin>>p;
if(p==1)
{
cout<<"name:";
cin>>text;
for(i=1;i<=x;i++)
{
if (strcmpi(text,list[i].name)==0)
{
cout<<list[i].name<<endl;
cout<<list[i].family<<endl;
cout<<list[i].phone<<endl;
}
else cout<<"this name not here"<<endl;
}
}
else
if (p==2)
{
cout<<"tell number:";
cin>>num;
for(i=1;i<=x;i++)
{
if (num==list[i].phone)
{
cout<<list[i].name<<endl;
cout<<list[i].family<<endl;
cout<<list[i].phone<<endl;
}
else cout<<"this number not here"<<endl;
}
}
else cout<<"sorry"<<endl;
}
void list_()
{
int i;
for(i=1;i<x;i++)
{cout<<"----------------"<<endl;
cout<<"|"<<list[i].name<<"|";
cout<<"|"<<list[i].family<<"|";
cout<<"|"<<list[i].phone<<"|"<<endl;
cout<<"----------------"<<endl;
}
}
void delet()
{
int a,i,j;
cout<<"enter a fhone number for delete:";
cin>>a;
for(i=1;i<=x;i++)
{if (a==list[i].phone)
{for (j=i;j<=x;j++)
{strcpy(list[j+1].name,list[j].name);
strcpy(list[j+1].family,list[j].family);
list[j+1].phone=list[j].phone;
}
}
else
cout<<"this number not here"<<endl;}}
int main()
{
int c,t,i,y;
long f;
while(1)
{
cout<<"1-Add"<<endl;
cout<<"2-Search"<<endl;
cout<<"3-List"<<endl;
cout<<"4-Delete"<<endl;
cout<<"5-Exit"<<endl<<"insert a number then press enter:";
cin>>c;
switch (c){
case 1:
add();
break;
case 2 :
search();
break;
case 3 :
list_();
break;
case 4 :
delet();
break;
case 5 :
return 0;
break;
}
}
getch();
return 0;
}
دوشنبه 26 اسفند 1392 10:33 PM
تشکرات از این پست