leishixian.cpp

来自「主要实现人员管理功能」· C++ 代码 · 共 127 行

CPP
127
字号
#include <iostream>
#include"Leidingyi.h"
using namespace std;

int Person::No=0;
int Person::Acount=0;

Person::Person()
{int i=0;
  while(i<22)
  {
   Name[i]=0;
   i++;
   //No=1;
   //Acount=0;
  }
}


void Person::AddNode(Node *m)
{
	Node* q=m;
	while(q->next!=NULL)
	{
		q=q->next;
	}
	Node zzh;
	Person people;
	//people.Name={0};
	q->next=new Node(zzh);
	
		if(q==NULL)
	    {
			cout<<"No enough memory!"<<endl;
		}
	q->next->next=NULL;
	cout<<"Input the name!"<<endl;
	cin>>people.Name;
	
	for(int i=0;i<22;i++)  
	{
		q->next->NName[i]=people.Name[i];
		
		
	}
	//Acount++;
	q->next->No=++No;
	
}

Node* Person::SearchName(Node *q,char name[22])
{
	int mark=1;
	int i=0;
	while(q->next!=NULL)
	{
		if(stricmp(q->next->NName,name)==0)
		{
			cout<<"Person's name is:";
			//for(i=0;i<22;i++)
			//if(q->next->NName[i]!=0)break;
        	cout<<q->next->NName<<endl;
			
			cout<<" Person's number is:"<<q->next->No<<endl;
			mark++;
			return q;
		}
		q=q->next;
	}
	if(mark==1)
	{return NULL;}
}

Node* Person::SearchNo(Node *q,int nNo)
{
	while(q->next!=NULL)
	{
		if(q->next->No==nNo)
		{
			cout<<"Person's name is:"<<q->next->NName<<endl<<"Person's number is:"<<q->next->No<<endl;
			return q;
		}
		q=q->next;
	}

}

void Person::DeleteName(Node *q,char name[22])
{
	Node *m,*n;
	m=SearchName(q,name);
	n=m->next->next;
	delete m->next;
	m->next=n;
    //Person::Acount--;//总人数减少

}

void Person::DeleteNo(Node *q,int number)
{
	Node *m,*n;
	m=SearchNo(q,number);
	n=m->next->next;
	delete m->next;
	m->next=n;
	//Person::Acount--;//总人数减少
}

void Person::ShowAllNode(Node *q)
{
	while(q->next!=NULL)
	{
		cout<<"Person's name is:"<<q->next->NName<<endl<<"Person's number is:"<<q->next->No<<endl;
        q=q->next;
	}
			

}
Person::Person(char* name)
{
  int i=0;
  while(i<20)
  {
   Name[i]=name[i];
   i++;
  }
}

⌨️ 快捷键说明

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