数据结构 通讯录的制作
#include
#include
#include
struct Telephone
{
char name[20];
char addrass[20];
char zip[20];
char telephone[20];
struct Telephone *next;
};
typedef struct Telephone TEL;
TEL *head=NULL;
void showmenu(); //菜单
void Appenditem(); //添加条目
void print(); //输出条目
void Finditem1(); //查找条目( 按姓名 )
void Removeitem(); //删除信息
void Saveandfree(); //保存到文件
void Open(); //打开文件
void main()
{
char ch;
Open(); //打开文件
while(1)
{
showmenu(); //显示菜单
scanf(" %c",&ch);
switch(ch)
{
case '1':Appenditem(); //添加条目
break;
case '2':print(); //输出条目
break;
case '3':Finditem1(); //查找条目1.按姓名
break;
case '4': Removeitem(); //删除信息
print(); //输出删除后的结果
break;
case '0':Saveandfree(); //保存并释放内存
exit(0); //退出
break;
default:
printf("选择错误!");
break;
}
}
}
//菜单
void showmenu()
{
printf("
*****************通讯录系统*****************
");
printf("1.添加条目。
");
printf("2.输出输出
");
printf("3.按姓名查询
");
printf("4.删除条目
");
printf("0.保存并退出!
");
printf("*************************************************
");
printf("请选择:
");
}
//添加条目
void Appenditem()
{
TEL *p1=NULL,*p2=NULL;
p1=(TEL *)malloc(sizeof(TEL)); //申请结点
printf("输入姓名:
"); //添加信息
scanf("%s",p1->name);
printf("输入地址:
");
scanf("%s",p1->addrass);
printf("输入邮编:
");
scanf("%s",p1->zip);
printf("输入电话:
");
scanf("%s",p1->telephone);
p1->next=NULL; //保存到链表
if(head==NULL)
{
head=(TEL *)malloc(sizeof(TEL)); //申请空间
head->next=p1;
}
else
{
for(p2=head;p2->next!=NULL;p2=p2->next); //找到结点尾
p2->next=p1;
}
printf("此信息已添加!");
}
//输出学生信息
void print()
{
TEL *p=NULL;
if(head==NULL)
{
printf("此通讯录中无记录,请输入记录后在使用本功能!
");
return;
}
printf("**************通讯录系统*********************
"); //输出信息
printf("姓名地址邮编电话
");
for(p=head->next;p!=NULL;p=p->next)
printf("%s%s%s%s
",p->name,p->addrass,p->zip,p->telephone);
}
//查找信息1.按姓名
void Finditem1()
{
TEL *p;
char findname[20];
printf("请输入要查找的姓名:
");
scanf("%s",findname);
printf("**************通讯录系统*********************
");
printf("姓名地址邮编电话
");
for(p=head->next;p!=NULL;p=p->next)
{
if(strcmp(p->name,findname)==0)
printf("%s%s%s%s
",p->name,p->addrass,p->zip,p->telephone);
}
}
//删除信息
void Removeitem()
{
char findname[20]; //先查找 后删除
TEL *p = head->next, *pr = head->next;
printf("请输入要删除的姓名:
");
scanf(" %s",&findname);
if (head->next == NULL)
{
printf("无此节点!
");
return;
}
while ((strcmp(p->name,findname)!=0 )&& p->next != NULL)
{
pr =p;
p =p->next;
}
if (strcmp(findname, p->name)==0) //输出删除信息
{
printf("%s%s%s%s
",p->next->name,p->next->addrass,\
p->next->zip,p->next->telephone);
if (p == head->next)
head->next = p->next;
else
pr->next = p->next;
free(p);
}
printf("此信息已删除!");
}
//保存链表信息到文件并释放内存空间
void Saveandfree()
{
TEL *p=NULL;
FILE *fp;
char *Book="books.txt";
if(head==NULL)
{
printf("
记录为空!
");
return;
}
else
p=head->next;
if((fp=fopen(Book,"wb+"))==NULL)
{
printf("
打不开文件!
");
return;
}
while(p!=NULL) //保存信息
{
fwrite(p,sizeof(TEL),1,fp);
p=p->next;
}
printf("保存完毕!");
fclose(fp);
//*****释放链表空间*****
for(;head->next!=NULL;)
{
p=head->next;
head->next=head->next->next;
free(p);
}
free(head);
}
//文件信息输出到链表
void Open()
{
FILE *fp;
TEL *p1=NULL,*p2=NULL,*temp=NULL;
if((fp=fopen("books.txt","rb+"))==NULL)
{
printf("
****************这是一个新的通讯录管理系统******************
");
return;
}
head=(TEL *)malloc(sizeof(TEL));
head->next=NULL;
temp=p2=head;
while(! feof(fp)) //循环读取
{
p1=(TEL *)malloc(sizeof(TEL));
temp=p2;
p2->next=p1;
p2=p1;
fread(p1,sizeof(TEL),1,fp);
}
temp->next=NULL;
fclose(fp); //关闭文件
}
#include
#include
#include
using namespace std;
#define SIZE 10
struct AddrList
{
string name;
string sex;
int age;
string QQ;
}addrlist[SIZE];
int main()
{
int i;
int j;
cout<<"输入要输入的记录数量:";
cin>>i;
if (i>SIZE)
{
cout<<"输入的记录数量大于顺序表的最大长度!"<<endl;
return 0;
}
cout<<"输入格式:
姓名 性别 年龄 QQ
"<<endl;
for (j=0;j<i;++j)
{
cout<<"输入第"<<j+1<<"条记录"<<endl;
cin>>addrlist[j].name>>addrlist[j].sex>>addrlist[j].age>>addrlist[j].QQ;
}
cout<<"
姓名性别年龄QQ"<<endl;
for (j=0;j<i;++j)
{
cout<<addrlist[j].name<<""<<addrlist[j].sex<<""<<addrlist[j].age<<""<<addrlist[j].QQ<<endl;
}
return 0;
}
输入:2
张三 男 23 123456
李四 女 24 66666
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct contacks
{ char name[10];
char street[20];
char city[10];
int eip;
char state[10];
}con[50];
int k=0;
void enter();
void display();
void lookandchange();
void del();
void save();
void main()
{
int a;
do
{
printf("\n\n ******************************************************************\n");
printf(" *"); printf("\t\twelcome enter the contacks system"); printf("\t*");
printf("\n ******************************************************************\n");
printf(" *"); printf("\t 1.Access information"); printf("\t\t\t\t\t*\n");
printf(" *"); printf("\t 2.display information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 3.lookandchange information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 4.Delete information"); printf("\t\t\t\t\t*\n");
printf(" *"); printf("\t 5.Save the information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 6. exit "); printf("\t\t\t\t\t*\n");
printf(" ******************************************************************\n");
printf(" Enter you choice : ");
scanf("%d",&a);
switch(a)
{
case 1:printf("\n");enter();break;
case 2:printf("\n");display();break;
case 3:printf("\n");lookandchange();break;
case 4:printf("\n");del();break;
case 5:printf("\n");save();break;
case 6:printf("\n");exit(0);break;
default:printf("\nThe choice is between 1 to 6.\n");
}
}while(a!=0);
}
void enter()
{
char ch[20];
printf("\nenter student information:\n");
do
{ printf("\nname: ");
scanf("%s",con[k].name);
printf("street: ");
scanf("%s",con[k].street);
printf("\ncity: ");
scanf("%s",con[k].city);
printf("\neip: ");
scanf("%d",&con[k].eip);
printf("\nstate: ");
scanf("%s",con[k].state);
k++;
printf("\nif want continue input student information(y/n): ");
scanf("%s",ch);
}while(strcmp(ch,"y")==0||strcmp(ch,"Y")==0);
display();
}
void display()
{ int i;
printf(" the information is:\n");
for(i=0;i<k;i++)
{ printf("%10s %20s %10s %6d %10s ",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
printf("\n"); }
}
void lookandchange()
{
int i;
char a[20],ch[10];
printf("\nenter you want look name:");
scanf("%s",a);
for(i=0;i<k;i++)
if(strcmp(con[i].name,a)==0) printf("%10s %20s %10s %6d %10s ",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
printf("\nenter you want change name:");
scanf("%s",a);
for(i=0;i<k;i++)
{
if(strcmp(con[i].name,a)==0)
{ printf("\nyou sure want change student name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nname:"); scanf("%s",con[i].name);}
printf("\nyou sure want change street(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nstreet"); scanf("%s",con[i].street);}
printf("\nyou sure want change city(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\ncity"); scanf("%s",con[i].city);}
printf("\nyou sure want change eip(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\neip"); scanf("%d",&con[i].eip);}
printf("\nyou sure want change state(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nstate"); scanf("%s",con[i].state);}
}
}
display();
}
void del()
{
int i,j;
char c[20];
printf("\nenter you want delete name :\n");
printf("name:");
scanf("%s",&c);
for(i=0;i<k;i++)
if(strcmp(c,con[i].name)==0) break;
for(j=i;j<=2;j++)
con[j]=con[j+1];
printf("\t\t\tyou had delete %s\n",c);
k--;
display();
}
void save()
{ FILE *fp; int i;
if((fp=fopen("xinxi.txt","w"))==NULL)
{ printf("cannot write the file.\n");
exit(0);}
for(i=0;strlen(con[i].name)!=0;i++)
fprintf(fp,"%s %s %s %d %s\n",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
fclose(fp);
}
在vc++中调试通过 有问题可以hi我
你的第六个load功能 既然有第一个enter了 第六个就没必要了
在第三个中你还可以修改信息
虽然没用到链表 但功能均可实现
表名:UserInfo
字段列表:
ID:自动编号字段(主键)
UserName;文本(10):用户姓名
UserSex:是/否:用户性别
UserBirth:日期:用户生日
UserJobAddress:文本(100):工作地址
UserHomeAddress:文本(100):家庭地址
UserTelMobil:文本(12):手机号
UserTelOffice:文本(12):办公室电话
UserTelHome:文本(12):家庭电话
UserGroup:文本(10):所在用户组(进行分类,便于管理)
UserEmail:文本(100):电子邮件地址
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct contacks
{ char name[10];
char street[20];
char city[10];
int eip;
char state[10];
}con[50];
int k=0;
void enter();
void display();
void lookandchange();
void del();
void save();
void main()
{
int a;
do
{
printf("\n\n ******************************************************************\n");
printf(" *"); printf("\t\twelcome enter the contacks system"); printf("\t*");
printf("\n ******************************************************************\n");
printf(" *"); printf("\t 1.Access information"); printf("\t\t\t\t\t*\n");
printf(" *"); printf("\t 2.display information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 3.lookandchange information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 4.Delete information"); printf("\t\t\t\t\t*\n");
printf(" *"); printf("\t 5.Save the information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 6. exit "); printf("\t\t\t\t\t*\n");
printf(" ******************************************************************\n");
printf(" Enter you choice : ");
scanf("%d",&a);
switch(a)
{
case 1:printf("\n");enter();break;
case 2:printf("\n");display();break;
case 3:printf("\n");lookandchange();break;
case 4:printf("\n");del();break;
case 5:printf("\n");save();break;
case 6:printf("\n");exit(0);break;
default:printf("\nThe choice is between 1 to 6.\n");
}
}while(a!=0);
}
void enter()
{
char ch[20];
printf("\nenter student information:\n");
do
{ printf("\nname: ");
scanf("%s",con[k].name);
printf("street: ");
scanf("%s",con[k].street);
printf("\ncity: ");
scanf("%s",con[k].city);
printf("\neip: ");
scanf("%d",&con[k].eip);
printf("\nstate: ");
scanf("%s",con[k].state);
k++;
printf("\nif want continue input student information(y/n): ");
scanf("%s",ch);
}while(strcmp(ch,"y")==0||strcmp(ch,"Y")==0);
display();
}
void display()
{ int i;
printf(" the information is:\n");
for(i=0;i<k;i++)
{ printf("%10s %20s %10s %6d %10s ",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
printf("\n"); }
}
void lookandchange()
{
int i;
char a[20],ch[10];
printf("\nenter you want look name:");
scanf("%s",a);
for(i=0;i<k;i++)
if(strcmp(con[i].name,a)==0) printf("%10s %20s %10s %6d %10s ",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
printf("\nenter you want change name:");
scanf("%s",a);
for(i=0;i<k;i++)
{
if(strcmp(con[i].name,a)==0)
{ printf("\nyou sure want change student name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nname:"); scanf("%s",con[i].name);}
printf("\nyou sure want change street(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nstreet"); scanf("%s",con[i].street);}
printf("\nyou sure want change city(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\ncity"); scanf("%s",con[i].city);}
printf("\nyou sure want change eip(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\neip"); scanf("%d",&con[i].eip);}
printf("\nyou sure want change state(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nstate"); scanf("%s",con[i].state);}
}
}
display();
}
void del()
{
int i,j;
char c[20];
printf("\nenter you want delete name :\n");
printf("name:");
scanf("%s",&c);
for(i=0;i<k;i++)
if(strcmp(c,con[i].name)==0) break;
for(j=i;j<=2;j++)
con[j]=con[j+1];
printf("\t\t\tyou had delete %s\n",c);
k--;
display();
}
void save()
{ FILE *fp; int i;
if((fp=fopen("xinxi.txt","w"))==NULL)
{ printf("cannot write the file.\n");
exit(0);}
for(i=0;strlen(con[i].name)!=0;i++)
fprintf(fp,"%s %s %s %d %s\n",con[i].name,con[i].street,con[i].city,con[i].eip,con[i].state);
fclose(fp);
}
在vc++中调试通过 有问题可以hi我
你的第六个load功能 既然有第一个enter了 第六个就没必要了
在第三个中你还可以修改信息
虽然没用到链表 但功能均可实现
应该是数据库结构吧?如果是,给你个示例
表名:UserInfo
字段列表:
ID:自动编号字段(主键)
UserName;文本(10):用户姓名
UserSex:是/否:用户性别
UserBirth:日期:用户生日
UserJobAddress:文本(100):工作地址
UserHomeAddress:文本(100):家庭地址
UserTelMobil:文本(12):手机号
UserTelOffice:文本(12):办公室电话
UserTelHome:文本(12):家庭电话
UserGroup:文本(10):所在用户组(进行分类,便于管理)
UserEmail:文本(100):电子邮件地址
.....
想更详细就自己根据需要增加吧
LS没用到链表,LZ发消息给你了
弓霞清胃: #include "stdio.h" #include "string.h" #include "stdlib.h" typedef struct { char num[5]; char name[10]; char sex[5]; char phone[15]; char addr[30]; }datatype; typedef struct node { datatype data; struct node * next; }listnode; typedef listnode * ...
谷城县18716401864: 用C语言编写一个通讯录系统,集合数据结构双向链表知识 - ?
弓霞清胃: //类似//#include "stdafx.h"#include<iostream.h> #include<string.h> #include<iomanip.h> class stu { char name[20]; double age,homephone,telphone; char sex; public: stu(){} stu(char n[20],char se,double ag,double ho,double te) { strcpy(name, n); ...
谷城县18716401864: 我想写一个通讯录程序,应该用什么数据结构?
弓霞清胃: 通讯录,就是一个简单的写入数据库,再从数据库读出的过程. 你就是简单的顺序结构即可.
谷城县18716401864: 求数据结构学生通讯录,要求原创,最好简单点,网上的看不明白 - ?
弓霞清胃: 数字、汉字直接保存到文件,看到的就都是乱码.英文字符保存如果可见(不是乱码)就是正确的,如果这个是乱码..那就是出了问题.如果希望都保存成可见,必须是作为纯文本,几个选择:1·数字保存要先转换为字符串,所以写入文件的,必须以全以字符串方式写入.2·使用INI保存函数GetPrivateProfileInt等(自己搜索查看用法和例程)3·使用其它格式和控件保存到数据库、XML等格式化文件中.
谷城县18716401864: 数据结构课程设计:建通讯录.请高人帮忙. - ?
弓霞清胃: 建立一个结构体,在里面定义各种姓名,号码,性别 ,住址等一系列你想要的属性就可以了.
谷城县18716401864: C++数据结构 用顺序表编出通讯录的程序 要求有姓名 性别 年龄 QQ 地址 - ?
弓霞清胃: #include <iostream>#include <fstream>#include <string> using namespace std;#define SIZE 10 struct AddrList { string name; string sex; int age; string QQ; }addrlist[SIZE]; int main() { int i; int j; cout<<"输入要输入的记录数量:"; cin>>i; if (i>...
谷城县18716401864: (java编程)采用双向链表作数据结构,编写一个通讯录管理系统. - ?
弓霞清胃: #include #include using namespace std;#define SIZE 10 struct AddrList { string name; string sex; int age; string QQ; }addrlist[SIZE]; int main() { int i; int j; cout<<"输入要输入的记录数量:"; cin>>i; if (i>SIZE) { cout<<"输入的记录数量大于顺序...
谷城县18716401864: 设计一个通讯录由以下几项数据信息构成:数据项(姓名、地址、邮编、电话号码)类型:都为字符串. - ?
弓霞清胃: 笔墨伺候
谷城县18716401864: 数据结构用C语言编写通讯录管理系统③任务:通过此系统可以实现如下功能..录入:录入新的通讯信息(包括姓名、通讯地址、邮编、联系电话)查询:可按照姓名进行查询相关信息修改:可修改相关信息?
弓霞清胃: #include <stdio.h> struct address_book {char name[100],char address[100],char zip[100],char phone[100] }; int search(char* search_name, char* address_book_list) {int search_index = -1;for(count=0;count<100;count++){if(strcmp(address...
谷城县18716401864: C++数据结构双向链表通讯录?
弓霞清胃: 可以使用C++提供的链表完成.把链表变量换成结构体就OK了.