📄 digiv15.cpp
字号:
}
while((!infile.eof())&&(flag==0))
{ infile.read((char*)&aperson,sizeof(Cperson));
if((strcmp(fname,fname1)==0) && (strcmp(lname,lname1)==0))
{ cout<<"\nENTER THE NEW EMAIL ID:";
gets(email_id);
outfile.write((char*)&aperson,sizeof(Cperson));
flag=1;
}
else
outfile.write((char*)&aperson,sizeof(Cperson));
}
infile.close();
outfile.close();
remove("diary.dat");
rename("temp.dat","diary.dat");
break;
case 8://MODIFY THE REMARKS
cout<<"\nENTER FIRST NAME:";gets(fname1);
l=strlen(fname1);
for(i=0;i<l;i++)
{ fname1[i]=toupper(fname1[i]);
}
cout<<"\nENTER LAST NAME:";gets(lname1);
l=strlen(lname1);
for(i=0;i<l;i++)
{ lname1[i]=toupper(lname1[i]);
}
infile.open("diary.dat",ios::in|ios::beg);
outfile.open("temp.dat",ios::out);
while(!infile)
{ cout<<"\nERROR";
exit(0);
}
while((!infile.eof())&&(flag==0))
{ infile.read((char*)&aperson,sizeof(Cperson));
if((strcmp(fname,fname1)==0) && (strcmp(lname,lname1)==0))
{ cout<<"\nENTER THE REMARKS:";
gets(remarks);
outfile.write((char*)&aperson,sizeof(Cperson));
flag=1;
}
else
outfile.write((char*)&aperson,sizeof(Cperson));
}
infile.close();
outfile.close();
remove("diary.dat");
rename("temp.dat","diary.dat");
break;
}
}while(ch2!=9);
}
//end of function modify
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//FUNCTION TO SEARCH FOR A CONTACT
void Cperson::search(void)
{ int l;
ifstream infile;
char fname1[20];
char lname1[20];
cout<<"\nENTER FIRST NAME:";
gets(fname1);
l=strlen(fname1);
for(int i=0;i<l;i++)
{ fname1[i]=toupper(fname1[i]);
}
cout<<"\nENTER LAST NAME:";
gets(lname1);
l=strlen(lname1);
for(i=0;i<l;i++)
{ lname1[i]=toupper(lname1[i]);
}
infile.open("diary.dat",ios::in);
if(!infile)
{ cout<<"\nERROR";
exit(0);
}
infile.seekg(0,ios::beg);
infile.read((char*)&aperson,sizeof(Cperson));
while (!infile.eof())
{ if((strcmp(fname,fname1)==0) )
{ clrscr();
aperson.show_data();
getch();
}
infile.read((char*)&aperson,sizeof(Cperson));
}
infile.close();
}
//end of function to search
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//FUNCTION TO DELETE A CONTACT
void Cperson::delet(void)
{ ifstream fio("diary.dat",ios::in);
ofstream fil("temp.dat",ios::out);
int refer;
char found='f',confirm='n';
cout<<"\n\tEnter reference no. of contact to be deleted :";
cin>>refer;
while(!fio.eof())
{ fio.read((char *)&aperson,sizeof(aperson));
if(getrefer()==refer)
{ found='t';
cout<<"\n\tAre you sure you want to delete(y/n) :";
cin>>confirm;
if(confirm=='n')
fil.write((char *)&aperson,sizeof(aperson));
}
else
fil.write((char *)&aperson,sizeof(aperson));
}
if(found=='f')
{ cout<<"\n\tCONTACT DOES NOT EXIST!!!!";
exit(0);
getch();
}
fio.close();
fil.close();
remove("diary.dat");
rename("temp.dat","diary.dat");
getch();
}
//***********************FUNCTIONS PROTOTYPES***************************
void display(void); //Function to display all contacts
void add_contact(void); //Function to add a contact
void displaymenu(void); //Function to display menu
void help(); //Help function.
//**********************************************************************
//-----------------------MAIN ()----------------------------------------
void main()
{ clrscr();
aperson.login();
}
//**************************************************************************
//-----------------------------------------------------------------------
//FUNCTION TO DISPLAY THE MENU
void displaymenu(void)
{ int ch1;
do
{ clrscr();
cout<<"\n\t\t\tDiGiTAL DiARY v15";
cout<<"\n\n";
cout<<"\n\n1. ENTER CONTACT";
cout<<"\n\n2. SEARCH FOR A CONTACT";
cout<<"\n\n3. MODiFY";
cout<<"\n\n4. DiSPLAY DETAiLS OF ALL THE CONTACTS";
cout<<"\n\n5. DELETE A CONTACT";
cout<<"\n\n6. CHANGE PASSWORD";
cout<<"\n\n7. EXiT";
cout<<"\n\n\n\nENTER YOUR CHOiCE AND PRESS <ENTER>:";
cin>>ch1;
switch(ch1)
{ case 1: add_contact();
break;
case 2: aperson.search();
break;
case 3: aperson.modify();
break;
case 4: display();
break;
case 5: aperson.delet();
break;
case 6: aperson.changepassword();
break;
case 7: clrscr();
cout<<"\n\n\n\n\n\n\n\n\n\n\n";
textcolor(GREEN+BLINK);
cout<<"\n\n";
cputs(" THANK YOU!!");
cout<<"\n\n********************************************************************************";
cout<<"\n\n\n\n\t\t\t **Team KAN** ";
cout<<"\n\n\n\t\t\t Made by :-";
cout<<"\n\n\n\t\t\t Karthik aka Kayjay (member Team KAN)";
delay(2000);
cout<<"\n\n\n\t\t\tEXITING...";
for(int z=0;z<15;z++)
{ cout<<".";
delay(100);
}
delay(1000);
exit(0);
break;
default:cout<<"THE CHOICE YOU HAVE ENTERED DOES NOT EXIST";
cout<<"\nPLEASE ENTER THE RIGHT CHOICE : ";
getch();
}
}while (ch1!=6);
}
//**********************************************************************
//FUNCTION TO ADD A CONTACT
void add_contact(void)
{ clrscr();
ofstream f1;
f1.open("diary.dat",ios::end|ios::app);
aperson.get_data();
f1.write((char*)&aperson,sizeof(Cperson));
f1.close();
}
//**********************************************************************
//FUNCTION TO DISPLAY DATA
void display(void)
{ Cperson aperson;
ifstream f2;
f2.open("diary.dat",ios::beg);
if(!f2)
{ cout<<"ERROR!!!";
cout<<"\n\n\tEXITING!!!!";
exit(0);
}
for(int i=0;!f2.eof();i++)
{ clrscr();
f2.read((char*)&aperson,sizeof(Cperson));
aperson.show_data();
delay(1000);
}
f2.close();
getch();
}
//**********************************************************************
//**********************************************************************
//LOGIN FUNCTION
void Cperson::login ()
{
ifstream infile;
infile.open("details.dat",ios::in|ios::beg);
while(!infile)
{
nofile();
}
char a,b[25],loginid1[25],lpass[25],ch;
int i;
cout<<"\n\n\n\t\tDiGiTAL DiARY v15\n\n\n\n\n\n";
cout<<"*******************************************************************************";
cout<<"\n\nEnter LoginID:";
gets(loginid1);
cout<<"\n\nEnter password:";
gets(lpass);
/*
You may activate this part if you dont
the password to be seen while you are entering it.
I am not sure if this will work in all versions of TC / Borland C++.
fflush(stdin);
do
{ ch=getch();
if(isalnum(ch))
{ b[i]=ch;
cout<<"*";
i++;
}
else
if(ch=='\r')
b[i]='\0';
else if(ch=='\b')
{ i--;
cout<<"\b\b";
}
}while(ch!='\r');
b[i]='\0';
for (int d=0;d<=i;d++) lpass[d]=b[d];
*/
cout<<"\n\n*******************************************************************************";
cout<<"\n\n\n\n\n\n";
delay(250);
cout<<"\n\n\t\t PROCESSING.....";
for(int z=0;z<15;z++)
{ cout<<".";
delay(150);
}
int flag=0;
while((!infile.eof())&&(flag==0))
{ infile.read((char*)&aperson,sizeof(Cperson));
if((strcmp(loginid,loginid1)==0) && (strcmp(password,lpass)==0))
{
infile.close();
cout<<"\n\n\n\t\t\tWELCOME!!!!";
delay(750);
displaymenu();
flag=1;
}
else
{
int ch;
cout<<"\n\n\nWrong ID or Password..";
cout<<"\n\n\nPRESS <1> TO TRY AGAIN OR ANY OTHER NUMBER TO EXIT";
cout<<"\n\n\t\tSELECT YOUR CHOICE AND PRESS <ENTER>:";
cin>>ch;
if (ch==1)
{ clrscr();
login();
}
else
{
clrscr();
cout<<"\n\n\n\n\n\n\n\n\n\n\n";
textcolor(GREEN+BLINK);
cout<<"\n\n";
cputs(" THANK YOU!!");
cout<<"\n\n********************************************************************************";
cout<<"\n\n\n\n\t\t\t **Team KAN** ";
cout<<"\n\n\n\t\t\t Made by :-";
cout<<"\n\n\n\t\t Karthik a.k.a Kayjay (member Team KAN)";
delay(500);
cout<<"\n\nEXiTiNG...";
for(int z=0;z<10;z++)
{ cout<<".";
delay(100);
}
delay(1000);
exit(0);
}
}
}
infile.close();
}
//******************************************************************************************************
//******************************************************************************************************
void Cperson::nofile()
{
char chk[25];
ofstream outfile;
outfile.open("details.dat",ios::out);
clrscr();
cout<<"ERROR!!!";
cout<<"\n\n\nReasons....";
cout<<"\n\n1. Maybe you are running this application for the first time.";
cout<<"\n\n2. Maybe the changes were not made properly.";
cout<<"\n\n3. Maybe there was a memory crash.";
cout<<"\n\n4. Maybe some files would have been misplaced.";
cout<<"\n\n5. Maybe the program did not shut properly.";
cout<<"\n\nNo need to panic..a new ID will be created, it is possible that if you are not using this program for the first time, you may still be able to view your saved contacts..";
cout<<"\n\n\t\tPress any key..";
getch();
clrscr();
z:
cout<<"\nENTER NEW LOGIN ID (max 20 characters):";
gets(loginid);
cout<<"\n\nENTER NEW PASSWORD (max 20 characters): ";
gets(password);
cout<<"\n\nRE-TYPE YOUR NEW PASSWORD : ";
gets(chk);
if ( strcmp(chk,password)==0)
{
outfile.write((char*)&aperson,sizeof(Cperson));
outfile.close();
cout<<"\n\nSAVED!!!!!!";
cout<<"\n\nAs some changes were made, the program will now shut down";
delay(3000);
exit(0);
}
else
{
clrscr();
cout<<"\nYou entered either an invalid Login ID or the password did not match.\n\n\n";
goto z;
}
}
//**************************************************************************
//**************************************************************************
void Cperson::changepassword()
{
clrscr();
ifstream infile;
ofstream outfile;
char loginid2[25],chk[25];
cout<<"\n\n\nENTER LOGIN ID (max 20 characters):";
gets(loginid2);
infile.open("details.dat",ios::in|ios::beg);
outfile.open("tempp.dat",ios::out);
while(!infile)
{
nofile();
}
int flag=0;
while((!infile.eof())&&(flag==0))
{ infile.read((char*)&aperson,sizeof(Cperson));
if((strcmp(loginid,loginid2)==0))
{ cout<<"\nENTER THE NEW PASSWORD: ";
gets(password);
outfile.write((char*)&aperson,sizeof(Cperson));
infile.close();
outfile.close();
remove("details.dat");
rename("tempp.dat","details.dat");
cout<<"\n\nSAVED!!!!!!";
cout<<"\n\n\nReturning to the main menu..";
delay(1000);
displaymenu();
flag=1;
}
else
{
cout<<"\n\nYou have entered an invalid Login ID.";
delay(2000);
changepassword();
}
}
}
//**************************************************************************
//**************************************************************************
//END..
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -