5_42.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
- # include<iostream.h>
- #include <iomanip.h>
- # include<string.h>
- struct date
- {
- int year; int month; int day;
- };
- struct address
- {
- char name[10]; char sex;char tel[12]; date birthday;
- };
- void input(address myfriend[],int &n)
- {
- int i=0;
- char name[10];
- cout<<"Input my friends'name ,with'#' to end:"<<endl;
- cin>>name;
- while (strcmp(name,"#")!=0)
- {
- strcpy(myfriend[i].name,name);
- cout<<"Continue to input my friends'sex(F/M),tel and birthday:"<<endl;
- cin>>myfriend[i].sex;
- cin>>myfriend[i].tel;
- cin>>myfriend[i].birthday.year>>myfriend[i].birthday.month>>
- myfriend[i].birthday.day;
- i++;
- cout<<"n input name,with'#' to end:"<<endl;
- cin>>name;
- }
- n=i;
- }
- void output(address myfriend[],int n)
- {
- int i;
- cout<<setw(11)<<"name"<<setw(5)<<"sex"<<setw(10)<<"telNO."
- <<setw(16)<<"birthday"<<endl;
- for(i=0;i<n;i++)
- {
- cout<<setw(11)<<myfriend[i].name<<setw(4)<<myfriend[i].sex<<setw(16)
- <<myfriend[i].tel<<" ";
- cout<<setw(5)<<myfriend[i].birthday.year;
- cout<<setw(3)<<myfriend[i].birthday.month<<" ";
- cout<<setw(3)<<myfriend[i].birthday.day<<endl;
- }
- cout<<endl;
- }
- int find(address myfriend[],int n,char findname[])
- {
- int i;
- for (i=0;i<n;i++)
- if(strcmp(myfriend[i].name,findname)==0)
- return i;
- return -1;
- }
- void main()
- {
- address myfriend[50];
- int n;
- int index;
- char findname[10];
- input(myfriend,n);
- output(myfriend,n);
- cout<<"find name?";
- cin>>findname;
- index=find(myfriend,n,findname);
- if(index==-1)
- cout<<" NO find!"<<endl;
- else
- {
- cout<<endl;
- cout<<setw(11)<<"name"<<setw(5)<<"sex"<<setw(10)<<"telNO."
- <<setw(16)<<"birthday"<<endl;
- cout<<setw(11)<<myfriend[index].name<<setw(4)<<myfriend[index].sex
- <<setw(16)<<myfriend[index].tel<<" ";
- cout<<setw(5)<<myfriend[index].birthday.year;
- cout<<setw(3)<<myfriend[index].birthday.month;
- cout<<setw(3)<<myfriend[index].birthday.day<<endl;
- }
- }