#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
typedef struct name
{
char fname[20];
char lname[20];
}NAM;
typedef struct contact
{
char landline[12];
char mobile[12];
}CON;
type struct telephoneentry
{
NAM pname;
CON pcontact;
}PENT;
void printmenu()
{
printf("********************************************\n);
printf("1. press 1 to add records in telephone book\n");
printf("2. press 1 to delete a record\n");
printf("3. press 1 to list available records\n");
printf("4. press 1 to serach a records\n");
printf("5. press 1 to exit"\n);
printf("********************************************\n");
}
void addrecord(PENT book[],int *count)
{
char ch;
clrscr();
printf(" *****************\n");
printf" ADD RECORDS\n");
printf(" *****************\n");
printf("enter the first name of the person:\t");
gets(book[*count].pname.fname);
printf("enter the last name of the person:\t");
gets(book[*count].pname.lname);
printf("enter the landline number:\t");
gets(book[*count].pcontact.landline);
printf("enter the mobile number :\t");
gets(book[*count].pcontact.mobile);
(*count)++;
printf("records enter successfully\n\n");
flushall();
printf("do you want to enetr more records(Y/N):\t");
scanf("%c",&ch);
flushall();
if(ch=='Y'||ch=='y')
addrecord(book,count);
else
return;
}
void listrecords(PENT book[],int count)
{
int i=0;
clrscr();
printf(" **********************\n");
printf(" LISTING RECORDS\n");
printf(" **********************\n");
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
printf("-------------------------------------------------------------------\n);
while(i<count)
{
printf("%-4s %-20s %-20s%-12s %-12s\n",i+1,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
i++;
}
printf("--------------------------------------------------------------------\n");
printf("\n %d records(s) available \n",count);
printf("press any key to return to main menu....\n");
getch();
}
void searchrecord(PENT book[],int count)
{
int ch,i=0,found=0,no=0;
char key[25];
clrscr();
printf(" **************************\n");
printf(" SEARCH RECORDS\n");
printf(" **************************\n");
printf("1.press 1 to search by first name \n");
printf("2.press 1 to search by last name \n");
printf("3.press 1 to search by mobile number \n";
printf("4.press any other key to return to main menu \n");
flushall();
printf("enter your choice:\t");
scanf("%d"&ch);
switch(ch)
{
case 1:
printf("\n\n enter the first name of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pname.fname.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
printf("press any key to continue....\n");
getch();
break;
case 2:
printf("\n\n enter the last name of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pname.lname.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
printf("press any key to continue....\n");
getch();
break;
case 3:
printf("\n\n enter the mobile number of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pcontact.mobile.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
}
printf("press any key to continue....\n");
getch();
}
deleterecord(PENT book[],int *count)
{
int sno,i;
clrscr();
printf(" ***********************\n");
printf( RECORD DELETION\n");
printf(" ***********************\n");
printf("\n\n enter the S.No of the record that you want to delete:\t");
scanf("%d",&sno);
i=sno-1;
if(sno<=0||sno>*count)
printf("not a valid S.No\n");
else
{
while(i<*count)
{
book[i]=book[i+1];
i++;
}
*count=*count-1;
printf("record successfully deleted\n");
}
printf("press any key to return to main menu...\n");
getch();
}
main()
{
int ch,count=0;
PENT book[50];
clrscr();
while(1)
{
printf(" TELEPHONE BOOK \n");
printmenu();
printf("enter the choice:\t");
scanf("%d",&ch);
flushall();
switch(ch)
{
case 1:
addrecord(book,&count);
break;
case 2:
deleterecord(book,&count);
break;
case 3:
listrecords(book,count);
break;
case 4:
searchrecord(book,count);
break;
case 5:
exit(1);
break;
defalut:
printf("invalid option \n");
getch();
exit(1);
}
clrscr();
}
}
#include<string.h>
#include<stdlib.h>
#include<conio.h>
typedef struct name
{
char fname[20];
char lname[20];
}NAM;
typedef struct contact
{
char landline[12];
char mobile[12];
}CON;
type struct telephoneentry
{
NAM pname;
CON pcontact;
}PENT;
void printmenu()
{
printf("********************************************\n);
printf("1. press 1 to add records in telephone book\n");
printf("2. press 1 to delete a record\n");
printf("3. press 1 to list available records\n");
printf("4. press 1 to serach a records\n");
printf("5. press 1 to exit"\n);
printf("********************************************\n");
}
void addrecord(PENT book[],int *count)
{
char ch;
clrscr();
printf(" *****************\n");
printf" ADD RECORDS\n");
printf(" *****************\n");
printf("enter the first name of the person:\t");
gets(book[*count].pname.fname);
printf("enter the last name of the person:\t");
gets(book[*count].pname.lname);
printf("enter the landline number:\t");
gets(book[*count].pcontact.landline);
printf("enter the mobile number :\t");
gets(book[*count].pcontact.mobile);
(*count)++;
printf("records enter successfully\n\n");
flushall();
printf("do you want to enetr more records(Y/N):\t");
scanf("%c",&ch);
flushall();
if(ch=='Y'||ch=='y')
addrecord(book,count);
else
return;
}
void listrecords(PENT book[],int count)
{
int i=0;
clrscr();
printf(" **********************\n");
printf(" LISTING RECORDS\n");
printf(" **********************\n");
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
printf("-------------------------------------------------------------------\n);
while(i<count)
{
printf("%-4s %-20s %-20s%-12s %-12s\n",i+1,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
i++;
}
printf("--------------------------------------------------------------------\n");
printf("\n %d records(s) available \n",count);
printf("press any key to return to main menu....\n");
getch();
}
void searchrecord(PENT book[],int count)
{
int ch,i=0,found=0,no=0;
char key[25];
clrscr();
printf(" **************************\n");
printf(" SEARCH RECORDS\n");
printf(" **************************\n");
printf("1.press 1 to search by first name \n");
printf("2.press 1 to search by last name \n");
printf("3.press 1 to search by mobile number \n";
printf("4.press any other key to return to main menu \n");
flushall();
printf("enter your choice:\t");
scanf("%d"&ch);
switch(ch)
{
case 1:
printf("\n\n enter the first name of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pname.fname.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
printf("press any key to continue....\n");
getch();
break;
case 2:
printf("\n\n enter the last name of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pname.lname.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
printf("press any key to continue....\n");
getch();
break;
case 3:
printf("\n\n enter the mobile number of the person \n");
flushall();
gets(key);
while(i<count)
{
if(strcmp(book[i].pcontact.mobile.key)==0)
{
if(no==0)
printf("%-4s %-20s %-20s%-12s %-12s\n","S.No","first name","last name","landline No","mobile No");
found=1;
no++;
printf("%-4s %-20s %-20s%-12s %-12s\n",no,book[i].pname.fname,book[i].pname.lname,book[i].pcontact.landline,book[i].pcontact.mobile);
}
i++;
}
if(found==0)
printf("no record found\n");
else
printf("\n %d record(s) found \n",no);
}
printf("press any key to continue....\n");
getch();
}
deleterecord(PENT book[],int *count)
{
int sno,i;
clrscr();
printf(" ***********************\n");
printf( RECORD DELETION\n");
printf(" ***********************\n");
printf("\n\n enter the S.No of the record that you want to delete:\t");
scanf("%d",&sno);
i=sno-1;
if(sno<=0||sno>*count)
printf("not a valid S.No\n");
else
{
while(i<*count)
{
book[i]=book[i+1];
i++;
}
*count=*count-1;
printf("record successfully deleted\n");
}
printf("press any key to return to main menu...\n");
getch();
}
main()
{
int ch,count=0;
PENT book[50];
clrscr();
while(1)
{
printf(" TELEPHONE BOOK \n");
printmenu();
printf("enter the choice:\t");
scanf("%d",&ch);
flushall();
switch(ch)
{
case 1:
addrecord(book,&count);
break;
case 2:
deleterecord(book,&count);
break;
case 3:
listrecords(book,count);
break;
case 4:
searchrecord(book,count);
break;
case 5:
exit(1);
break;
defalut:
printf("invalid option \n");
getch();
exit(1);
}
clrscr();
}
}
No comments:
Post a Comment