📄 telephone_directory.cpp
字号:
modified = 1 ;
valid = 1 ;
gotoxy(13,16) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME OF THE PERSON" ;
gotoxy(13,16) ;
gets(name) ;
strupr(name) ;
if (strlen(name) > 19 || strlen(name) == 0)
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"LENGTH SHOULD NOT BE BLANK OR GREATER THAN 19" ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,16) ; clreol() ;
}
}
gotoxy(1,25) ; clreol() ;
gotoxy(13,17) ;
cout <<"Change (y/n) : " ;
do
{
valid = 1 ;
gotoxy(28,17) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(28,17) ; clreol() ;
}
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{
modified = 1 ;
valid = 1 ;
gotoxy(13,17) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER THE PHONE NO. OF THE PERSON, <ENTER> FOR BLANK";
gotoxy(13,17) ;
gets(phone1) ;
if ((strlen(phone1) < 7 && strlen(phone1) > 0) || (strlen(phone1) > 9))
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"LENGTH SHOULD NOT BE GREATER THAN 9 OR LESS THAN 7" ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,17) ; clreol() ;
}
if (strlen(phone1) == 0)
strcpy(phone1,"-") ;
}
gotoxy(1,25) ; clreol() ;
gotoxy(13,18) ;
cout <<"Change (y/n) : " ;
do
{
valid = 1 ;
gotoxy(28,18) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(28,18) ; clreol() ;
}
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{
modified = 1 ;
valid = 1 ;
gotoxy(13,18) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER THE PHONE NO. OF THE PERSON, <ENTER> FOR BLANK";
gotoxy(13,18) ;
gets(phone2) ;
if ((strlen(phone2) < 7 && strlen(phone2) > 0) || (strlen(phone2) > 9))
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"LENGTH SHOULD NOT BE GREATER THAN 9 OR LESS THAN 7" ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,18) ; clreol() ;
}
if (strlen(phone2) == 0)
strcpy(phone2,"-") ;
}
gotoxy(1,25) ; clreol() ;
gotoxy(13,19) ;
cout <<"Change (y/n) : " ;
do
{
valid = 1 ;
gotoxy(28,19) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(28,19) ; clreol() ;
}
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{
modified = 1 ;
valid = 1 ;
gotoxy(13,19) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER THE PHONE NO. OF THE PERSON, <ENTER> FOR BLANK" ;
gotoxy(13,19) ;
gets(phone3) ;
if ((strlen(phone3) < 7 && strlen(phone3) > 0) || (strlen(phone3) > 9))
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"LENGTH SHOULD NOT BE GREATER THAN 9 OR LESS THAN 7" ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,19) ; clreol() ;
}
if (strlen(phone3) == 0)
strcpy(phone3,"-") ;
}
gotoxy(1,25) ; clreol() ;
gotoxy(13,20) ;
cout <<"Change (y/n) : " ;
do
{
valid = 1 ;
gotoxy(28,20) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(28,20) ; clreol() ;
}
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{
modified = 1 ;
valid = 1 ;
gotoxy(13,20) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER THE E_MAIL ADDRESS OF THE PERSON, <ENTER> FOR BLANK" ;
gotoxy(13,20) ;
gets(e_mail) ;
if ((strlen(e_mail) < 10 && strlen(e_mail) > 0))
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"LENGTH SHOULD NOT BE LESS THAN 10";
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,20) ; clreol() ;
}
if (strlen(e_mail) == 0)
strcpy(e_mail,"-") ;
}
gotoxy(1,25) ; clreol() ;
gotoxy(13,21) ;
cout <<"Change (y/n) : " ;
do
{
valid = 1 ;
gotoxy(28,21) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(28,21) ; clreol() ;
}
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{
modified = 1 ;
valid = 1 ;
gotoxy(13,21) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ADDRESS OF THE PERSON" ;
gotoxy(13,21) ;
gets(address) ;
strupr(address) ;
if (strlen(address) > 43 || strlen(address) == 0)
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ;
cout <<"SHOULD NOT BE BLANK OR GREATER THAN 48" ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(13,21) ; clreol() ;
}
}
if (!modified)
return ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,23) ; clreol() ;
gotoxy(1,23) ;
cout <<"Do you want to save the record (y/n) : " ;
do
{
valid = 1 ;
gotoxy(41,23) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(41,23) ; clreol() ;
}
} while ( !valid ) ;
if (ch == 'N')
return ;
fstream file ;
file.open("TDIARY.DAT", ios::out | ios::ate) ;
int recno ;
recno = t_code ;
int location ;
location = (recno-1) * sizeof(diary) ;
file.seekp(location) ;
file.write((char *) this, sizeof(diary)) ;
file.close() ;
sort() ;
clrscr() ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(1,14) ;
cout <<"Record Modified" ;
m.line_hor(1,79,24,196) ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// CLASS NAME : DIARY
// FUNCTION NAME : MODIFY
// DETAILS : IT GIVES THE CODE NO. TO MODIFY THE
// RECORD IN DIARY'S FILE (TDIARY.DAT)
//**********************************************************
void diary :: modify(void)
{
menu m ;
clrscr() ;
int valid ;
int t_code=0, t;
char t1_code[5], t2_code[5] ;
char ch ;
gotoxy(3,3) ;
cout <<"Enter Code no. of the record to be modify " ;
gotoxy(3,4) ;
cout <<"or Press <ENTER> to see from the list or `0' to exit : " ;
gets(t1_code) ;
t = atoi(t1_code) ;
t_code = t ;
if (t1_code[0] == '0')
return ;
if (t1_code[0] != '\0')
{
clrscr() ;
if (!found_record(t_code))
{
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(3,15) ;
cout <<"Record not found" ;
m.line_hor(1,79,24,196) ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
return ;
}
display_record(t_code) ;
gotoxy(3,12) ;
cout <<"Do you want to modify this Record (y/n) : " ;
do
{
valid = 1 ;
gotoxy(45,12) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(45,12) ; clreol() ;
}
} while (!valid ) ;
if (ch == 'N')
return ;
modify_record(t_code) ;
return ;
}
display_list() ;
gotoxy(1,25) ;
clreol() ;
gotoxy(3,25) ;
cout <<"Enter Code no. of the record or <ENTER> to exit " ;
gets(t2_code) ;
t = atoi(t2_code) ;
t_code = t ;
if (t2_code[0] == '\0')
return ;
clrscr() ;
if (!found_record(t_code))
{
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(3,15) ;
cout <<"Record not found" ;
m.line_hor(1,79,24,196) ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getch() ;
return ;
}
display_record(t_code) ;
gotoxy(3,12) ;
cout <<"Do you want to modify this Record (y/n) : " ;
do
{
valid = 1 ;
gotoxy(45,12) ;
ch = getche() ;
ch = toupper(ch) ;
if (ch != 'Y' && ch != 'N')
{
valid = 0 ;
sound(500) ;
delay(100) ;
nosound() ;
gotoxy(45,12) ; clreol() ;
}
} while (!valid ) ;
if (ch == 'N')
return ;
modify_record(t_code) ;
}
//**********************************************************
// CLASS NAME : DIARY
// FUNCTION NAME : SORT
// DETAILS : IT SORTS THE RECORD IN THE DIARY'S
// FILE (TDIARY.DAT)
//**********************************************************
void diary :: sort(void)
{
int i=0,j ;
diary arr[100] ;
diary temp ;
fstream file ;
file.open("TDIARY.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) &arr[i], sizeof(diary)))
i++ ;
int size ;
size = i ;
file.close() ;
for (i=1; i<size; i++)
for (j=0; j<size-i; j++)
{
if (strcmp(arr[j].name,arr[j+1].name) > 0)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
int t_code = 1 ;
for (i=0; i<size; i++)
{
arr[i].code = t_code ;
t_code++ ;
}
file.open("TDIARY.DAT", ios::out) ;
for (i=0; i<size; i++)
file.write((char *) &arr[i], sizeof(diary)) ;
file.close() ;
}
//**********************************************************
// FUNCTION NAME : MAIN
// DETAILS : IT CALLS THE STARTUP FUNCTION AND
// MENU FUNCTION.
//**********************************************************
void main(void)
{
menu m ;
m.startup() ;
m.main_menu() ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -