《数据结构》课程设计题目急急!!!!
为了实现通讯录管理的几种操作功能,首先设计一个含有多个菜单项的主控菜单程序,然后再为这些菜单项配上相应的功能。【设计要求】1.菜单内容程序运行后,给出6个菜单项的内容和输...
为了实现通讯录管理的几种操作功能,首先设计一个含有多个菜单项的主控菜单程
序,然后再为这些菜单项配上相应的功能。
【设计要求】
1.菜单内容
程序运行后,给出6个菜单项的内容和输人提示:
1.通讯录链表的建立
2.通讯者结点的插人
3.通讯者结点的查询
4.通讯者结点的删除
5.通讯录链表的输出
6.通讯录链表的导入
0.退出管理系统
请选择0-6
2.设计要求
(1)使用数字0-6来选择菜单项,其他输入则不起作用。
(2)功能“6.通讯录链表的导入”是指,从硬盘的“通讯录.txt”文件记录中导入通讯录的数据。
问题补充:为实现通讯录管理的
现在提升到30了可以了吧,就那么多了,都给你了.
希望你可以快一点,有急用.谢谢!!
对了是用C语言编的哦. 展开
序,然后再为这些菜单项配上相应的功能。
【设计要求】
1.菜单内容
程序运行后,给出6个菜单项的内容和输人提示:
1.通讯录链表的建立
2.通讯者结点的插人
3.通讯者结点的查询
4.通讯者结点的删除
5.通讯录链表的输出
6.通讯录链表的导入
0.退出管理系统
请选择0-6
2.设计要求
(1)使用数字0-6来选择菜单项,其他输入则不起作用。
(2)功能“6.通讯录链表的导入”是指,从硬盘的“通讯录.txt”文件记录中导入通讯录的数据。
问题补充:为实现通讯录管理的
现在提升到30了可以了吧,就那么多了,都给你了.
希望你可以快一点,有急用.谢谢!!
对了是用C语言编的哦. 展开
1个回答
展开全部
又来了
这个是学生的管理的 改改吧
#include<iostream.h>
#include"string.h"
#include "process.h"
#include <stdio.h>
struct Node
{
int age;
char* name;
Node* next;
};
struct newnode
{
char newname[20];
int newage;
};
void AddTohead(Node* node,char* name,int age)
{
if(!node)
return;
Node* newnode = new Node;
if(name)
{
int cd = strlen(name)+1;
newnode->name = new char [cd];
strcpy(newnode->name,name);
}
else newnode->name = NULL;
newnode->age = age;
newnode->next = node->next;
node->next = newnode;
}
void Show(Node* node)
{
Node* p = NULL;
p = node->next;
while(p!=NULL&&p->name!=NULL)//我的软肋 我没有注意指针的真正的指向 以后要注意 这是我看以前的程序中看出来的问题 while(p)这是我原先写 切记切记
{ //看完程序后我还是没写对 我写对了
cout<<p->name<<" "<<p->age<<endl;
p = p->next;
}
}
void Delete(Node* node)
{
Node* del;
while(node->next)
{
del = node->next;
if(del->next)
delete [] del->name;
node->next = del->next;
delete del;
}
}
void AddToList(Node* node,char* name,int age)
{
if(!node)
return;
Node* newnode = new Node;
while(node->next)
node = node->next;
if(name)
{
int cd = strlen(name)+1;
newnode->name = new char [cd];
strcpy(newnode->name,name);
}
else newnode->name = NULL;
newnode->age = age;
node->next = newnode;
newnode->next = NULL;
}
void FindAndAdd(Node* node,char* findname,char* addname,int addage,int canshu)
{
if(!node)
return;
Node* head = node;
Node* m = NULL;
m = node->next;
do
{
if (!strcmp(m->name,findname))
break;
m = m->next;
} while (m);
if(m==NULL)
{
cout<<"nobody"<<endl;
}
else
{
switch(canshu)
{
case 1:
{
Node* p = head;
while(p->next!= m )
{
p = p->next;
}
Node* newnode = new Node;
if(addname)
{
int cd = strlen(addname)+1;
newnode->name = new char [cd];
strcpy(newnode->name,addname);
}
else
{
newnode->name = new char;
strcpy(newnode->name,"somebody");
}
newnode->age = addage;
newnode->next = p->next;
p->next = newnode;
} break;
case 2:
{
Node* newnode = new Node;
if(addname)
{
int cd = strlen(addname)+1;
newnode->name = new char [cd];
strcpy(newnode->name,addname);
}
else
{
newnode->name = new char;
strcpy(newnode->name,"somebody");
}
newnode->age = addage;
newnode->next = m->next;
m->next = newnode;
} break;
default:break;
}
}
}
void DelSomeBody(Node* node,char* name)
{
if(!node)
return;
Node* head = node;
if(!name)
cout<<"the name please";
else
{
Node* p = node->next;
Node* m = node;
while(m)
{
if(!strcmp(p->name,name))
break;
m = m->next;
p = p->next;
}
if(p==NULL)
{
cout<<"no one";
}
else
{
while(head->next!= p)
head = head->next;
delete [] p->name;
head->next = p->next;
delete p;
}
}
}
void Change(Node* node,char* name,char* newname,int age)
{
if(!node)
return;
Node* head = node;
if(!name)
cout<<"the name please";
else
{
Node* p = node->next;
Node* m = node;
while(m)
{
if(!strcmp(p->name,name))
break;
m = m->next;
p = p->next;
}
if(p==NULL)
{
cout<<"no one";
}
else
{
int cd = strlen(newname)+1;
p->name = new char [cd];
strcpy(p->name,newname);
p->age = age;
}
}
}
void Find(Node* node,char* findname)
{
if(!node)
return;
Node* head = node;
Node* m = NULL;
m = node->next;
if(!m)
cout<<"链表为空的 不存在 请选择操作"<<endl;
return;
do
{
if (!strcmp(m->name,findname))
break;
m = m->next;
} while (m);
if(m==NULL)
{
cout<<"nobody"<<endl;
}
else
{
cout<<m->name<<"的年龄是"<<m->age<<endl;
}
}
void CleanTheWindow()
{
system("cls");
}
void Keep(Node* node,char* fname)
{
Node* p = node->next;
newnode newd;
FILE* ip = fopen(fname,"wb");
if(!ip)
{
cout<<"wrong"<<endl;
return;
}
while(p)
{
strcpy(newd.newname,p->name);
newd.newage = p->age;
fwrite(&newd,sizeof(newnode),1,ip);
p = p->next;
}
fclose(ip);
}
void CreatList(Node* node,char* fname)
{
newnode newd;
FILE* ip =fopen(fname,"rb");
if(!ip)
{
cout<<"wrong"<<endl;
return;
}
Delete(node);
while(!feof(ip))
{
int a =fread(&newd,sizeof(newnode),1,ip);
if(a==1)
AddTohead(node,newd.newname,newd.newage);
}
fclose(ip);
}
void main()
{
Node node;
node.age = NULL;
node.name = NULL;
node.next = NULL;
while(1)
{
cout<<"请选择您的操作1:添加到头部(输入姓名,年龄)"<<endl;
cout<<" 2:添加到尾部(输入姓名,年龄)"<<endl;
cout<<" 3:查找某人的年龄 "<<endl;
cout<<" 4:在某人的前面或后面插入"<<endl;
cout<<" (输入查找的姓名,输入要插入的名字,输入要插入的名字,和年龄)"<<endl;
cout<<" (输入插入类型1:在前插入 2:在后插入)"<<endl;
cout<<" 5:修改某人的信息(输入要修改人的名字 输入要修改的信息姓名,年龄)"<<endl;
cout<<" 6:删除某人的信息(输入你要删除的人的姓名)"<<endl;
cout<<" 7:删除链表"<<endl;
cout<<" 8:显示"<<endl;
cout<<" 9:清屏"<<endl;
cout<<" 10:保存"<<endl;
cout<<" 11:显示保存的内容"<<endl;
cout<<" 0:退出"<<endl;
int a;
cin>>a;//如何对输入的数据进行判断,比如我输入adfd字符型的时候,我想提示用户输入错误
switch(a)
{
case 1:
{
cout<<"请输入要加在头部的姓名和年龄"<<endl;
char* name = new char;
int age;
cin>>name;
cin>>age;
AddTohead(&node,name,age);
cout<<"加入头部完成 请选择下一步操作"<<endl;
} break;
case 2:
{
cout<<"请输入要加在尾部的姓名和年龄"<<endl;
char* name = new char;
int age;
cin>>name;
cin>>age;
AddToList(&node,name,age);
cout<<"加入尾部完成 请选择下一步操作"<<endl;
} break;
case 3:
{
cout<<"请输入要查找人的姓名"<<endl;
char* name = new char;
cin>>name;
Find(&node,name);
} break;
case 4:
{
cout<<"请按上面的输入"<<endl;
char* name = new char;
char* name2 = new char;
int age;
int cs;
cin>>name;
cin>>name2;
cin>>age;
cin>>cs;
FindAndAdd(&node,name,name2,age,cs);
cout<<"4输入完成"<<endl;
} break;
case 5:
{
cout<<"输入要修改的信息和修改的信息"<<endl;
char* name = new char;
char* name2 = new char;
int age;
cin>>name;
cin>>name2;
cin>>age;
Change(&node,name,name2,age);
cout<<"修改完成"<<endl;
} break;
case 6:
{
cout<<"输入要删除的姓名"<<endl;
char* name = new char;
cin>>name;
DelSomeBody(&node,name);
cout<<"删除完成"<<endl;
} break;
case 7:
{
cout<<"确定要删除全部的链表吗?1 是 2否"<<endl;
int npd;
cin>>npd;
if(npd==1)
{
Delete(&node);
}
else break;
} break;
case 8:
{
cout<<"当前的链表是"<<endl;
Show(&node);
} break;
case 9:
{
CleanTheWindow();
} break;
case 10:
{
cout<<"请输入要保存的文件的名称"<<endl;
char a[10];
cin>>a;
Keep(&node,a);
}
break;
case 11:
{
cout<<"请输入保存的文件的名称"<<endl;
char a[10];
cin>>a;
CreatList(&node,a);
Show(&node);
}
break;
case 0:
{
goto stop;
} break;
default :cout<<"输入有误重新输入"<<endl;
}
}
stop: cout<<"exit"<<endl;
}
其实我也很菜的
这个是学生的管理的 改改吧
#include<iostream.h>
#include"string.h"
#include "process.h"
#include <stdio.h>
struct Node
{
int age;
char* name;
Node* next;
};
struct newnode
{
char newname[20];
int newage;
};
void AddTohead(Node* node,char* name,int age)
{
if(!node)
return;
Node* newnode = new Node;
if(name)
{
int cd = strlen(name)+1;
newnode->name = new char [cd];
strcpy(newnode->name,name);
}
else newnode->name = NULL;
newnode->age = age;
newnode->next = node->next;
node->next = newnode;
}
void Show(Node* node)
{
Node* p = NULL;
p = node->next;
while(p!=NULL&&p->name!=NULL)//我的软肋 我没有注意指针的真正的指向 以后要注意 这是我看以前的程序中看出来的问题 while(p)这是我原先写 切记切记
{ //看完程序后我还是没写对 我写对了
cout<<p->name<<" "<<p->age<<endl;
p = p->next;
}
}
void Delete(Node* node)
{
Node* del;
while(node->next)
{
del = node->next;
if(del->next)
delete [] del->name;
node->next = del->next;
delete del;
}
}
void AddToList(Node* node,char* name,int age)
{
if(!node)
return;
Node* newnode = new Node;
while(node->next)
node = node->next;
if(name)
{
int cd = strlen(name)+1;
newnode->name = new char [cd];
strcpy(newnode->name,name);
}
else newnode->name = NULL;
newnode->age = age;
node->next = newnode;
newnode->next = NULL;
}
void FindAndAdd(Node* node,char* findname,char* addname,int addage,int canshu)
{
if(!node)
return;
Node* head = node;
Node* m = NULL;
m = node->next;
do
{
if (!strcmp(m->name,findname))
break;
m = m->next;
} while (m);
if(m==NULL)
{
cout<<"nobody"<<endl;
}
else
{
switch(canshu)
{
case 1:
{
Node* p = head;
while(p->next!= m )
{
p = p->next;
}
Node* newnode = new Node;
if(addname)
{
int cd = strlen(addname)+1;
newnode->name = new char [cd];
strcpy(newnode->name,addname);
}
else
{
newnode->name = new char;
strcpy(newnode->name,"somebody");
}
newnode->age = addage;
newnode->next = p->next;
p->next = newnode;
} break;
case 2:
{
Node* newnode = new Node;
if(addname)
{
int cd = strlen(addname)+1;
newnode->name = new char [cd];
strcpy(newnode->name,addname);
}
else
{
newnode->name = new char;
strcpy(newnode->name,"somebody");
}
newnode->age = addage;
newnode->next = m->next;
m->next = newnode;
} break;
default:break;
}
}
}
void DelSomeBody(Node* node,char* name)
{
if(!node)
return;
Node* head = node;
if(!name)
cout<<"the name please";
else
{
Node* p = node->next;
Node* m = node;
while(m)
{
if(!strcmp(p->name,name))
break;
m = m->next;
p = p->next;
}
if(p==NULL)
{
cout<<"no one";
}
else
{
while(head->next!= p)
head = head->next;
delete [] p->name;
head->next = p->next;
delete p;
}
}
}
void Change(Node* node,char* name,char* newname,int age)
{
if(!node)
return;
Node* head = node;
if(!name)
cout<<"the name please";
else
{
Node* p = node->next;
Node* m = node;
while(m)
{
if(!strcmp(p->name,name))
break;
m = m->next;
p = p->next;
}
if(p==NULL)
{
cout<<"no one";
}
else
{
int cd = strlen(newname)+1;
p->name = new char [cd];
strcpy(p->name,newname);
p->age = age;
}
}
}
void Find(Node* node,char* findname)
{
if(!node)
return;
Node* head = node;
Node* m = NULL;
m = node->next;
if(!m)
cout<<"链表为空的 不存在 请选择操作"<<endl;
return;
do
{
if (!strcmp(m->name,findname))
break;
m = m->next;
} while (m);
if(m==NULL)
{
cout<<"nobody"<<endl;
}
else
{
cout<<m->name<<"的年龄是"<<m->age<<endl;
}
}
void CleanTheWindow()
{
system("cls");
}
void Keep(Node* node,char* fname)
{
Node* p = node->next;
newnode newd;
FILE* ip = fopen(fname,"wb");
if(!ip)
{
cout<<"wrong"<<endl;
return;
}
while(p)
{
strcpy(newd.newname,p->name);
newd.newage = p->age;
fwrite(&newd,sizeof(newnode),1,ip);
p = p->next;
}
fclose(ip);
}
void CreatList(Node* node,char* fname)
{
newnode newd;
FILE* ip =fopen(fname,"rb");
if(!ip)
{
cout<<"wrong"<<endl;
return;
}
Delete(node);
while(!feof(ip))
{
int a =fread(&newd,sizeof(newnode),1,ip);
if(a==1)
AddTohead(node,newd.newname,newd.newage);
}
fclose(ip);
}
void main()
{
Node node;
node.age = NULL;
node.name = NULL;
node.next = NULL;
while(1)
{
cout<<"请选择您的操作1:添加到头部(输入姓名,年龄)"<<endl;
cout<<" 2:添加到尾部(输入姓名,年龄)"<<endl;
cout<<" 3:查找某人的年龄 "<<endl;
cout<<" 4:在某人的前面或后面插入"<<endl;
cout<<" (输入查找的姓名,输入要插入的名字,输入要插入的名字,和年龄)"<<endl;
cout<<" (输入插入类型1:在前插入 2:在后插入)"<<endl;
cout<<" 5:修改某人的信息(输入要修改人的名字 输入要修改的信息姓名,年龄)"<<endl;
cout<<" 6:删除某人的信息(输入你要删除的人的姓名)"<<endl;
cout<<" 7:删除链表"<<endl;
cout<<" 8:显示"<<endl;
cout<<" 9:清屏"<<endl;
cout<<" 10:保存"<<endl;
cout<<" 11:显示保存的内容"<<endl;
cout<<" 0:退出"<<endl;
int a;
cin>>a;//如何对输入的数据进行判断,比如我输入adfd字符型的时候,我想提示用户输入错误
switch(a)
{
case 1:
{
cout<<"请输入要加在头部的姓名和年龄"<<endl;
char* name = new char;
int age;
cin>>name;
cin>>age;
AddTohead(&node,name,age);
cout<<"加入头部完成 请选择下一步操作"<<endl;
} break;
case 2:
{
cout<<"请输入要加在尾部的姓名和年龄"<<endl;
char* name = new char;
int age;
cin>>name;
cin>>age;
AddToList(&node,name,age);
cout<<"加入尾部完成 请选择下一步操作"<<endl;
} break;
case 3:
{
cout<<"请输入要查找人的姓名"<<endl;
char* name = new char;
cin>>name;
Find(&node,name);
} break;
case 4:
{
cout<<"请按上面的输入"<<endl;
char* name = new char;
char* name2 = new char;
int age;
int cs;
cin>>name;
cin>>name2;
cin>>age;
cin>>cs;
FindAndAdd(&node,name,name2,age,cs);
cout<<"4输入完成"<<endl;
} break;
case 5:
{
cout<<"输入要修改的信息和修改的信息"<<endl;
char* name = new char;
char* name2 = new char;
int age;
cin>>name;
cin>>name2;
cin>>age;
Change(&node,name,name2,age);
cout<<"修改完成"<<endl;
} break;
case 6:
{
cout<<"输入要删除的姓名"<<endl;
char* name = new char;
cin>>name;
DelSomeBody(&node,name);
cout<<"删除完成"<<endl;
} break;
case 7:
{
cout<<"确定要删除全部的链表吗?1 是 2否"<<endl;
int npd;
cin>>npd;
if(npd==1)
{
Delete(&node);
}
else break;
} break;
case 8:
{
cout<<"当前的链表是"<<endl;
Show(&node);
} break;
case 9:
{
CleanTheWindow();
} break;
case 10:
{
cout<<"请输入要保存的文件的名称"<<endl;
char a[10];
cin>>a;
Keep(&node,a);
}
break;
case 11:
{
cout<<"请输入保存的文件的名称"<<endl;
char a[10];
cin>>a;
CreatList(&node,a);
Show(&node);
}
break;
case 0:
{
goto stop;
} break;
default :cout<<"输入有误重新输入"<<endl;
}
}
stop: cout<<"exit"<<endl;
}
其实我也很菜的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询