#include<iostream> #include<string> using namespace std; struct One{ char name[10]; int age; char sex[10]; char phone[12]; char address[20]; }; void fun1(One *one,int *sum); void fun2(One one[],int sum); void fun3(One one[],int sum); void fun4(One one[],int sum); void fun5(One one[],int sum); void fun6(One one[],int sum); void fun7(); int main() { int choice; int sum=0; while(1) { One one[1000]; cout<<"1,添加联系人"<<endl; cout<<"2,显示联系人"<<endl; cout<<"3,删除联系人"<<endl; cout<<"4,查找联系人"<<endl; cout<<"5,修改联系人"<<endl; cout<<"6,清空"<<endl; cout<<"7,退出通讯录"<<endl; if(sum<1000) { cin>>choice; switch(choice) { case 1:fun1(&one[sum],&sum); break; case 2:fun2(one,sum); break; case 3:fun3(one,sum); break; case 4:fun4(one,sum); break; case 5:fun5(one,sum); break; case 6:fun6(one,sum); break; case 7:fun7(); break; } } } return 0; } void fun1(One *one,int *sum) { cout<<"输入名字"<<endl; cin>> one->name; cout<<"输入年龄"<<endl; cin>> one->age; cout<<"输入性别"<<endl; cin>> one->sex; cout<<"输入电话"<<endl; cin>> one->phone; cout<<"输入地址"<<endl; cin>> one->address; (*sum)++; } void fun2(One one[],int sum) { int i=0; for(i=0;i<=(sum-1);i++) { if(one[i].age!=-1) { cout<<"名字:"<<one[i].name<<"\t"; cout<<"年龄:"<<one[i].age<<"\t"; cout<<"性别:"<<one[i].sex<<"\t"; cout<<"电话:"<<one[i].phone<<"\t"; cout<<"地址:"<<one[i].address<<"\t"; cout<<endl; } } } void fun3(One one[],int sum) { int i,n; string a; cout<<"你要删除:"<<endl; cin>>a; for(i=0;i<sum;i++) { if(a==one[i].name) { n=i; for(i=n;i<sum;i++) { one[i]=one[i+1]; } } } one[sum-1].age=-1; } void fun4(One one[],int sum) { int i; string a; cout<<"你要查找:"<<endl; cin>>a; for(i=0;i<sum;i++) { if(a==one[i].name) { cout<<"名字:"<<one[i].name<<"\t"; cout<<"年龄:"<<one[i].age<<"\t"; cout<<"性别:"<<one[i].sex<<"\t"; cout<<"电话:"<<one[i].phone<<"\t"; cout<<"地址:"<<one[i].address<<"\t"; cout<<endl; } } } void fun5(One one[],int sum) { cout<<"你要修改:"<<endl; int i; string a; cin>>a; for(i=0;i<sum;i++) { if(a==one[i].name) { cout<<"输入名字"<<endl; cin>> one[i].name; cout<<"输入年龄"<<endl; cin>> one[i].age; cout<<"输入性别"<<endl; cin>> one[i].sex; cout<<"输入电话"<<endl; cin>> one[i].phone; cout<<"输入地址"<<endl; cin>> one[i].address; } } } void fun6(One one[],int sum) { int i=0; for(i=0;i<sum;i++) { one[i].age=-1; } cout<<"清除成功!"<<endl; } void fun7() { cout<<"退出成功!"<<endl; }
0.0分
1 人评分
C语言考试练习题_排列 (C语言代码)浏览:1373 |
【数组的距离】 (C语言代码)浏览:787 |
C语言训练-数字母 (C语言代码)浏览:670 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:467 |
DNA (C语言代码)浏览:564 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:727 |
数对 (C语言代码)浏览:762 |
1017题解浏览:663 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:585 |