Skip to content

Instantly share code, notes, and snippets.

@m-zakeri
Created January 29, 2018 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save m-zakeri/882fe27d4063ffb52beef13d89436a38 to your computer and use it in GitHub Desktop.
Save m-zakeri/882fe27d4063ffb52beef13d89436a38 to your computer and use it in GitHub Desktop.
/* PHONEBOOK 2011-TC Version(2.5)
By: MORTEZA ZAKERI (m-zakeri@live.com)
[2010-2011 ARAK UNIVERCITY-Computer Group]
www.micropedia.ir
Note: Run this program with Turbo C++3.0 - 3.5
*/
//1-header files...
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <iostream>
struct contact{
char fname[31];
char lname[31];
char telep[15];
char cellp[15];
}A[50];
//2-functions...
void insert(void);
void delet(void);
void edit(void);
void search(void);
void searchf(void);
void searchl(void);
void searchp(void);
void searchc(void);
void list(void);
void list2(void);
void sort(void);
void sortf(void);
void sortl(void);
void sortp(void);
void sortc(void);
void help(void);
//3-Public Variables...
int last;
//using namespace std;
//Start Progarm
int main()
{
int count=1;
char n;
while(count){
clrscr(); //system("cls");
printf("\n|Phone Book12<::>Home|\n");
printf("--------------------------------------------------------------------------------\n");
printf("Welcome to PHONE BOOK2012!\nYou have inserted ( %d ) contacts.\n\n",last);
printf("\t[1] |--> Insert\n");
printf("\t[2] |--> Delete\n");
printf("\t[3] |--> Edit\n");
printf("\t[4] |--> Search\n");
printf("\t[5] |--> Show All\n");
printf("\t[6] |--> Sort\n");
printf("\t[7] |--> Help\n");
printf("\t[8] |--> Exit\n");
printf("\n\tPlease Enter Your Choice (1-8): ");
n=getche();
switch(n){
case '1':
insert();
break;
case '2':
delet();
break;
case '3':
edit();
break;
case '4':
search();
break;
case '5':
list();
break;
case '6':
sort();
break;
case '7':
help();
break;
case '8':
exit(1);
break;
default:
printf("\nThere is no item with symbol \"%c\".Please enter a number between 1-8!\nPress any key to continue...",n);
getch();
break;
}//End of swicth
//getch();
}//End of while.
return 0;
}//End of main function!
//******************************************
void insert(void)
{
//int i=0;
char ans='y';
system("cls");
printf("\nPhone Book12<::>Insert Contacts");
printf("\n--------------------------------------------------------------------------------");
while(ans=='y'){
if(last==50)
printf("\n*Phone Book is Full.Please Delete Some Records and Continue.*\n");
else{
printf("\n\nData of Contact %2.2d{\n",last+1);
printf("\n\t 1-F.Name: ");
gets(A[last].fname); //scanf("%s",A[last].fname);
printf("\t 2-L.Name: ");
gets(A[last].lname); //scanf("%s",A[last].lname);
printf("\t 3-Tele.P: ");
gets(A[last].telep); //scanf("%s",A[last].telep);
printf("\t 4-Cell.P: ");
gets(A[last].cellp); //scanf("%s",A[last].cellp);
printf("\n|-->Data Recorded!}");
printf("\n\t\t\tNext Contact?(y/n) Answer: ");
ans=getche();
last++;
}
}
printf("\n\nYou have inserted ( %d ) contact!\nPress a key to return main page & continue program|-->",last);
getch();
}
//******************************************
void delet(void)
{
char dfname[31],dlname[31];
register int i,j,find=0;
char ch;
clrscr(); //system("cls");
printf("\nPhone Book12<::>Delete Contacts");
printf("\n--------------------------------------------------------------------------------");
printf ("\n::Enter data of the contact that you want delete it,please:");
printf("\n\n ::Enter first name: ");
gets(dfname);
printf("\n ::Enter last name: ");
gets(dlname);
for (i=0; i<last; i++){
if (strcmp (dfname, A[i].fname)==0 && strcmp (dlname, A[i].lname)==0 )
{
printf("\nContact find! Detail:");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
printf("\n\nDo you sure to delete this contact?(y/n) ");
ch=getche();
if(ch=='y'){
for(j=i;j<=last;j++)
A[j]=A[j+1];
last--;
find=1;
break;
}}
}
if (find==0)
printf("\t\t\n<<This contact dose not exist in this list or program can not delete it.>>");
else
printf("\t\t\n<<Target contact was successfully deleted from list!>>");
printf("\n\n\nPress a key to return main page & continue program|-->");
getch();
}
//******************************************
void edit()
{
struct contact newc;
char dfname[31],dlname[31];
register int i,j,find=0;
char ch;
clrscr(); //system("cls");
printf("\nPhone Book12<::>Edit Contacts");
printf("\n--------------------------------------------------------------------------------");
printf ("\n::Enter data of the contact that you want edit it,please:");
printf("\n\n ::Enter first name: ");
gets(dfname);
printf("\n ::Enter last name: ");
gets(dlname);
for (i=0; i<last; i++){
if (strcmp (dfname, A[i].fname)==0 && strcmp (dlname, A[i].lname)==0 )
{
printf("\nContact find! Detail:");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
printf("\n\nDo you want edit it?(y/n) ");
ch=getche();
if(ch=='y'){
printf("\n::Enter NEW data for this contact...");
printf("\n >|Enter new first name: ");
gets(newc.fname);
printf(" >|Enter new last name: ");
gets(newc.lname);
printf(" >|Enter new telephone number: ");
gets(newc.telep);
printf(" >|Enter new cellphone number: ");
gets(newc.cellp);
strcpy(A[i].fname,newc.fname);
strcpy(A[i].lname,newc.lname);
strcpy(A[i].telep,newc.telep);
strcpy(A[i].cellp,newc.cellp);
find=1;
break;
}}
}
if (find==0)
printf("\t\t\n<<This contact dose not exist in list or program can not Edit it.>>");
else
printf("\t\t\n<<Target contact was successfully updated!>>");
printf("\n\n\n ::Press a key to return main page & continue program|-->");
getch();
}
//******************************************
void search(void)
{
char ch;
clrscr(); //system("cls");
printf("\nPhone Book12<::>$earch Contacts");
printf("\n--------------------------------------------------------------------------------");
printf("\nChoose search type,please:\n\n");
printf("\t[1] |--> Search by first name\n");
printf("\t[2] |--> Search by last name\n");
printf("\t[3] |--> Search by phone number\n");
printf("\t[4] |--> Search by cellphone number\n");
printf("\n\t::Enter a number (1-4): ");
ch=getche();
printf("\n--------------------------------------------------------------------------------");
switch(ch){
case '1':
searchf();
break;
case '2':
searchl();
break;
case '3':
searchp();
break;
case '4':
searchc();
break;
default:
printf("\nThere is no item with symbol \"%c\".Please enter a number between 1-8!\nPress any key to continue...",ch);
getch();
}//end of switch
printf("\n--------------------------------------------------------------------------------");
printf("\n\n\n::Press a key to return main page & continue program|-->");
//getch();
}
//##########################################
void searchf(void)
{
char sname[31];
register int i,find=0;
//char ch;
printf("Enter a first name to search:");
gets(sname); // scanf("%s",sname);
for(i=0;i<last;i++)
if(strcmp(sname,A[i].fname)==0){
find=1;
break;
}
if(find==0)
printf("\t\n<<Not Find!There is not contact with tish name in phone book.>>");
else{
printf("\t\n<<Target contact find! Detail:>>");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
}
printf("\nPress a key to search another contact.");
getch();
search();
}
//##########################################
void searchl(void)
{
char sname[31];
register int i,find=0;
printf("\n::Enter a last name to search:");
gets(sname); // scanf("%s",sname);
for(i=0;i<last;i++)
if(strcmp(sname,A[i].lname)==0){
find=1;
break;
}
if(find==0)
printf("\t\n<<Not Find!There is not contact with tish name in phone book.>>");
else{
printf("\t\n<<Target contact find! Detail:>>");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
}
printf("\nPress a key to search another contact.");
getch();
search();
}
//##########################################
void searchp(void)
{
char sname[31];
int i,find=0;
printf("\n::Enter a phone number to search:");
gets(sname); // scanf("%s",sname);
for(i=0;i<last;i++)
if(strcmp(sname,A[i].telep)==0){
find=1;
break;
}
if(find==0)
printf("\t\n<<Not Find!There is not contact with tish phone number in phone book.>>");
else{
printf("\t\n<<Target contact find! Detail:>>");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
}
printf("\nPress a key to search another contact.");
getch();
search();
}
//##########################################
void searchc(void)
{
char sname[31];
int i,find=0;
printf("\n::Enter a cellphone number to search:");
gets(sname); // scanf("%s",sname);
for(i=0;i<last;i++)
if(strcmp(sname,A[i].cellp)==0){
find=1;
break;
}
if(find==0)
printf("\t\n<<Not Find!There is not contact with tish cellphone number in phone book.>>");
else{
printf("\t\n<<Target contact find! Detail:>>");
printf("\n\nCantact %2.2d{",i+1);
printf("\n\t F.Name:%s\n\t L.name:%s\n\t Tele.P:%s\n\t Cell.P:%s\n\t }",A[i].fname,A[i].lname,A[i].telep,A[i].cellp);
}
printf("\nPress a key to search another contact.");
getch();
search();
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//******************************************
void sort(void)
{
char ch;
clrscr(); //system("cls");
printf("\nPhone Book12<::>$earch Contacts");
printf("\n--------------------------------------------------------------------------------");
printf("\nChoose sort type,please:\n\n");
printf("\t[1] |--> Sort by first name\n");
printf("\t[2] |--> Sort by last name\n");
printf("\t[3] |--> Sort by phone number\n");
printf("\t[4] |--> Sort by cellphone number\n");
printf("\n\t::Enter a number (1-4): ");
ch=getche();
printf("\n--------------------------------------------------------------------------------");
switch(ch){
case '1':
sortf();
break;
case '2':
sortl();
break;
case '3':
sortp();
break;
case '4':
sortc();
break;
default:
printf("\nThere is no item with symbol \"%c\".Please enter a number between 1-8!\nPress any key to continue...",ch);
getch();
}//end of switch
printf("\n--------------------------------------------------------------------------------");
printf("\n\n\n ::Press a key to return main page & continue program.|-->");
//getch();
}
//##########################################
void sortf(void)
{
struct contact B;
register int i,j;
for(i=last-1;i>0;i--)
for(j=0;j<i;j++)
if(strcmp(A[j].fname,A[j+1].fname)>0){
B=A[j];
A[j]=A[j+1];
A[j+1]=B;
}
printf("\nplease wait... .Contacts will be sort by first names.");
list2();
printf("\n ::Press any key to sort contact by another form... ");
getch();
sort();
}
//##########################################
void sortl(void)
{
struct contact B;
register int i,j;
for(i=last-1;i>0;i--)
for(j=0;j<i;j++)
if(strcmp(A[j].lname,A[j+1].lname)>0){
B=A[j];
A[j]=A[j+1];
A[j+1]=B;
}
printf("\nplease wait... .Contacts will be sort by last names.");
list2();
printf("\n ::Press any key to sort contact by another form... ");
getch();
sort();
}
//##########################################
void sortp(void)
{
struct contact B;
register int i,j;
for(i=last-1;i>0;i--)
for(j=0;j<i;j++)
if(strcmp(A[j].telep,A[j+1].telep)>0){
B=A[j];
A[j]=A[j+1];
A[j+1]=B;
}
printf("\nplease wait... .Contacts will be sort by telephone numbers.");
list2();
printf("\n ::Press any key to sort contact by another form... ");
getch();
sort();
}
//##########################################
void sortc(void)
{
struct contact B;
register int i,j;
for(i=last-1;i>0;i--)
for(j=0;j<i;j++)
if(strcmp(A[j].cellp,A[j+1].cellp)>0)
{
B=A[j];
A[j]=A[j+1];
A[j+1]=B;
}
printf("\nPlease wait... .Contacts will be sort by cellphone numbers.");
list2();
printf("\n ::Press any key to sort contact by another form... ");
getch();
sort();
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//******************************************
void list()
{
register int i;
clrscr(); //system("cls");
printf("\nPhone Book12<::>All Contacts List");
printf("\n--------------------------------------------------------------------------------");
//printf("\nRow First Name Last Name Telephone Cellphone");
gotoxy(1,4);
printf("Row");
gotoxy(9,4);
printf("First Name");
gotoxy(27,4);
printf("Last Name");
gotoxy(44,4);
printf("Telephone");
gotoxy(60,4);
printf("Cellphone");
printf("\n--------------------------------------------------------------------------------");
for(i=0;i<last;i++)
{
//printf("%3.3d %s %s %s %s",i,A[i].fname,A[i].lname,A[i].telep);
gotoxy(1,i+6);
printf("%3.3d",i+1);
gotoxy(9,i+6);
printf("%s",A[i].fname);
gotoxy(28,i+6);
printf("%s",A[i].lname);
gotoxy(44,i+6);
printf("%s",A[i].telep);
gotoxy(60,i+6);
printf("%s",A[i].cellp);
}
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n\t\t **********End Of list!**********");
printf("\n\n\n ::Press a key to return main page & continue program.|-->");
getch();
}
//******************************************
void list2(void)
{
register int i;
printf("\n--------------------------------------------------------------------------------");
gotoxy(1,18);
printf("Row");
gotoxy(9,18);
printf("First Name");
gotoxy(27,18);
printf("Last Name");
gotoxy(44,18);
printf("Telephone");
gotoxy(60,18);
printf("Cellphone");
printf("\n--------------------------------------------------------------------------------");
for(i=0;i<last;i++)
{
gotoxy(1,i+21);
printf("%3.3d",i+1);
gotoxy(9,i+21);
printf("%s",A[i].fname);
gotoxy(27,i+21);
printf("%s",A[i].lname);
gotoxy(44,i+21);
printf("%s",A[i].telep);
gotoxy(60,i+21);
printf("%s",A[i].cellp);
}
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n\t\t **********End Of list!**********");
//printf("\n\n\n ::Press a key to return main page & continue program.|-->");
//getch();
}
//******************************************
void help(void)
{
clrscr();
gotoxy(26,1);
printf("--------------------------");
gotoxy(26,2);
printf("|Welcome To Phone Book12!|");
gotoxy(26,3);
printf("--------------------------");
gotoxy(1,5);
printf("PhoneBook12>>[Help & Instructions] \n");
printf("--------------------------------------------------------------------------------\n");
printf("\nAbout Phonebook12\n *Version: 2.5\n *Valence: 50 Contacts(MAX)\n *By: Morteza Zakeri (2011-12)");
printf("\n\nThis program allows you to have a list of your contacts.\nIt also allows you to have your listing added or deleted from your list.\nOther features of this program include:\nSearch,edit,sort & list.\n\n ::Press a key to return main page & continue program.|-->");
getch();
}
//END OF PROGRAM.
/* test input and output:
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment