?? 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 << " *******************************數(shù)組處理***********************************" <<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 << "請輸入本次登記的人數(shù):" ;
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 <<"請增加數(shù)據(jù):(輸入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**********請按任意鍵顯示按生日排序的結(jié)果*************" << endl;
system("pause");
system("cls");
cout <<"\n ****************按生日排序的結(jié)果****************\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 << "請輸入本次登記的人數(shù):" ;
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) //這個函數(shù)是增加一個人用
{
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;//為了動態(tài)分布鏈表
person * jumin()
{ person *head,*p1,*p2;
n=0;
p1=p2=new person; //新的結(jié)構(gòu)體,指針指向結(jié)構(gòu)體,使用new命令為心的結(jié)構(gòu)體放出空間
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<<"請繼續(xù)輸入他(她)的生日、性別、身份證號、民族、教育程度、電話、電子郵箱:"<<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<<"請輸入居民的名字(輸入'#'結(jié)束):"<<endl;
cin>>name;
if(strcmp(p1->get_name(),"#")!=0)
{
cout<<"請繼續(xù)輸入他(她)的生日、性別、身份證號、民族、教育程度、電話、電子郵箱:"<<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) //這個函數(shù)是按照年齡排列進行輸出
{
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) //這個函數(shù)是按照名字排列進行輸出
{
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) //這個函數(shù)是增加一個人用
{
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相同時,結(jié)束循環(huán)
{
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<<"請輸入居民的名字(輸入'#'結(jié)束):"<<endl;
cin>>t->name;
if(strcmp(t->name,"#")!=0)
{
cout<<"請繼續(xù)輸入他(她)的生日、性別、身份證號、民族、教育程度、電話、電子郵箱:"<<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 + -