急求C++课程设计答案!重金悬赏!!....

2024-12-17 10:28:55
推荐回答(2个)
回答1:

#include
using namespace std;
#define null 0
struct notelist
{
char num[5]; // 编号
char name[9]; // 姓名
char sex[3]; // 性别
char phone[13]; // 电话
char addr[31]; // 地址
notelist *next;
};
int n;
bool find1(notelist *head,char num[]);
notelist *creat()//通讯录的建立
{char i;
notelist *head;
notelist*p1,*p2;

n=0;

p1=p2=new notelist;
p1->next=null;
head=null;
/*cout<<"请输入通讯录信息的条数:";
cin>>i;*/
/*cin.clear(); //清空状态和缓冲区 ,判断输入正确与否
cin.sync();
for(int j=1;j<100000;j++)
k=i-j;
if(k==0)
cout<else
{cout<<"输入错误"<cin>>i;}*/
do
{
cout<<"请输入第"<cout<<"请输入编号:";
cin>>p1->num;
while(find1(head,p1->num))
{
cout<<"-----此编号已存在!请重新输入!-----"<
cout<<"请输入编号:";
cin>>p1->num;
}
cout<<"请输入姓名:";
cin>>p1->name;
cout<<"请输入性别:";
cin>>p1->sex;
cout<<"请输入电话号码:";
cin>>p1->phone;
cout<<"请输入地址:";
cin>>p1->addr;
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=new notelist;
p1->next=null;
cout<<"是否继续输入通讯录讯息:(是请按y---否请按其它任意键)";
cin>>i;
}
while(i=='y'||i=='Y');
p2->next=null;

return(head);

}

bool find1(notelist *head,char num[])//查询相同编号
{notelist *p1,*p2;

if(head==null)
{return 0;}
p1=head;
while((strcmp(num,p1->num)!=0)&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{
return 1;
}
else return 0;

}

void print(notelist*head)//通讯录信息的输出
{
notelist *p;
cout<cout<<"编号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"电话"<<" "<<"地址"< p=head;
if(head!=null)
do
{
cout<num<<" "<name<<" "<sex<<" "<phone<<" "<addr<p=p->next;
}
while(p!=null);
}

void find(notelist *head,char num[])//查询
{notelist *p1,*p2;
if(head==null)
{cout<<"没记录"<p1=head;
while((strcmp(num,p1->num)!=0)&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{
cout<<"编号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"电话"<<" "<<"地址"<cout<num<<" "<name<<" "<sex<<" "<phone<<" "<addr<}
else cout<<"找不到该编号:";
}

notelist *del(notelist *head,char num[])//通讯录信息的删除
{notelist *p1,*p2;
if(head==null)
{cout<<"没记录"<p1=head;
while(strcmp(num,p1->num)!=0&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
cout<<"编号为"<n=n-1;
}
else cout<<"找不到该编号:";
return(head);
}

notelist *insert(notelist *head,notelist *stud)//通讯录信息的添加
{
notelist *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==null)
{head=p0;p0->next=null;}
else
{
while(strcmp(p0->num,p1->num)>0&&(p1->next!=null))
{
p2=p1;
p1=p1->next;}
if(strcmp(p0->num,p1->num)<0)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=null;}
}
n=n+1;
return(head);
}

int main()
{
int s,d, a,j=0;
notelist *head,*stu;
char c, i,k[5],del_num[5];

char y;

do
{
cout<<"*****************请选择:******************"<cout<<"建立通讯录请按1--------查询通讯录请按2"<cout<<"删除通讯录请按3--------插入通讯录请按4"<cout<<"退出菜单请按5"<cout<<"******************************************"<cin>>c;

switch(c)
{case '1':
head=creat();
print(head);
break;

case '2':
cout<cin>>k;
do
{
find(head,k);
cout<cin>>k;
}
while(strcmp(k,"exit")!=0);
break;

case '3':
cout<cin>>del_num;
while(strcmp(del_num,"exit")!=0)
{head=del(head,del_num);
print(head);
cout<<"请输入要删除的编号:(结束请输入exit)";
cin>>del_num;
}
break;

case '4':
/*cout<cin>>i;*/
do
{
cout<stu=new notelist;
cout<<"请输入编号:";
cin>>stu->num;

while(find1(head,stu->num))//判断编号是否存在
{
cout<<"-----此编号已存在!请重新输入!-----"<
cout<<"请输入编号:";
cin>>stu->num;
}

cout<<"请输入姓名:";
cin>>stu->name;
cout<<"请输入性别:";
cin>>stu->sex;
cout<<"请输入电话号码:";
cin>>stu->phone;
cout<<"请输入地址:";
cin>>stu->addr;
head=insert(head,stu);
print(head);
j=j+1;
cout<<"是否继续输入通讯录讯息:(是请按y---否请按其它任意键)";
cin>>i;
}
while(i=='y'||i=='Y');

break;

case '5':break;
default: cout<<"输入错误!"<}
cout<<"是否继续操作:(是请按y---退出请按其它任意键)"<cin>>y;
}
while(y=='y'||y=='Y');

return 0;
}

回答2:

30分,也叫重金.

这点程序写个雏形也得写几个小时.
现在程序员同志们越来越便宜了.