课程设计啊~~写的都快哭了~~
写了一个电话本~~能实现下列功能~~
1.添加联系人
2.删除联系人
3.显示全部联系人
4.查找联系人
5.修改密码
6.退出
post code
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
using namespace std;
int k=0;
struct element{
char name[31],num[31];
}people[20];
void show();
void add();
void delete_name();
void display();
bool cmp(struct element,struct element);
void search();
int main()
{
char a[7]="123456",b[7];
int flag=0,n=2,choice;
begin:
cout<<"please input passwords"<<endl;
while(n--)
{
gets(b);
while(strcmp(a,b)==0)
{
flag=1;
show();
cin>>choice;
switch(choice)
{
case 1: add();continue;
case 2: delete_name();continue;
case 3: display();continue;
case 4: search();continue;
case 5:getchar();gets(a);goto begin; continue;
case 6:;
}
if(choice==6)break;
}
if(flag==0)cout<<"please input passwords"<<endl;
if(flag==1)break;
}
system("pause");
}
void search()
{
getchar();
char name1[31];
gets(name1);
int flag=0,i;
for(i=0;i<k;i++)
if(strcmp(people[i].name,name1)==0){flag=1;cout<<name1<<" "<<people[i].num<<endl;}
if(flag==0)cout<<"This person don't exist in the contract!"<<endl;
}
void delete_name()
{
char name1[31];
getchar();
gets(name1);
int flag=0,i,j;
for(i=0;i<=k-1;i++)
{
if(strcmp(people[i].name,name1)==0){flag=1;break;}
}
if(flag==0)cout<<"Didn't find this person!"<<endl;
if(flag==1){for(j=i;j<=k-1;j++)
{
strcpy(people[j].name,people[j+1].name);
strcpy(people[j].num,people[j+1].num);
}
k--;
}
}
void display()
{
int i;
cout<<endl;
for(i=0;i<=k;i++)
cout<<people[i].name<<" "<<people[i].num<<endl;
cout<<endl<<endl;
}
void add()
{
cout<<"please add the contract with name and phone number and it is terminaled by # !"<<endl;
char name1[31],num1[21];
while(scanf("%s %s",name1,num1)&&name1[0]!='#')
{
if(k==20){cout<<"The contract is full"<<endl;break;}
strcpy(people[k].name,name1);
strcpy(people[k].num,num1);
k++;
}
sort (people,people+k,cmp);
}
void show()
{
int i;
for(i=1;i<=52;i++)
cout<<'*';
cout<<endl;
cout<<"* *"<<endl;
cout<<"* CONTRACT *"<<endl;
cout<<"* 1.add contract *"<<endl;
cout<<"* 2.delete contract *"<<endl;
cout<<"* 3.display all of the contract *"<<endl;
cout<<"* 4.search people's contract *"<<endl;
cout<<"* 5.modify passwords *"<<endl;
cout<<"* 6.exit *"<<endl;
for(i=1;i<=52;i++)
cout<<'*';
cout<<endl;
cout<<"Please select number to realize corresponding function!"<<endl<<endl;
}
bool cmp(struct element x,struct element y)
{
if(strcmp(x.name,y.name)<0)return 1;
if(strcmp(x.name,y.name)>0)return 0;
}