⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbook.cpp

📁 这是一个简单的地址簿程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       || ch ==':' ) && cursor.x2<x2-10 && opt==4)
  {
   *string++ = ch;
   *string = 0;
   setcolor(0);
   outtextxy(tx, ty, perm);
   setcolor(15);
   line( cursor.x1, cursor.y, cursor.x2, cursor.y);
   cursor.x1+=8;
   cursor.x2+=8;
   setcolor(0);
   line( cursor.x1, cursor.y, cursor.x2, cursor.y);
  }
  else if ( ch == 8 && *perm!=0 )
  {
   setcolor(15);
   outtextxy(tx, ty, perm);
   string--;
   *string = 0;
   setcolor(0);
   outtextxy(tx, ty, perm);
   setcolor(15);
   line( cursor.x1, cursor.y, cursor.x2, cursor.y);
   cursor.x1-=8;
   cursor.x2-=8;
   setcolor(0);
   line( cursor.x1, cursor.y, cursor.x2, cursor.y);
  }
 }while (ch!=27 && ch!=13);
}

class
{
 char name[50];
 char nickname[50];
 char job[50];
 char email[50];
 char telephone[20];
 char mobile[20];
 char fax[20];
 char address[100];
 char city[50];
 char zip[20];
 char country[50];

 public:
	friend void adbkaddmenu();
	friend void adbkremmenu();
	friend void adbkviewmenu();

	void reset()
	{
	 strcpy(name, "");
	 strcpy(nickname, "");
	 strcpy(job, "");
	 strcpy(email, "");
	 strcpy(telephone, "");
	 strcpy(mobile, "");
	 strcpy(fax, "");
	 strcpy(address, "");
	 strcpy(city, "");
	 strcpy(zip, "");
	 strcpy(country, "");
	}
}info;

void adbkaddmenu()
{
 refreshbox();
 hidemouseptr();
 setcolor(0);
 outtextxy(45, 50,  "     Enter Name: ");
 outtextxy(45, 80,  " Enter Nickname: ");
 outtextxy(45, 110, "     Profession: ");
 outtextxy(45, 140, "      E-mail ID: ");
 outtextxy(45, 170, "  Telephone no.: ");
 outtextxy(45, 200, "     Mobile no.: ");
 outtextxy(45, 230, "            Fax: ");
 outtextxy(45, 260, "        Address: ");
 outtextxy(45, 290, "           City: ");
 outtextxy(45, 320, "       Zip Code: ");
 outtextxy(45, 350, "        Country: ");
 rectangle(200, 40, 400, 65);
 rectangle(200, 70, 400, 95);
 rectangle(200, 100, 400, 125);
 rectangle(200, 130, 500, 155);
 rectangle(200, 160, 400, 185);
 rectangle(200, 190, 400, 215);
 rectangle(200, 220, 400, 245);
 rectangle(200, 250, 500, 275);
 rectangle(200, 280, 400, 305);
 rectangle(200, 310, 400, 335);
 rectangle(200, 340, 400, 365);
 enterlinetext(200, 40, 400, info.name, 1);
 enterlinetext(200, 70, 400, info.nickname, 1);
 enterlinetext(200, 100, 400, info.job, 1);
 enterlinetext(200, 130, 500, info.email, 3);
 enterlinetext(200, 160, 400, info.telephone, 2);
 enterlinetext(200, 190, 400, info.mobile, 2);
 enterlinetext(200, 220, 400, info.fax, 2);
 enterlinetext(200, 250, 500, info.address, 4);
 enterlinetext(200, 280, 400, info.city, 1);
 enterlinetext(200, 310, 400, info.zip, 2);
 enterlinetext(200, 340, 400, info.country, 1);
 adb.open("Address.dat", ios::app);
 adb.write((char*)&info, sizeof(info));
 adb.close();
 setfillstyle(1, 4);
 bar(5, 440, getmaxx()-5, 455);
 setcolor(14);
 outtextxy(20, 445, "Information successfully Added !");
 getch();
 showmouseptr();
}

void adbkremmenu()
{
 char *name=NULL;
 int flag=0;
 refreshbox();
 hidemouseptr();
 setcolor(0);
 outtextxy(100, 110, "Enter Name: ");
 enterlinetext(200, 100, 400, name, 1);
 fstream temp_file;
 adb.open("Address.dat", ios::in);
 temp_file.open("Temp.dat", ios::out);
 adb.read((char*)&info, sizeof(info));
 while(!adb.eof())
 {
  if (strcmpi(name, info.name)!=0)
	temp_file.write((char*)&info, sizeof(info));
  else
	flag=1;
  adb.read((char*)&info, sizeof(info));
 }
 if (strcmpi(name, info.name)!=0 && flag==0)
	temp_file.write((char*)&info, sizeof(info));
 else
	flag=1;
 temp_file.close();
 adb.close();
 if (flag==1)
 {
  setfillstyle(1, 4);
  bar(5, 440, getmaxx()-5, 455);
  setcolor(14);
  outtextxy(20, 445, "Information successfully Deleted !");
  getch();
 }
 else if (flag==0)
 {
  setfillstyle(1, 4);
  bar(5, 440, getmaxx()-5, 455);
  setcolor(14);
  outtextxy(20, 445, "Information Not Found !");
  getch();
 }
 remove("Address.dat");
 rename("Temp.dat", "Address.dat");
 info.reset();
 showmouseptr();
}

