实现科研项目基础属性的增加、删除、修改、查找、统计等功能
感激不尽!
5条回答 默认 最新
- 唐之风采 2016-07-05 02:57关注
这是一个用链表保存的通讯录,具备信息的增加、删除、修改、查询功能,不知是否符合你的要求。
//2015/3/12 by LDSD
#include
#include
using namespace std;
struct node
{
char num[15];
char name[7];
char phone[12];
node *next;
};
void serch(node *head)
{
head=head->next;
char con;
char data[15];
while(1)
{
cout<<"1:按学号查询 2:按姓名查询,请选择指令执行操作。\n";
cin>>con;
if(con=='1')
{
cout<<"请输入学号。"< cin>>data;
while(head!=NULL)
{
if(strcmp(head->num,data)==0)
{
cout<num<<'\t'<name<<'\t'<phone<<'\n';break;
}
else
head=head->next;
}
if(head==NULL)
cout<<"未查询到匹配的记录!"< break;
}
else if(con=='2')
{
cout cin>>data;
while(head!=NULL)
{
if(strcmp(head->name,data)==0)
{
cout<num<<'\t'<name<<'\t'<phone<<'\n';break;
}
else
head=head->next;
}
if(head==NULL)
cout<<"未查询到匹配的记录!"< break;
}
else
cout }
}
void add(node *head)
{
node *new_stu=new node;
cout cin>>new_stu->num>>new_stu->name>>new_stu->phone;
new_stu->next=head->next;
head->next=new_stu;
}
void modify(node *head)
{
char num[15];
char name[7];
char phone[12];
node *head1=head->next;
int i=1;
node *new_stu=new node;
cout<<"通讯录内容如下,其依次输入编号,学号,姓名,电话号码,以便对信息更新。\n";
while(head1!=NULL)
{
cout<num<<'\t'<name<<'\t'<phone<<'\n';
head1=head1->next;
}
cin>>i>>num>>name>>phone;
while(i--&&head!=NULL)
head=head->next;
if(head==NULL)
cout<<"你的编号不正确!"< else
{
strcpy(head->num,num);
strcpy(head->name,name);
strcpy(head->phone,phone);
}}
void del(node *head)
{
node *head1=head->next;
int i=1;
cout<<"通讯录内容如下,请输入要删除的编号。\n";
while(head1!=NULL)
{
cout<num<<'\t'<name<<'\t'<phone<<'\n';
head1=head1->next;
}
cin>>i;
i--;
while(i--&&head->next!=NULL)
head=head->next;
if(head->next==NULL)
cout<<"你的编号不正确!"< else
{
head->next=head->next->next;
}
}void main()
{
char con;
node *head=new node;
head->next=NULL;
while(1)
{
cout<<"1:查询 2:添加 3:修改 4:删除,请选择指令执行操作。\n";
cin>>con;
if(con=='1')
serch(head);
else if(con=='2')
add(head);
else if(con=='3')
modify(head);
else if(con=='4')
del(head);
else
cout<<"你输入的指令不正确!"<<endl;
}}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度