用C++来编写通讯录数据结构

本文介绍了如何使用C++来构建通讯录数据结构,涉及iostream、cstdlib、string.h等头文件的使用,以及类的定义和面向对象编程的基础概念。通过示例展示了如何创建并操作一个点的坐标类。
摘要由CSDN通过智能技术生成

1.#包括<的iostream>里的定义

iostream =输入输出流标准的输入输出流头文件,包含两个基本操作:

(1)CIN >> “要输入的内容”

(2)>> COUT “要输出的内容”

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据结构课程设计 include "stdio.h" #include "ctype.h" #include "string.h" #include"stdlib.h" #include "malloc.h" struct list { char name[10]; char street[10]; char city[10]; char state[10]; char eip[10]; struct list *prior; struct list *next; }; void mainmenu(struct list * head); void read_file(struct list * head); void read_file(); void px_menu(struct list * head); void px_name(struct list * head); void px_street(struct list * head); void px_city(struct list * head); void px_state(struct list * head); void px_eip(struct list * head); void delete_menu(struct list * head); void delete_name(struct list * head); void search_menu(struct list * head); void search_name(struct list * head); void search_street(struct list * head); void search_city(struct list * head); void search_state(struct list * head); void search_eip(struct list * head); void add_new(struct list * head); void prin_list(struct list * head); void write_file(struct list * head); int flag=0; int flag1=0;//删除为空标志位 void main() { struct list *head; read_file(); mainmenu(head); return; } /**************************************************** 主菜单 ****************************************************/ void mainmenu(struct list * head) { char tmp; system("cls"); printf("输入要进行的操作:\n"); printf("\t '1'-----------------------添加记录\n"); printf("\t '2'-----------------------排序记录\n"); printf("\t '3'-----------------------显示记录\n"); printf("\t '4'-----------------------查找记录\n"); printf("\t '5'-----------------------删除记录\n"); printf("\t '6'---------------------------退出\n"); printf("\t '0'---------------------保存并退出\n"); printf("\n\t请选择:"); tmp=getchar(); switch(tmp) { case '1':add_new(head);break; case '2':px_menu(head);break; case '3':prin_list(head);break; case '4':search_menu(head);break; case '5':delete_menu(head);break; case '6':exit(0);break; case '0':write_file(head);break; default :{printf("错误操作返回主菜单");mainmenu(head);} } } /**************************************** 双链表建立以及文件读取 ****************************************/ //void read_file(struct list * head) void read_file() { int i; struct list *p1,*p2; struct list *head; FILE *fp; fp=fopen("list.txt","a"); fclose(fp); if ((fp = fopen ( "list.txt" , "rt" ) ) == NULL ) { printf("打开文件失败\n"); exit(0) ; } rewind(fp);//将文件指针重新指向流的开头 fseek(fp,0,2);//重定位流上的文件指针 if ((ftell(fp)==0))//返回当前文件指针 { printf("没有记录:\n"); head=p1=p2=(struct list *)malloc(sizeof(struct list)); head->name[10]='\0'; head->street[10]='\0'; head->city[10]='\0'; head->state[10]='\0'; head->eip[10]='\0'; head->next=head; head->prior=head; flag=1; } else { rewind(fp); head=p1=p2=(struct list *)malloc(sizeof(struct list)); head->next=head; head->prior=head; if(fread(p1,sizeof(struct list),1,fp)!=1)//从流中读数据 { p2->next=p1; p1->next=head; head->prior=p1; p1->prior=p2; p2=p1; } else { for (i=0;;i++) { p2->next=p1; p1->next=head; head->prior=p1; p1->prior=p2; p2=p1; if (feof ( fp ))//检测流上的文件结束符用 { p1->next=head; head->prior=p1; printf("记录读入完成\n"); break; } else { p1=(struct list *)malloc(sizeof(struct list)); p1->name[10]='\0'; p1->street[10]='\0'; p1->city[10]='\0'; p1->state[10]='\0'; p1->eip[10]='\0'; if(fread(p1,sizeof(struct list),1,fp)!=1) { break; } } } } } printf("记录读入完成\n"); fclose ( fp ) ; printf("按任意键进入主菜单\n"); getchar(); mainmenu(head); return; } /**************************************** 增添 ****************************************/ void add_new(struct list * head) { int k=0; int n; char tmp1,tmp2; struct list *p; struct list *p1,*p2; p1=(struct list *)malloc(sizeof(struct list)); p1->name[10]='\0'; p1->street[10]='\0'; p1->city[10]='\0'; p1->state[10]='\0'; p1->eip[10]='\0'; printf("请输入所要添加的名字:\n"); scanf("%s",p1->name); printf("请输入所要添加的街道:\n");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值