void adbkviewmenu()
{
 char *name=NULL;
 char *str=NULL;
 int flag=0;
 refreshbox();
 hidemouseptr();
 setcolor(0);
 outtextxy(100, 40, "Enter Name: ");
 enterlinetext(200, 40, 400, name, 1);
 adb.open("Address.dat", ios::in|ios::app);
 int abc=0;
 if(!adb)
    outtextxy(10, 10, "problem");
 adb.read((char*)&info, sizeof(info));
 adb.read((char*)&info, sizeof(info));
 abc=adb.tellg();
 while (!adb.eof())
 {
  if (strcmpi(name, info.name)==0)
   {
    strcpy(str, "Name: ");
    strcat(str, info.name);
    outtextxy(80, 70, str);

    strcpy(str, "Nickname: ");
    strcat(str, info.nickname);
    outtextxy(80, 100, str);

    strcpy(str, "Profession: ");
    strcat(str, info.job);
    outtextxy(80, 130, str);

    strcpy(str, "Email ID: ");
    strcat(str, info.email);
    outtextxy(80, 160, str);

    strcpy(str, "Telephone: ");
    strcat(str, info.telephone);
    outtextxy(80, 190, str);

    strcpy(str, "Mobile: ");
    strcat(str, info.mobile);
    outtextxy(80, 220, str);

    strcpy(str, "Fax: ");
    strcat(str, info.fax);
    outtextxy(80, 250, str);

    strcpy(str, "Address: ");
    strcat(str, info.address);
    outtextxy(80, 280, str);

    strcpy(str, "City: ");
    strcat(str, info.city);
    outtextxy(80, 310, str);

    strcpy(str, "Zip Code: ");
    strcat(str, info.zip);
    outtextxy(80, 340, str);

    strcpy(str, "Country: ");
    strcat(str, info.country);
    outtextxy(80, 370, str);
    flag=1;
    break;
   }
  adb.read((char*)&info, sizeof(info));
  if (adb.eof())
	break;
 }
  adb.close();
  if (flag==1)
  {
   setfillstyle(1, 4);
   bar(5, 440, getmaxx()-5, 455);
   setcolor(14);
   outtextxy(20, 445, "Hit any key to continue...");
  }
  else if (flag==0)
  {
   setfillstyle(1, 4);
   bar(5, 440, getmaxx()-5, 455);
   setcolor(14);
   outtextxy(20, 445, "Information not found !");
  }
  getch();
 showmouseptr();
}

void main()
{
 initialize();
 drawinterface();
 showmouseptr();
 menubutton adbkadd(200, 150, 370, 180, "Add Entry");
 menubutton adbkrem(200, 200, 370, 230, "Delete Entry");
 menubutton adbkview(200, 250, 370, 280, "View Entry");
 menubutton adbkqt(200, 300, 370, 330, "Back");
 hidemouseptr();
 restrictmouseptr(0, 0, getmaxx(), 459);
 setfillstyle(1, 1);
 bar(4, 4, getmaxx()-4, 24);
 setcolor(15);
 outtextxy(250, 10, "ADDRESS BOOK");
 adbkadd.draw();
 adbkrem.draw();
 adbkview.draw();
 adbkqt.draw();
 draw3dbox(2, 2, getmaxx()-2, 457);
 showmouseptr();
 do
 {
  getmousepos(&button, &x, &y);
  if (adbkadd.check() && adbkadd.flag==0)
  {
	adbkadd.onover();
	adbkadd.flag=1;
  }
  if (!adbkadd.check() && adbkadd.flag==1)
  {
	adbkadd.draw();
	adbkadd.flag=0;
  }
  if ((button&1)==1 && adbkadd.check())
  {
	adbkadd.flag=2;
	adbkrem.flag=2;
	adbkview.flag=2;
	adbkqt.flag=2;
	adbkaddmenu();
	refreshbox();
	adbkadd.draw();
	adbkrem.draw();
	adbkview.draw();
	adbkqt.draw();
	adbkadd.flag=0;
	adbkrem.flag=0;
	adbkview.flag=0;
	adbkqt.flag=0;
  }

  if (adbkrem.check() && adbkrem.flag==0)
  {
	adbkrem.onover();
	adbkrem.flag=1;
  }
  if (!adbkrem.check() && adbkrem.flag==1)
  {
	adbkrem.draw();
	adbkrem.flag=0;
  }
  if ( (button & 1)==1 && adbkrem.check() )
  {
	adbkadd.flag=2;
	adbkrem.flag=2;
	adbkview.flag=2;
	adbkqt.flag=2;
	adbkremmenu();
	refreshbox();
	adbkadd.draw();
	adbkrem.draw();
	adbkview.draw();
	adbkqt.draw();
	adbkadd.flag=0;
	adbkrem.flag=0;
	adbkview.flag=0;
	adbkqt.flag=0;
  }

  if (adbkview.check() && adbkview.flag==0)
  {
	adbkview.onover();
	adbkview.flag=1;
  }
  if (!adbkview.check() && adbkview.flag==1)
  {
	adbkview.draw();
	adbkview.flag=0;
  }
  if ( (button & 1)==1 && adbkview.check() )
  {
	adbkadd.flag=2;
	adbkrem.flag=2;
	adbkview.flag=2;
	adbkqt.flag=2;
	adbkviewmenu();
	refreshbox();
	adbkadd.draw();
	adbkrem.draw();
	adbkview.draw();
	adbkqt.draw();
	adbkadd.flag=0;
	adbkrem.flag=0;
	adbkview.flag=0;
	adbkqt.flag=0;
  }

  if (adbkqt.check() && adbkqt.flag==0)
  {
	adbkqt.onover();
	adbkqt.flag=1;
  }
  if (!adbkqt.check() && adbkqt.flag==1)
  {
	adbkqt.draw();
	adbkqt.flag=0;
  }
  if ((button&1)==1 && adbkqt.check())
	break;
 }while (1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -