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

📄 xqd.cpp

📁 复数计算器:1、设计的任务要求 (1) 所设计的复数计算器可以进行+、-、*、+=、-=、*=、++、--、>=、<=、==、!=运算符
💻 CPP
字号:
#include<iostream>#include<fstream>#include<string>#include<iomanip>using namespace std;struct LNode{  char name[20];  char phonenumber[20];  struct LNode *prior;  struct LNode *next;};typedef struct LNode* LN;class  Imf{  LN head; public:  Imf()  {    head=new struct LNode;    head->next=head;    head->prior=head;  }  ~Imf();  void Addnew_message();  void Insert_message(LN L);  void Delete_message();  void Display_message();  void Search_message();  void File_close();};Imf::~Imf(){  LN p,s;  p=head->next;  while(p!=head)    {      s=p->next;      delete p;      p=s;    }  delete head;}void  Imf::Addnew_message(){ system("clear");  char c[20]={'y'};   LN p;  while(c[0]=='Y'||c[0]=='y')   { p=new struct LNode;     cout<<"Please input name:\n";     cin>>p->name;     cout<<"Please input phonenumber:\n";     cin>>p->phonenumber;     Insert_message(p);     cout<<"Continue(y/n):";     cin>>c;     while(strlen(c)>1||(c[0]!='Y'&&c[0]!='y'&&c[0]!='N'&&c[0]!='n'))       { cout<<"Input error!Input again!\n";         cout<<"Continue(y/n):";         cin>>c;        }    } }void Imf::Insert_message(LN L){  if(head->next==head)    { head->next=L;      head->prior=L;      L->prior=head;      L->next=head;           }  else    {      L->prior=head;      L->next=head->next;      head->next=L;      L->next->prior=L;    }}void  Imf::Display_message(){  LN p;  p=head->next;  system("clear");  while(p!=head)    {      cout<<"\n\tName:"<<p->name<<endl;      cout<<"\t Tel:"<<p->phonenumber<<endl;      p=p->next;        }  cout<<"Enter any key to exit!\n";  cin.get();  cin.get();}void  Imf::Delete_message(){ char ch[20],c[20]={'y'};  LN p;  system("clear");  while(c[0]=='Y'||c[0]=='y')    {      cout<<"Input the name or the phonenumber!\n";      cin>>ch;      p=head->next;      while(p!=head)	{ 	  if(strcmp(p->name,ch)==0||strcmp(p->phonenumber,ch)==0)	    {  	      p->prior->next=p->next;	      p->next->prior=p->prior;	      delete p;	      cout<<"The message has been deleted!\n ";	      break;	    }	  else	    p=p->next;	}      if(p==head&&(ch!=p->name||ch!=p->phonenumber)) 	cout<<"No this message!\n";      cout<<"Continue(y/n):";      cin>>c;      while(strlen(c)>1||(c[0]!='Y'&&c[0]!='y'&&c[0]!='N'&&c[0]!='n'))       { cout<<"Input error!Input again!\n";         cout<<"Continue(y/n):";         cin>>c;        }     }}void Imf::Search_message(){ char ch[20],c[20]={'y'};  LN p;  system("clear");  while(c[0]=='Y'||c[0]=='y')    {      cout<<"Input the name or the phonenumber!\n";      cin>>ch;      p=head->next;      while(p!=head)	{ 	  if(strcmp(p->name,ch)==0||strcmp(p->phonenumber,ch)==0)	    { cout<<"\tName:"<<p->name<<endl;	      cout<<"\t Tel:"<<p->phonenumber<<endl<<endl;  	      break; 	    }	  p=p->next;	}      if(p==head) 	cout<<"No this message!\n";      cout<<"Continue(y/n):";      cin>>c;      while(strlen(c)>1||(c[0]!='Y'&&c[0]!='y'&&c[0]!='N'&&c[0]!='n'))	{ cout<<"Input error!Input again!\n";	  cout<<"Continue(y/n):"; 	  cin>>c; 	}     }  /* cout<<"Enter any key to exit!\n";  cin.get();  cin.get();*/}  void Imf::File_close(){ LN p;  p=head->next;  ofstream outfile("friends.dat",ios::binary);  if(!outfile)    {      cout<<"Oper error!"<<endl;      abort();    }  while(p!=head)    {      outfile.write((char *)p,sizeof(struct LNode));        p=p->next;     } outfile.close();}int main(){  char choise[10];  Imf D;   LN L;  ifstream infile("friends.dat",ios::binary);  if(!infile)   {     cout<<"Open error!"<<endl;   }  else    {      while(1)	{ L=new struct LNode;	  infile.read((char *)L,sizeof(struct LNode));       		   if(infile.eof()) 	   break;	   else  D.Insert_message(L);	}    }        while(1)     {system("clear");       cout<<"\n\n\n\t***********************PHONE BOOK**************************\n\n\n";      cout<<"\t     1: ADD NEW RECORD\n\n";      cout<<"\t     2: DISPLAY ALL RECORDS\n\n";      cout<<"\t     3: DELETE SOME MESSAGE\n\n";      cout<<"\t     4: SEARCH FOR USEFUL MESSAGE\n\n";      cout<<"\t     5: EXIT\n\n\n";      cout<<"\t***********************************************************\n\n\n";      cout<<"Please chiose from 1 to 5:";      cin>>choise;      while(strlen(choise)>1||choise[0]<'1'||choise[0]>'5')	{ cout<<"Input error!Input again!\n";	  cout<<"Please chiose frome 1 to 5:"; 	  cin>>choise;	}        switch(choise[0]-'0')	{	case 1:D.Addnew_message();break;	case 2:D.Display_message();break;	case 3:D.Delete_message();break;	case 4:D.Search_message();break;        case 5:D.File_close();exit(0);	default:break;	}    } }

⌨️ 快捷键说明

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