عنوان 

 

برنامه دفتر تلفن با امکانات افزودن اطلاعات- ویرایش – جستجو-نمایش لیست – حذف و سایر امکانات 

نوع فایل

فرمت

سورس زبان سی

CPP , EXE

پیش نمایش از سورس کد پروژه

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
class tele{
char name[20];
int num;
public:void input(void);
void list(void);
void sort(void);
void search(void);
void delt(void);
void customize(void);
int i_search(char[20]);
};
//******************************************************
void tele::input(void){
int flag=0;
ofstream my(“info.dat”,ios::app);
if(!my){
printf(“Can’t open file”);
exit(0);
}
while(1){
ofstream my(“info.dat”,ios::app);
if(!my){
printf(“Can’t open file”);
exit(0);
}
printf(“Enter name, phone number : \n –>”);
cin.getline(name,20);
if(name[0]==’\0′)
break;
flag = i_search (name);
if(flag==1)
break;
printf(” –>”);
scanf(“%d”,&num);
my.write((char*)this,sizeof(tele));
my.close();
}
}
//******************************************************
int tele::i_search(char s[20]){
int flag=0;
ifstream my (“info.dat”,ios::out);
tele p;
if(!my){
printf(“Can’t open file”);
exit(0);
}
while(my.read((char*)&p,sizeof(tele))){
if(strcmp(p.name,s)==0){
printf(“The name already exists! \n”);
flag=1;
}
}//end of while
my.close();
return flag;
}
//******************************************************
void tele::list(void){
ifstream my(“info.dat”);
tele p;
if(!my){
printf(“Can’t open file”);
exit(0);
}
while(my.read((char*)&p,sizeof(tele)))
printf(“%s %d \n”,p.name,p.num);
my.close();
}
//******************************************************
void tele::sort(void){
int k, j, i=0;
ifstream my (“info.dat”,ios::out);
if(!my){
printf(“Can’t open file”);
exit(0);
}
tele p[100],temp;
while(my.read((char*)&p[i],sizeof(tele)))
i++;
for(j=0;j<i-1;j++)
for(k=j+1;k<i;k++)
if(strcmp(p[j].name,p[k].name)>0){
temp=p[j];
p[j]=p[k];
p[k]=temp;
}
for (j=0;j<i;j++)
printf(“%s %d \n”,p[j].name,p[j].num);
my.close();
}
//******************************************************
void tele::search(void){
int flag=0;
char s[20];
ifstream my (“info.dat”);
tele p;
if(!my){
printf(“Can’t open file”);
exit(0);
}
printf(“Enter a name to sreach : \n –>”);
scanf(“%s”,&s);
while(my.read((char*)&p,sizeof(tele))){
if(strcmp(p.name,s)==0){
flag=1;
printf(“%s %d \n”,p.name,p.num);
}
}//end of while
if(flag==0)
printf(“Not found \n”);
my.close();
}
//******************************************************
void tele::delt(void){
int i=0, n, flag=0;
char s[20];
printf(“Enter the name to be deleted \n”);
scanf(“%s”,&s);
ifstream my(“info.dat”,ios::out);
tele temp[100], p;
while (my.read((char*)&p,sizeof(tele))){
if(strcmp(p.name,s)==0)
flag=1;
if(strcmp(p.name,s)==0)
continue;
temp[i]=p;
i++;
}//end of while
ofstream mp(“temp.dat”,ios::app);
for(n=0;n<i;n++)
mp.write((char*)&temp[n],sizeof(tele));
my.close();
mp.close();
remove(“info.dat”);
rename(“temp.dat”,”info.dat”);
if(flag==0){
printf(“Record does not exist \n”);
}
if(flag==1){

}

Telbook

======