C語(yǔ)言通訊錄管理系統(tǒng)課程設(shè)計(jì)
本文實(shí)例為大家分享了C語(yǔ)言通訊錄管理系統(tǒng)課程設(shè)計(jì),供大家參考,具體內(nèi)容如下
#include <stdio.h> #include <stdlib.h> #include <windows.h> struct Sign{ char name[8]; char sex[4]; char birthday[12]; char phone[11]; char postcode[7]; char addr[30]; struct Sign *next; }pe; char PhoneCop[4] ; //結(jié)構(gòu)體 struct Sign *p1,*p2,*head; FILE *fp; void ShowMenu(){ system("color 1F"); printf("################# 通訊錄管理系統(tǒng) v1.0 ###################\n"); printf("#####################################################################\n"); printf("# #\n"); printf("# 1-----------------信息錄入------------------- #\n"); printf("# #\n"); printf("# 2-----------------信息查詢(xún)------------------- #\n"); printf("# #\n"); printf("# 3-----------------信息查看------------------- #\n"); printf("# #\n"); printf("# 4-----------------信息修改------------------- #\n"); printf("# #\n"); printf("# 5-----------------信息統(tǒng)計(jì)------------------- #\n"); printf("# #\n"); printf("# 6-----------------退出系統(tǒng)------------------- #\n"); printf("# #\n"); printf("#####################################################################\n"); printf("# POWER BY ************* 蘭州理工大學(xué) 201407 #\n"); printf("#####################################################################\n"); }; void HeadShow() { printf("################# 通訊錄管理系統(tǒng) v1.0 ###################\n"); printf("---------------------------------------------------------------------\n"); } void FileLoading() { if((fp=fopen("txl.dat","rb"))==NULL) { printf("文件操作錯(cuò)誤,請(qǐng)檢查是否有權(quán)限操作文件!"); Sleep(3000); exit(1); } p1=(struct Sign*)malloc(sizeof(struct Sign)); p1->next=NULL; head=p1; while(!feof(fp)) { if(fread(p1,sizeof(struct Sign),1,fp)!=1) break; p2=(struct Sign*)malloc(sizeof(struct Sign)); p2->next=NULL; p1->next=p2; p1=p2; } fclose(fp); } void add() { char ch; if((fp==fopen("txl.dat","ab+"))!=1) { printf("文件打開(kāi)失敗"); exit(1); } while(1) { system("cls"); printf("請(qǐng)輸入__\n"); p2=(struct Sign*)malloc(sizeof(struct Sign)); p2->next=NULL; printf("姓名:");scanf("%s",pe.name); printf("性別:");scanf("%s",pe.sex); printf("生日:");scanf("%s",pe.birthday); printf("電話(huà)號(hào)碼:");scanf("%s",pe.phone); printf("郵編:");scanf("%s",pe.postcode); printf("地址:");scanf("%s",pe.addr); strcpy(p1->name,pe.name); strcpy(p1->sex,pe.sex); strcpy(p1->birthday,pe.birthday); strcpy(p1->phone,pe.phone); strcpy(p1->postcode,pe.postcode); strcpy(p1->addr,pe.addr); p1->next=p2; p1=p2; if(fwrite(&pe,sizeof(struct Sign),1,fp)!=1) printf("寫(xiě)入錯(cuò)誤"); printf("輸入E或e來(lái)結(jié)束輸入?"); getchar(); ch=getchar(); if(ch=='e'||ch=='E') break; } fclose(fp); } void SaveChange() { if((fp==fopen("txl.dat","w"))!=1) { printf("文件打開(kāi)失敗"); exit(1); } p1=head; while(p1->next!=NULL) { if(fwrite(p1,sizeof(struct Sign),1,fp)!=1) printf("寫(xiě)入錯(cuò)誤"); p1=p1->next; } fclose(fp); } void AllShow() { HeadShow(); printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n","姓名","性別","生日","電話(huà)","郵編","地址"); printf("---------------------------------------------------------------------\n"); p1=head; while(p1->next!=NULL) { printf("%10.8s %6.6s %10.12s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); p1=p1->next; } } void AllNum() { int i=0; HeadShow(); printf(" 共有記錄條數(shù)為: \n"); printf("---------------------------------------------------------------------\n"); p1=head; while(p1->next!=NULL) { i++; p1=p1->next; } printf(" %d \n",i); printf("---------------------------------------------------------------------\n"); printf(" 共有聯(lián)通用戶(hù)為: \n"); printf("---------------------------------------------------------------------\n"); p1=head; i=0; while(p1->next!=NULL) { strncpy(PhoneCop,p1->phone,3); if(strcmp(PhoneCop,"130")==0||strcmp(PhoneCop,"131")==0||strcmp(PhoneCop,"132")==0||strcmp(PhoneCop,"155")==0||strcmp(PhoneCop,"156")==0||strcmp(PhoneCop,"185")==0||strcmp(PhoneCop,"186")==0) i++; p1=p1->next; } printf(" %d \n",i); printf("---------------------------------------------------------------------\n"); printf(" 共有移動(dòng)用戶(hù)為: \n"); printf("---------------------------------------------------------------------\n"); p1=head; i=0; while(p1->next!=NULL) { strncpy(PhoneCop,p1->phone,3); if(strcmp(PhoneCop,"134")==0||strcmp(PhoneCop,"135")==0||strcmp(PhoneCop,"136")==0||strcmp(PhoneCop,"137")==0||strcmp(PhoneCop,"138")==0||strcmp(PhoneCop,"139")==0||strcmp(PhoneCop,"150")==0||strcmp(PhoneCop,"151")==0||strcmp(PhoneCop,"152")==0||strcmp(PhoneCop,"157")==0||strcmp(PhoneCop,"158")==0||strcmp(PhoneCop,"159")==0||strcmp(PhoneCop,"187")==0||strcmp(PhoneCop,"188")==0) i++; p1=p1->next; } printf(" %d \n",i); printf("---------------------------------------------------------------------\n"); printf(" 共有電信用戶(hù)為: \n"); printf("---------------------------------------------------------------------\n"); p1=head; i=0; while(p1->next!=NULL) { strncpy(PhoneCop,p1->phone,3); if(strcmp(PhoneCop,"180")==0||strcmp(PhoneCop,"189")==0||strcmp(PhoneCop,"133")==0||strcmp(PhoneCop,"153")==0) i++; p1=p1->next; } printf(" %d \n",i); printf("---------------------------------------------------------------------\n"); } void CheckFace() { int Check_key; printf("########### 通訊錄管理系統(tǒng) v1.0 ################\n"); printf("############################################################\n"); printf("# #\n"); printf("# 1------按姓名查詢(xún) #\n"); printf("# #\n"); printf("# 2------按電話(huà)號(hào)碼查詢(xún) #\n"); printf("# #\n"); printf("# 3------綜合查詢(xún) #\n"); printf("# #\n"); printf("# 4------退出查詢(xún)模塊 #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("############################################################\n"); printf("# POWER BY ************* 蘭州理工大學(xué) 201407 #\n"); printf("############################################################\n"); } void Selelctname() { system("cls"); HeadShow(); printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n","姓名","性別","生日","電話(huà)","郵編","地址"); printf("---------------------------------------------------------------------\n"); p1=head; char FindName[8]; int i=0; printf("請(qǐng)輸入要查詢(xún)的姓名:"); scanf("%s",&FindName); while(p1->next!=NULL) { if(strcmp(p1->name,FindName)==0) {printf("%10.8s %6.6s %10.10s %11.14s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); i++; } p1=p1->next; } printf("共 %d 條\n",i); system("pause"); } void Selelctphone() { system("cls"); HeadShow(); printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n","姓名","性別","生日","電話(huà)","郵編","地址"); printf("---------------------------------------------------------------------\n"); p1=head; char phone[11]; int i=0; printf("請(qǐng)輸入要查詢(xún)的電話(huà)號(hào)碼:"); scanf("%s",&phone); while(p1->next!=NULL) { if(strcmp(p1->phone,phone)==0) {printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); i++; } p1=p1->next; } printf("共 %d 條\n",i); system("pause"); } void Selelctall() { system("cls"); HeadShow(); printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n","姓名","性別","生日","電話(huà)","郵編","地址"); printf("---------------------------------------------------------------------\n"); p1=head; char all[30]; int i=0; printf("請(qǐng)輸入任意一項(xiàng)要查詢(xún)的內(nèi)容:"); scanf("%s",&all); while(p1->next!=NULL) { if(strcmp(p1->name,all)==0||strcmp(p1->sex,all)==0||strcmp(p1->birthday,all)==0||strcmp(p1->phone,all)==0||strcmp(p1->postcode,all)==0||strcmp(p1->addr,all)==0) {printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); i++; } p1=p1->next; } printf("共 %d 條\n",i); system("pause"); } void Change() { char ChangeName[8]; int changekey; system("cls"); HeadShow(); int i,y=0; p1=p2=head; printf("請(qǐng)輸入你要修改的條目的姓名:"); scanf("%s",&ChangeName); getchar(); while(p1!=NULL) { if(strcmp(p1->name,ChangeName)==0) { printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); printf("您要修改的是這條記錄嗎?1---是|2---否\n"); scanf("%d",&i); if(i==1) { y=1; printf("你要修改的通訊錄為:\n"); printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr); printf("請(qǐng)選擇您的操作 1---刪除|2---修改\n"); scanf("%d",&changekey); if(changekey==1) { if(p1==head) {head=p1->next; free(p1); } else { p2->next=p1->next; free(p1); SaveChange(); } } else if(changekey==2) { printf("姓名:");scanf("%s",p1->name); printf("性別:");scanf("%s",p1->sex); printf("生日:");scanf("%s",p1->birthday); printf("電話(huà):");scanf("%s",p1->phone); printf("郵編:");scanf("%s",p1->postcode); printf("地址:");scanf("%s",p1->addr); SaveChange(); printf("\n OK! \n"); } } } else if(strcmp(p1->name,ChangeName)&&(p1->next)==NULL) { i=0; } p2=p1; p1=p1->next; } if(y==0) { printf("對(duì)不起,沒(méi)有找到要修改的通訊名單,請(qǐng)檢查你要修改的姓名是否正確\n"); } system("pause"); } void ExirShow() { system("color 0E"); printf("########### 通訊錄管理系統(tǒng) v1.0 ################\n"); printf("############################################################\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("# 謝謝使用! #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("# #\n"); printf("############################################################\n"); printf("# POWER BY ************* 蘭州理工大學(xué) 201407 #\n"); printf("############################################################\n"); } void ErrorShow() { int errortime=5; system("color 0E"); for(errortime=5;errortime>0;errortime--) {printf("\r輸入錯(cuò)誤!請(qǐng)仔細(xì)檢查!將在%d秒后返回",errortime); Sleep(1000); } } int main() { int key; int Ex_key; int Check_key; char a[10]; if((fp=fopen("txl.dat","ab"))==NULL) { printf("文件操作錯(cuò)誤,請(qǐng)檢查是否有權(quán)限操作文件!"); Sleep(3000); exit(1); } fclose(fp); FileLoading(); while(1){ ShowMenu(); gets(a); key=atoi(a); if(key==1) {system("cls"); add(); } else if(key==2) { system("cls"); system("color 0E"); while(1) { system("color 0E"); CheckFace(); printf("請(qǐng)輸入你的選擇:\n"); gets(a); Check_key=atoi(a); if(Check_key==1) Selelctname() ; else if(Check_key==2) Selelctphone() ; else if(Check_key==3) Selelctall() ; else if(Check_key==4) break; else ErrorShow(); system("cls"); system("color 1F"); getchar(); } } else if(key==3) //2013級(jí) 耿。。 { system("color 0E"); system("cls"); AllShow(); system("pause"); } else if(key==4) { system("color 0A"); Change(); } else if(key==5) { system("color 5F"); system("cls"); AllNum(); system("pause"); } else if(key==6) { system("cls"); ExirShow(); Sleep(1000); exit(0); } else ErrorShow(); system("cls"); system("color 1F"); getchar(); } }
比較簡(jiǎn)單就是用到了鏈表和文件操作,其中統(tǒng)計(jì)聯(lián)通和移動(dòng)人數(shù)的那里其實(shí)只用一個(gè)循環(huán)就可以。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:C語(yǔ)言對(duì)對(duì)碰游戲源碼分享
欄 目:C語(yǔ)言
本文標(biāo)題:C語(yǔ)言通訊錄管理系統(tǒng)課程設(shè)計(jì)
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/877.html
您可能感興趣的文章
- 04-02c語(yǔ)言函數(shù)調(diào)用后清空內(nèi)存 c語(yǔ)言調(diào)用函數(shù)刪除字符
- 04-02c語(yǔ)言的正則匹配函數(shù) c語(yǔ)言正則表達(dá)式函數(shù)庫(kù)
- 04-02func函數(shù)+在C語(yǔ)言 func函數(shù)在c語(yǔ)言中
- 04-02c語(yǔ)言中對(duì)數(shù)函數(shù)的表達(dá)式 c語(yǔ)言中對(duì)數(shù)怎么表達(dá)
- 04-02c語(yǔ)言用函數(shù)寫(xiě)分段 用c語(yǔ)言表示分段函數(shù)
- 04-02c語(yǔ)言編寫(xiě)函數(shù)冒泡排序 c語(yǔ)言冒泡排序法函數(shù)
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 04-02c語(yǔ)言分段函數(shù)怎么求 用c語(yǔ)言求分段函數(shù)
- 04-02C語(yǔ)言中怎么打出三角函數(shù) c語(yǔ)言中怎么打出三角函數(shù)的值
- 04-02c語(yǔ)言調(diào)用函數(shù)求fibo C語(yǔ)言調(diào)用函數(shù)求階乘


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 04-02c語(yǔ)言函數(shù)調(diào)用后清空內(nèi)存 c語(yǔ)言調(diào)用
- 04-02func函數(shù)+在C語(yǔ)言 func函數(shù)在c語(yǔ)言中
- 04-02c語(yǔ)言的正則匹配函數(shù) c語(yǔ)言正則表達(dá)
- 04-02c語(yǔ)言用函數(shù)寫(xiě)分段 用c語(yǔ)言表示分段
- 04-02c語(yǔ)言中對(duì)數(shù)函數(shù)的表達(dá)式 c語(yǔ)言中對(duì)
- 04-02c語(yǔ)言編寫(xiě)函數(shù)冒泡排序 c語(yǔ)言冒泡排
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 04-02c語(yǔ)言分段函數(shù)怎么求 用c語(yǔ)言求分段
- 04-02C語(yǔ)言中怎么打出三角函數(shù) c語(yǔ)言中怎
- 04-02c語(yǔ)言調(diào)用函數(shù)求fibo C語(yǔ)言調(diào)用函數(shù)求
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 01-10delphi制作wav文件的方法
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?