📄 main.cpp
字号:
#include"person.h"
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include <iomanip.h>
//bool jadge(person p1,person p2);
person *add();
void paixu(person *head);
void create(person *head,person *tail);
void print(person *head);
void print11(person *head);
//bool jadgeyun(int n);
//int jsday(person p);
void del(person *head);
void login(person *head);
person a[60];
int count=0;
int tt=0;
person ta[60];
void main()
{
person temp;
int i,j;
char s;
person p[100];
count=3;
cout <<endl;
cout << " *******************************数组处理***********************************" <<endl;
system("pause");
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
for(i=0; i<count; i++)
{
p[1].set_inf("wang",1987,4,5,'M',"3408","han","benke","anhui","2409","eros");
p[2].set_inf("li",1987,11,18,'F',"3408","han","benke","sichuan","2409","xli");
p[0].set_inf("zhang",1989,10,17,'F',"3408","han","benke","sichuan","2409","zhang");
p[i].print();
}
for(int ttt=0;;ttt++)
{
cout <<"\n***********请选择A增加、L排序**************" << endl;
cin >> s;
if(s=='l' || s=='L')
{
system("cls");
for(i=0;i<count-1; i++)
for(j=i+1; j<count; j++)
{
if(strcmp(p[i].get_name(),p[j].get_name())>0)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
cout<<"按任意键排序!" << endl;
system("pause");
cout << " ********************按字符串排序后*********************\n"<< endl;
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
for(i=0; i<count; i++)
p[i].print();
break;
}
if(s=='a' || s=='A')
{
system("cls");
int tn;
cout << "请输入本次登记的人数:" ;
cin >> tn;
for(int t1=count; t1<count+tn; t1++)
{
char name[20];
char sex;
b birthday;
char num[20];
char nationality[20];
char education[20];
char address[50];
char telNum[20];
char Email[30];
cout << "请输入姓名、年龄、性别、身份证、民族、教育程度、住址、电话、邮箱:" << endl;
cin >> name >> birthday.year>>birthday.month>>birthday.day >> sex >> num>>nationality>>education>>address>>telNum>>Email;
p[t1].set_inf(name,birthday.year,birthday.month,birthday.day ,sex, num,nationality,education,address,telNum,Email);
}
count+=tn;
cout <<"登记完成!" << endl;
system("pause");
}
else
cout << "输入错误,重新输入!"<< endl;
}
cout << endl;
cout<<"按任意键清屏!" << endl;
system("pause");
system("cls");
system("pause");
cout <<" *******************************链表处理***********************************"<< endl;
person *head=NULL, *tail=NULL;
person *ptr=NULL;
head=tail=new person;
tail->next=NULL;
system("pause");
ptr=new person;
ptr->set_inf("li",1987,11,18,'F',"2222","han","Ma","sichuang","5570","xli");
tail->next=ptr;
tail=ptr;
ptr=new person;
ptr->set_inf("wang",1987,4,5,'M',"3408","han","Ma","anhui","7408","eros");
tail->next=ptr;
tail=ptr;
ptr=new person;
ptr->set_inf("Han",1987,8,1,'M',"3333","han","Ma","shanxi","7400","xhan");
tail->next=ptr;
tail=ptr;
tail->next=NULL;
count=3;
cout <<"请增加数据:(输入0则推出)" <<endl;
create(head,tail);
system("pause");
system("cls");
system("pause");
cout << "当前登记的居民有:" << endl;
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
print(head);
ptr=head->next;
count=1;
while(ptr!=NULL)
{
count++;
ptr=ptr->next;
}
paixu(head);
cout <<"\n**********请按任意键显示按生日排序的结果*************" << endl;
system("pause");
system("cls");
cout <<"\n ****************按生日排序的结果****************\n" << endl;
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
print11(head);
cout <<"删除"<< endl;
del(head);
system("pause");
system("cls");
ptr=head->next;
count=1;
while(ptr!=NULL)
{
count++;
ptr=ptr->next;
}
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
print(head);
cout <<"增加"<< endl;
login(head);
system("pause");
system("cls");
cout<<setw(10)<<"姓名"<<setw(12)<<"年龄"<<setw(6)<<"性别"<<setw(7)<<"身份证"
<<setw(7)<<"民族"<<setw(10) <<"教育程度"<<setw(8)<<"住址"<<setw(8)<<"电话"<<setw(10)<<"邮箱"<<endl;
ptr=head->next;
count=1;
while(ptr!=NULL)
{
count++;
ptr=ptr->next;
}
paixu(head);
print11(head);
system("pause");
}
/*bool jadgeyun(int n)
{
if(n%4==0 && (n%100!=0) || (n%400==0))
return true;
else
return false;
}*/
/*int jsday(person p)
{
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int sum=0,msum=0;
int cc=0;
for(int i=1900;i<p.get_birth().year;i++)
if(jadgeyun(i))
cc++;
for(int j=0; j<p.get_birth().month;j++)
msum+=a[i];
sum=(p.get_birth().year-1900)*365+msum+p.get_birth().day+cc;
return sum;
}*/
/*bool jadge(person p1,person p2)//year da;
{
if(p1.get_birth().year<p2.get_birth().year)
return false;
else if(p1.get_birth().month<p2.get_birth().month)
return false;
else if(p1.get_birth().day<p2.get_birth().day)
return false;
return true;
}
*/
person *add()
{
person *p=new person;
char name[20];
char sex;
b birthday;
char num[20];
char nationality[20];
char education[20];
char address[50];
char telNum[20];
char Email[30];
cout << "请输入姓名、年龄、性别、身份证、民族、教育程度、住址、电话、邮箱:" << endl;
cin >> name >> birthday.year>>birthday.month>>birthday.day >> sex >> num>>nationality>>education>>address>>telNum>>Email;
p->set_inf(name,birthday.year,birthday.month,birthday.day ,sex, num,nationality,education,address,telNum,Email);
return p;
}
void paixu(person *head)
{
int i=1;
person *temp;
temp=head->next;
while(temp!=NULL)
{
ta[i++]=*temp;
temp=temp->next;
}
person tt;
int min,f;
for(i=1; i<count-1; i++)
{
min=ta[i].get_birth();
f=i;
for(int j=i+1;j<count;j++)
{
if(min>ta[j].get_birth())
{
min=ta[j].get_birth();
f=j;
}
}
tt=ta[f];
ta[f]=ta[i];
ta[i]=tt;
}
}
void create(person *head,person *tail)
{
int n;
cout << "请输入本次登记的人数:" ;
cin >> n;
for(int i=0; i<n ;i++)
{
person *q=add();
tail->next=q;
tail=q;
tail->next=NULL;
tt++;
}
cout <<"登记完成!" << endl;
}
void print(person *head)
{
person *temp;
temp=head->next;
if(temp->next==NULL)
cout << "Kong" << endl;
else
{
while(temp!=NULL)
{
temp->print();
temp=temp->next;
}
}
}
void print11(person *head)
{
for(int t2=1;t2<count;t2++)
ta[t2].print();
}
/*void del(person *head,char *n)
{
cout << "Input";
cin >> n;
person *temp,*t,*p,*q;
temp=head->next;
temp=head;
while(t!=NULL)
{
while(t!=NULL)
{
if(strcmp(temp->next->getname(),n)==0)
p=temp;
t=t->next;
}
p->next=
}
}*/
void del(person *head)
{
char name[20];
cout << "Input" << endl;
cin >> name;
person *p1,*p2;
p1=head;
if(head==NULL)
{
cout<<"没有元素,无法删除:"<<endl;
}
while(strcmp(p1->get_name(),name)!=0 && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->get_name(),name)==0)
{
if(p1==head) head=p1->next;//删除head后必须把head重新定义
else p2->next=p1->next;
delete p1;
cout<<"删除了:"<<name<< endl;
}
else
cout<<name<<"没有找到!"<<endl;
}
void login(person *head) //这个函数是增加一个人用
{
person *p0,*p1,*p2;
p1=head;
p0=add();
if(head->next==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while(strcmp(p0->get_name(),p1->get_name())>0 && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
}
if(strcmp(p0->get_name(),p1->get_name())<=0)
{
if(head==p1)
{
head=p0;
p0->next=p1;
}
else
{
p2->next=p0;
p0->next=p1;
}
}
else
{
p2->next=p0;
p0->next=NULL;
}
}
/*int n;//为了动态分布链表
person * jumin()
{ person *head,*p1,*p2;
n=0;
p1=p2=new person; //新的结构体,指针指向结构体,使用new命令为心的结构体放出空间
char name[20];
b birthday;
char sex;
char num[20];
char nationality[20];
char education[20];
char address[50];
char telNum[20];
char Email[30];
cout<<"请输入居民的名字:"<<endl;
cin>>name;
cout<<"请继续输入他(她)的生日、性别、身份证号、民族、教育程度、电话、电子邮箱:"<<endl;
cin>>birthday.year;cin>>birthday.month;cin>>birthday.day;
cin>>sex;
cin>>num;
cin>>nationality;
cin>>education;
cin>>telNum;
cin>>Email;
p1->set_inf(name,birthday.year,birthday.month,birthday.day,sex, num,nationality,education,address,telNum, Email);
head=NULL;
while (strcmp(p1->get_name(),"#")!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=new person;
cout<<"请输入居民的名字(输入'#'结束):"<<endl;
cin>>name;
if(strcmp(p1->get_name(),"#")!=0)
{
cout<<"请继续输入他(她)的生日、性别、身份证号、民族、教育程度、电话、电子邮箱:"<<endl;
cin>>birthday.year;cin>>birthday.month;cin>>birthday.day;
cin>>sex;
cin>>num;
cin>>nationality;
cin>>education;
cin>>telNum;
cin>>Email;
p1->set_inf(name,birthday.year,birthday.month,birthday.day,sex, num,nationality,education,address,telNum, Email);
}
p2->next=NULL;
}
return head;
}
*/
/*void print_in_age(person *head) //这个函数是按照年龄排列进行输出
{
person *p1,*p2;
p1=head;
char c[10];
int x;
cout<<setw(10)<<"姓名"<<setw(10)<<"年龄"<<setw(9)<<"性别"<<setw(10)<<"身份证"
<<setw(7)<<"民族"<<setw(10)<<"教育程度"<<setw(10)<<"电话"<<setw(10)<<"邮箱"<<endl;
while(p1!=NULL) //冒泡排序
{
p2=p1->next;
while(p2!=NULL)
{
if(judge(*p1,*p2))
{
strcpy(c,p1->name);
strcpy(p1->name,p2->name);
strcpy(p2->name,c);
x=p1->age;
p1->age=p2->age;
p2->age=x;
strcpy(c,p1->sex);
strcpy(p1->sex,p2->sex);
strcpy(p2->sex,c);
x=p1->num;
p1->num=p2->num;
p2->num=x;
strcpy(c,p1->nationality);
strcpy(p1->nationality,p2->nationality);
strcpy(p2->nationality,c);
strcpy(c,p1->edcuation);
strcpy(p1->edcuation,p2->edcuation);
strcpy(p2->edcuation,c);
strcpy(c,p1->email);
strcpy(p1->email,p2->email);
strcpy(p2->email,c);
x=p1->tel;
p1->tel=p2->tel;
p2->tel=x;
}
p2=p2->next;
}
p1=p1->next;
}
p1=head;
while (p1!=NULL)
{
cout<<setw(10)<<p1->name<<setw(10)<<p1->age;
cout<<setw(10)<<p1->sex<<setw(12)<<p1->num<<setw(6)<<p1->nationality;
cout<<setw(6)<<p1->edcuation<<setw(10)<<p1->tel<<setw(10)<<p1->email<<endl;
p1=p1->next;
}
}
void print_in_name(person *head) //这个函数是按照名字排列进行输出
{
person *p1,*p2;
p1=head;
char c[10];
int x;
cout<<setw(10)<<"姓名"<<setw(10)<<"年龄"<<setw(4)<<"性别"<<setw(12)<<"身份证"<<setw(6)<<"民族"<<setw(6)<<"教育程度"<<setw(10)<<"电话"<<setw(10)<<"邮箱"<<endl;
while(p1!=NULL) //冒泡排序
{
p2=p1->next;
while(p2!=NULL)
{
if(strcmp(p1->name,p2->name)>0)
{
strcpy(c,p1->name);
strcpy(p1->name,p2->name);
strcpy(p2->name,c);
x=p1->age;
p1->age=p2->age;
p2->age=x;
strcpy(c,p1->sex);
strcpy(p1->sex,p2->sex);
strcpy(p2->sex,c);
x=p1->num;
p1->num=p2->num;
p2->num=x;
strcpy(c,p1->nationality);
strcpy(p1->nationality,p2->nationality);
strcpy(p2->nationality,c);
strcpy(c,p1->edcuation);
strcpy(p1->edcuation,p2->edcuation);
strcpy(p2->edcuation,c);
strcpy(c,p1->email);
strcpy(p1->email,p2->email);
strcpy(p2->email,c);
x=p1->tel;
p1->tel=p2->tel;
p2->tel=x;
}
p2=p2->next;
}
p1=p1->next;
}
p1=head;
while (p1!=NULL)
{
cout<<setw(10)<<p1->name<<setw(10)<<p1->age;
cout<<setw(4)<<p1->sex<<setw(12)<<p1->num<<setw(6)<<p1->nationality;
cout<<setw(6)<<p1->edcuation<<setw(10)<<p1->tel<<setw(10)<<p1->email<<endl;
p1=p1->next;
}
}*/
/*
person *login(person *head,person *asd) //这个函数是增加一个人用
{
person *p0,*p1,*p2;
p1=head;
p0=asd;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while(strcmp(p0->name,p1->name)>0 && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
}
if(strcmp(p0->name,p1->name)<=0)
{
if(head==p1)
{
head=p0;
p0->next=p1;
}
else
{
p2->next=p0;
p0->next=p1;
}
}
else
{
p2->next=p0;
p0->next=NULL;
}
return head;
}
person *del(person *head,char name[])
{
struct human*p1,*p2;
p1=head;
while(strcmp(p1->name,name)!=0 && p1->next!=NULL)//当p1所指的name与传入的name相同时,结束循环
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->name,name)==0)
{
if(p1=head)
head=p1->next;
else
if(p1==NULL)
p2=NULL;
else
p2->next=p1->next;
delete p1;
cout<<"已将"<<name<<"删除"<<endl;
}
else
cout<<name<<"没有找到,无法删除"<<endl;
return head;
}
*/
/*void main()
{
char del_man[10];
human *s,*t;
s=junmin();print_in_age(s);
cout<<"请输入你要删除的人:"<<endl;
cin>>del_man;
s=del(s,del_man);
cout<<"删除后,按姓名排列为:"<<endl;
print_in_name(s);
t=new human;
cout<<"请输入居民的名字(输入'#'结束):"<<endl;
cin>>t->name;
if(strcmp(t->name,"#")!=0)
{
cout<<"请继续输入他(她)的生日、性别、身份证号、民族、教育程度、电话、电子邮箱:"<<endl;
cin>>t->age;
cin>>t->sex;
cin>>t->num;
cin>>t->nationality;
cin>>t->edcuation;
cin>>t->tel;
cin>>t->email;
}
s=login(s,t);
cout<<"按照年龄排序为:"<<endl;
print_in_age(s);
delete t;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -