日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

基于C语言通讯录管理系统编程设计

發布時間:2023/12/31 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于C语言通讯录管理系统编程设计 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.課程目的
本程序旨在訓練學生的C語言基本編程能力,通過串聯C語言輸入輸出、循環語句、子函數設計、數組、結構體、指針等知識點,完成一個簡單系統的設計開發。
2.系統功能
(1)通過菜單的形式實現人機交互界面
(2)實現批量錄入聯系人基本信息功能
(3)實現查詢指定聯系人的基本信息
(4)實現添加單個聯系人的基本信息
(5)實現刪除指定聯系人的基本信息
(6)實現對所有聯系人打印顯示
3.設計思想
(1)人機交互界面
使用printf()和scanf()輸入輸出函數設計出主界面交互菜單,通過switch case語句判斷輸入的選項值,執行相對應得子函數。
設計程序保存菜單選項,用戶執行其選項后,需要使用C語言文件操作,保存當前錄入得全部聯系人的基本信息。
程序啟動時需要打開上次保存得數據文件,讀入到內存中,如果沒有則新建一個文件用于程序退出時保存數據。
人機交互界面可以自己設計,可以加上開發者信息,體現每個學生的差異。
展示如下:

2)批量添加聯系人信息
設計為單獨的子函數供主函數調用。
定義一個結構體類型,包括四個成員變量(姓名,職業,手機號,電子郵件,通訊地址),并用該類型定義一個全局的結構體數組,供外部錄入聯系人信息時存儲。
定義一個全局變量來存儲當前聯系人個數。
添加聯系人信息時,需要從外部讀入聯系人的姓名,職業,手機號,電子郵件以及通訊地址,聯系人個數變量加一,并根據當前聯系人個數將其保存在結構體數組對應序號的元素中。
當聯系人姓名為“0”時,表示錄入結束。
(3)顯示全部聯系人信息
通過對當前結構體數組進行遍歷,并顯示輸出
展示如下:

(4)查找單個聯系人
根據輸入需要查找聯系人的信息,遍歷當前結構體數組,判斷是否含有一致姓名的元素,若有則顯示輸出對應的信息,否則顯示此人未在本通訊錄中。
顯示如下:


5)添加單個聯系人
此項功能與(2)中批量添加聯系人類似,本功能為添加一個聯系人,顯示如下:

(6)刪除指定聯系人
根據輸入需要刪除聯系人的姓名,遍歷當前結構體數組,判斷是否含有一致姓名的元素,若有則從該元素之后依次將下一個元素賦值到上一個元素,直至最后一個賦值完成,最后當前聯系人個數變量減一。
顯示如下:

7)保存通訊錄
將通訊錄文件內容保存到本地。
展示如下:

struct address_list {int num; //編號 char name[30]; //名字char work[30]; //職業char handset[30]; //手機char email[30]; //電子郵件char address[30]; //通訊地址struct address_list *next; }peo[30]; struct address_list *shifang(struct address_list *head); // 釋放內存函數聲明//創建函數,不帶頭結點的鏈表 struct address_list *creat(void) {struct address_list *head,*p1,*p2;char name[20];n=0;p1=(struct address_list *)malloc(LEN);p2=p1; //強制內存轉換printf("請輸入通訊錄的內容!\n姓名輸入為0時表示創建完畢!\n");printf("請輸入姓名:");gets(name);if(strcmp(name,"0")!=0){strcpy(p1->name,name);printf("請輸入職業:"); gets(p1->work);printf("請輸入手機:"); gets(p1->handset);printf("請輸入電子郵件:"); gets(p1->email);printf("請輸入通訊地址:"); gets(p1->address);head=NULL;while(1){n=n+1; //記錄通訊錄人數個數if(n==1)head=p1;elsep2->next=p1;p2=p1;printf("請輸入姓名:");gets(name);if(strcmp(name,"0")==0){break;}else{p1=(struct address_list *)malloc(LEN);strcpy(p1->name,name);printf("請輸入職業:"); gets(p1->work);printf("請輸入手機:"); gets(p1->handset);printf("請輸入電子郵件:"); gets(p1->email);printf("請輸入通訊地址:"); gets(p1->address);}}p2->next=NULL;return head;}elsereturn 0; } //輸出函數 void print(struct address_list *head) {struct address_list *p;if(head!=NULL){p=head;printf("本通訊錄現在共有%d人:\n",n);printf("---姓名-------職業--------手機-------Email-------通訊地址\n");printf("==================================\n");do{printf("== %s",p->name); printf(" ");printf("%s",p->work); printf(" ");printf("%s",p->handset); printf(" ");printf("%s",p->email); printf(" ");printf("%s",p->address); printf(" \n");p=p->next;}while(p!=NULL);printf("==================================\n");}elseprintf("通訊錄為空,無法輸出!\n"); } //增加函數 struct address_list *insert(struct address_list *head) {struct address_list *p0,*p1,*p2;char name[20];p1=head;printf("請輸入增加的內容:\n");printf("請輸入姓名:"); gets(name);if(strcmp(name,"0")==0){printf("姓名不能為0,增加失敗!\n");return(head);}else{p0=(struct address_list *)malloc(LEN);strcpy(p0->name,name);printf("請輸入職業:"); gets(p0->work);printf("請輸入手機:"); gets(p0->handset);printf("請輸入電子郵件:"); gets(p0->email);printf("請輸入通訊地址:"); gets(p0->address);n=n+1;if(head==NULL){head=p0;p0->next=NULL;return head;}else{while(strcmp(p0->name,p1->name)>0&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(strcmp(p0->name,p1->name)<0 || strcmp(p0->name,p1->name)==0){if(head==p1){head=p0;}else{p2->next=p0;}p0->next=p1;}else{p1->next=p0;p0->next=NULL;}return head;}} } //刪除函數 struct address_list* delete_txl(struct address_list *head) {struct address_list *p,*q;char name[30];if(head==NULL){printf("通訊錄為空,無法顯示!\n");return head;}p=head;printf("請輸入需要刪除的人的姓名:");gets(name);if(strcmp(head->name,name)==0){head=head->next;free(p);printf("刪除操作成功!\n");return head;}else{q=head,p=head->next;while(p!=NULL){if(strcmp(p->name,name)==0){q->next=p->next;free(p);printf("刪除操作成功!\n");return head;}p=p->next;q=q->next;}} } //顯示函數 struct address_list *display(struct address_list *head) {struct address_list *p1,*p2;char name[30];int m;if(head==NULL){printf("通訊錄為空,無法顯示!\n");return head;}p1=head;m=0;printf("請輸入需要顯示人的姓名:");gets(name);while(p1!=NULL){while((strcmp(p1->name,name))!=0 && p1->next!=NULL){p2=p1;p1=p1->next;}if(strcmp(p1->name,name)==0){m++;printf("%s的通訊內容如下:\n",name);printf("---姓名--------職業--------手機-------Email------通訊地址\n");printf("==================================\n");printf("== %s",p1->name);printf(" ");printf("%s",p1->work);printf(" ");printf("%s",p1->handset);printf(" ");printf("%s",p1->email);printf(" ");printf("%s",p1->address); printf(" \n");printf("==================================\n");}p1=p1->next;}if(m==0){printf("此人未在本通訊錄中!\n");}return(head); }//姓名查找函數 struct address_list *search(struct address_list *head) {struct address_list *p1,*p2;int m;char name[30];if(head==NULL){printf("通訊錄為空,無法分類查找!\n");return(head);}p1=head;printf("********************\n");printf("** 請輸入需要查找的姓名 **\n");printf("********************\n");m=0;gets(name);while(p1!=NULL){while(strcmp(p1->name,name)!=0&&p1->next!=NULL){p2=p1;p1=p1->next;}if(strcmp(p1->name,name)==0){m++;printf("你查找的內容是:\n");printf("+++++++++++++++++++++++++++++++++++\n");printf("++ %s %s %s %s %s\n",p1->name,p1->work,p1->handset,p1->email,p1->address);printf("+++++++++++++++++++++++++++++++++++\n");}p1=p1->next;if(m==0){printf("此人未在本通訊錄中!\n");}break;}return(head); }//釋放內存函數 struct address_list *shifang(struct address_list *head) {struct address_list *p1;while(head!=NULL){p1=head;head=head->next;free(p1);}return(head); }//文件寫入函數 void save(struct address_list *head) {FILE *fp;struct address_list *p1;char tong[30];if(head==NULL){printf("通訊錄為空,無法存儲!\n");return;}printf("請輸入保存后的文件名:");gets(tong);fp=fopen("(tong).txt","w");if(fp==NULL){printf("cannot open file\n");return;}p1=head;fprintf(fp,"姓名 職業 手機 Email 通訊地址\n");for(;p1!=NULL;) {fprintf(fp,"%s %s %s %s %s\n",p1->name,p1->work,p1->handset,p1->email,p1->address);p1=p1->next;}printf("保存完畢!\n");fclose(fp); }//主函數 void main() {struct address_list *head=NULL;char num[10];printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");printf("*=* 程序說明 *=*\n");printf("*=* 請及時保存創建完畢的通訊錄內容! *=*\n");printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");while(1){printf("************************\n");printf("*** 1 批量添加聯系人 ****\n");printf("*** 2 查找聯系人 ****\n");printf("*** 3 添加聯系人 ****\n");printf("*** 4 刪除聯系人 ****\n");printf("*** 5 保存通訊錄 ****\n"); printf("*** 6 退出系統 ****\n");printf("************************\n");printf("請輸入您選擇的操作:");gets(num);switch(*num){case '1':{if(head==NULL){head=creat(); //創建print(head);}else{head=shifang(head);head=creat(); //重新創建print(head);}}break;case '2':{head=display(head); //增加操作 }break;case '3':{head=insert(head); //增加操作print(head); }break;case '5':{save(head); //文件保存print(head);}break;case '4':{head=delete_txl(head); //刪除print(head);}break;case '6':head=shifang(head);break;default:printf("操作錯誤,此項不存在!\n");break;}if(strcmp(num,"6")==0)break;} }

總結

以上是生活随笔為你收集整理的基于C语言通讯录管理系统编程设计的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。