數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)電話簿管理(附源程序)_第1頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)電話簿管理(附源程序)_第2頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)電話簿管理(附源程序)_第3頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)電話簿管理(附源程序)_第4頁
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)電話簿管理(附源程序)_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、 簿管理源程序代碼,聯(lián)系153893706 指導(dǎo)老師: 一 課程設(shè)計(jì)題目 簿管理二 軟件開發(fā)環(huán)境和使用語言 Microsoft Visual C+ 6.0 ,C+三 軟件功能以及需求分析在現(xiàn)在這個(gè)科技高速發(fā)展的社會(huì)進(jìn)程中,交流成了社會(huì)生活重要的一部分,不過越來越多的聯(lián)系方式和號(hào)碼讓人們感覺到了麻煩。電子產(chǎn)品迅猛發(fā)展的時(shí)代,個(gè)人 簿管理系統(tǒng)在生活中使用的越來越頻繁。比如電子詞典等設(shè)備,這種不用動(dòng)一紙和一筆的系統(tǒng)成了產(chǎn)品的一大亮點(diǎn),有的家用 也增加了 簿,給用戶使用帶來很大的方便,尤其應(yīng)用在手機(jī)上。 對(duì)于 薄的要求,一般基本的要求主要是記錄姓名與 號(hào)碼。不過現(xiàn)在只記錄這一兩項(xiàng)已不能為人們滿足,人們

2、不僅需要記錄這些數(shù)據(jù)還要方便我們存入和查找。這樣在我們需要時(shí)才能更方便快速的找到我們需要的號(hào)碼。我完成的個(gè)人 簿管理系統(tǒng)是一個(gè)基于DOS界面的管理系統(tǒng)。程序的主要功能有:增加記錄、修改記錄、刪除記錄、顯示全部聯(lián)系人信息以及按姓氏查找聯(lián)系人等基本功能。程序設(shè)計(jì)思路和方法:本程序主要是以C+語言為主,運(yùn)用結(jié)構(gòu)體構(gòu)造對(duì)象的基本共同數(shù)據(jù),自定義函數(shù)來實(shí)現(xiàn)程序的各種功能,這樣使得程序有條理易于分塊。在主函數(shù)中對(duì)個(gè)個(gè)自定義函數(shù)調(diào)用,這用易于操作。對(duì)于每一條記錄,單獨(dú)設(shè)計(jì)成一個(gè)結(jié)構(gòu)體數(shù)據(jù)類型record。其成員主要有:姓氏、名字、固定 、移動(dòng) 。為了方便按姓氏查找,設(shè)計(jì)的時(shí)候,把姓名拆分開來,姓和名單獨(dú)存儲(chǔ)

3、。程序運(yùn)用具體操作流程和步驟:(1) 開始運(yùn)行程序時(shí),DOS界面出面“歡迎使用Rainboy個(gè)人 簿管理系統(tǒng)”,此時(shí)按任意鍵進(jìn)入主操作頁面。(2) 進(jìn)入到操作頁面有操作選項(xiàng):1 - 添加一條記錄;2 - 顯示全部記錄;3 - 按姓氏查找;4 - 更新記錄;5 - 刪除一條記錄;6 - 清空 簿;7 - 幫助;8 - 退出系統(tǒng);此時(shí)按照用戶具體的實(shí)際要求選擇相應(yīng)的功能選項(xiàng)進(jìn)行操作。最初使用 薄時(shí)要進(jìn)行新的數(shù)據(jù)項(xiàng)的輸入儲(chǔ)存,這個(gè)時(shí)候要先輸入姓氏,名字, 號(hào)碼,手機(jī)號(hào)碼。當(dāng)已有數(shù)據(jù)儲(chǔ)存可進(jìn)行其它的相關(guān)操作。當(dāng)用戶不知道下一部應(yīng)該做什么時(shí)或出現(xiàn)其它的情況時(shí)可以選擇幫助項(xiàng),在那里可以得到相關(guān)的幫助和解釋

4、。每做出一個(gè)操作動(dòng)作都會(huì)有相關(guān)的提示,如: “記錄刪除成功”,“沒有匹配記錄!”,“更新成功!”等,操作完畢后可以選擇退出系統(tǒng)。四 軟件設(shè)計(jì)代碼解釋 1結(jié)構(gòu)體:每一個(gè)對(duì)象的基本數(shù)據(jù)項(xiàng),其中定義了每一個(gè)數(shù)據(jù)項(xiàng)的最大儲(chǔ)存容量。 struct record/結(jié)構(gòu)體類型定義char lastName20;/姓氏char firstName15;/名字char phoneNum15;/ char mobile15;/手機(jī)record *next;全局變量:record *head;/全局變量,鏈表頭指針record *current;/全局變量,鏈表當(dāng)前結(jié)點(diǎn)指針2函數(shù)原型聲明:void handleCh

5、oice(int choice); /函數(shù)根據(jù)用戶的選擇調(diào)用相應(yīng)的函數(shù)處void addRecord(); /添加一條記錄void insertNode(record *newRecord); /記錄插入鏈表相應(yīng)的位置record *posInsertPoint(char lastname20); /按姓氏返回記錄在鏈表中正確的位置void makeNodeNewHead(record *newRecord);void addNodeToEnd(record *newRecord);void moveCurrentToEnd();void display(); /完成顯示全部信息void up

6、date(); /修改記錄void deleteRecord(); /刪除一條記錄void deleteAll(); /完成清空void deleteHead();void deleteEnd(record *previous);void deleteMiddle(record *previous);int verifyDelete(); /確認(rèn)是否執(zhí)行刪除void deleteNode(record *previous);void deleteList(); /刪除整個(gè)鏈表void searchByLastname(); /按姓氏查找匹配記錄void wiriteToFile();void

7、loadFromFile();void help(); /提供給用戶必要的操作信息char pause;3自定義函數(shù): 函數(shù)void handleChoice(int choice)根據(jù)用戶選擇(choice)調(diào)用對(duì)應(yīng)處函數(shù),對(duì)于用戶選擇的功能轉(zhuǎn)化為相應(yīng)的choice數(shù)值,void handleChoice(int choice)函數(shù)利用switch函數(shù)調(diào)動(dòng)不同的功能函數(shù)進(jìn)行操作。void handleChoice(int choice)switch(choice)case 1:/添加一條記錄addRecord();break;case 2:/顯示全部記錄display();break;cas

8、e 3:/按姓氏查找searchByLastname();break;case 4:/更新記錄update();break;case 5:/刪除一條記錄deleteRecord();break;case 6:/清空 簿deleteAll();break;case 7:/幫助help();break;case 8:/文件存盤,然后退出系統(tǒng)wiriteToFile();if(head != NULL)deleteList(); break;default : /其它輸入則出錯(cuò)cout <<"輸入有誤!請(qǐng)您重新輸入選項(xiàng)!n"break; 函數(shù)void addRecor

9、d()在鏈表中增加一個(gè)記錄功能,先執(zhí)行系統(tǒng)命令:cls-清屏,然后系統(tǒng)提示用戶按照步驟進(jìn)行輸入操作,然后調(diào)用insertNode(newRecord)查入結(jié)點(diǎn)。如果出錯(cuò)后提示"警告: 存儲(chǔ)器錯(cuò)誤, 新記錄添加失敗!"。addRecord函數(shù)完成添加一條記錄的功能的接收用戶輸入部分。設(shè)計(jì)的時(shí)候,把整個(gè)所有記錄信息以鏈表的方式存儲(chǔ)。每一條完整的record都是鏈表的一個(gè)結(jié)點(diǎn),最后所有信息在退出系統(tǒng)的時(shí)候以文件的方式存盤,信息存在同一目錄下的PhoneBook.dat文件中。當(dāng)下一次進(jìn)入系統(tǒng)的時(shí)候,重新加載信息。void addRecord()record *newRecord;

10、newRecord = new record;if(newRecord != NULL)system("cls");cout << "Add a new record.n" cout<<"*n"cout << "請(qǐng)您輸入.n"cin.ignore(20,'n');cout << " 姓氏: "cin.get(newRecord->lastName,20);cin.ignore(20,'n');cout <

11、< " 名字: "cin.get(newRecord->firstName,15);cin.ignore(20,'n');cout << " 號(hào)碼: "cin.get(newRecord->phoneNum,15);cin.ignore(20,'n');cout << " 手機(jī)號(hào)碼:"cin.get(newRecord->mobile,15);cin.ignore(20,'n');insertNode(newRecord);elsecout

12、 << "警告: 存儲(chǔ)器錯(cuò)誤, 新記錄添加失敗!n"system("cls");函數(shù)void insertNode(record *newRecord) 當(dāng)接收了用戶的輸入后就把這個(gè)新結(jié)點(diǎn)插入鏈表相應(yīng)的位置,這一操作是由insertNode函數(shù)完成的。先對(duì)屏幕清屏,如果鏈表為空,直接插入到頭結(jié)點(diǎn),否則利用posInsertPoint(newRecord->lastName)函數(shù)和addNodeToEnd(newRecord)函數(shù)進(jìn)行相關(guān)的數(shù)據(jù)插入操作。void insertNode(record *newRecord)system(&q

13、uot;cls");record *before;record *after;if(head = NULL)/鏈表為空,直接插入到頭結(jié)點(diǎn)newRecord->next = NULL;head = newRecord;elseif(strcmp(newRecord->lastName, head->lastName) < 0)makeNodeNewHead(newRecord);elsecurrent = posInsertPoint(newRecord->lastName);before = current;after = current->nex

14、t;if(after = NULL)addNodeToEnd(newRecord);elsebefore->next = newRecord;newRecord->next = after;函數(shù)record *posInsertPoint(char lastname20) 對(duì)于插入鏈表頭部或者尾部的情況很好處理,對(duì)于插入鏈表中間的情況,其核心是調(diào)用函數(shù)posInsertPoint按姓氏返回其在鏈表中正確的位置。record *posInsertPoint(char lastname20)char tempName20;record *temp;int tempint;if(head

15、->next != NULL)current = head;temp = current->next;strcpy(tempName, temp->lastName);tempint = strcmp(lastname,tempName);while(tempint > 0) && (current->next !=NULL)current = temp;if(current->next != NULL)temp = current->next;strcpy(tempName, temp->lastName);tempint =

16、strcmp(lastname,tempName);elsecurrent = head;return(current);函數(shù)makeNodeNewHead(record *newRecord),addNodeToEnd(record *newRecord),moveCurrentToEnd()分別實(shí)現(xiàn)將數(shù)據(jù)添加到鏈表頭部,末尾和current指針移動(dòng)到鏈表尾的操作功能。添加到鏈表頭部void makeNodeNewHead(record *newRecord)record *temp;temp = head;newRecord->next = temp;head = newRecord

17、;添加到鏈表末尾void addNodeToEnd(record *newRecord)newRecord->next = NULL;moveCurrentToEnd();current->next = newRecord;current指針移動(dòng)到鏈表尾void moveCurrentToEnd()current = head;while(current->next != NULL)current = current->next;函數(shù)void display()對(duì)數(shù)據(jù)進(jìn)行全部的顯示,display函數(shù)完成顯示全部信息的功能,其實(shí)就是一個(gè)鏈表的遍歷。void displa

18、y()char fullname36;current = head;if(current != NULL)cout << endl;cout << " 姓 名 號(hào)碼 手機(jī)號(hào)n"cout << "- - -n"dostrcpy(fullname,"");strcat(fullname, current->lastName);strcat(fullname, ", ");strcat(fullname, current->firstName);cout.setf(ios:

19、left);cout << setw(36) << fullname;cout.unsetf(ios:left);cout.setf(ios:right);cout << setw(12) << current->phoneNum;cout.unsetf(ios:left);cout.setf(ios:right);cout << setw(15) << current->mobile << endl;current = current->next;cout << endl;whi

20、le(current != NULL);cout << "Press Enter to continue n"cin.get(pause);cin.ignore(1,pause);system("cls");elsecout << "n記錄為空!n"cout << "Press Enter to continue n"cin.get(pause);cin.ignore(1,pause);system("cls");函數(shù)void searchByLastname

21、()對(duì)姓氏進(jìn)行查找void searchByLastname()system("cls");char searchStr20;current = head;cin.ignore(20,'n');cout << "Search.n"cout << "*n"cout << "請(qǐng)輸入姓氏: "cin.get(searchStr,20);cin.ignore(20,'n');while(current != NULL) && (strcmp

22、(current->lastName, searchStr) != 0)current = current->next;if(current != NULL)cout << "匹配的記錄:n"cout << current->firstName << ' ' << current->lastName << endl;cout << current->phoneNum << ' ' << current->mobi

23、le << endl;cout << "Press Enter to Contiunen"cin.get(pause);system("cls");elsecout << "沒有匹配記錄!n"cout << "Press Enter to Contiunen"cin.get(pause);system("cls");函數(shù)void update()進(jìn)行更新操作功能,修改記錄通過調(diào)用函數(shù)update完成,接收用戶新的記錄然后覆蓋舊的記錄。void up

24、date()system("cls");char searchStr20;current = head;cin.ignore(20,'n');cout << "Update.n"cout << "*n"cout << "請(qǐng)輸入需要更新記錄的姓氏:"cin.get(searchStr,20);cin.ignore(20,'n');while(current != NULL) && (strcmp(current->lastNam

25、e, searchStr) != 0)current = current->next;if(current != NULL)cout << "匹配的記錄:n"cout << current->lastName << ' ' << current->firstName << ' 'cout << current->phoneNum << ' ' << current->mobile << en

26、dl;cout << "請(qǐng)您輸入新的記錄信息.n"cout << "姓氏: "cin.get(current->lastName,20);cin.ignore(20,'n');cout << "名字: "cin.get(current->firstName,15);cin.ignore(20,'n');cout << " 號(hào)碼: "cin.get(current->phoneNum,15);cin.ignore(20,

27、'n');cout << "手機(jī)號(hào)碼:"cin.get(current->mobile,15);cin.ignore(20,'n');cout << "更新成功!n"cout << "Press Enter to Contiunen"cin.get(pause);system("cls");elsecout << "沒有指定要更新的記錄!n"cout << "Press Enter to

28、Contiunen"cin.get(pause);system("cls");函數(shù)void deleteRecord()實(shí)現(xiàn)刪除函數(shù)完成刪除一條記錄也就是鏈表的一個(gè)結(jié)點(diǎn)的功能。要求用戶輸入要?jiǎng)h除的記錄,然后進(jìn)行查找,找到了就進(jìn)行刪除操作,若沒有打到就提示刪除失敗。void deleteRecord()system("cls");char searchStr20;record *previous;previous = NULL;current = head;cin.ignore(20,'n');cout << &quo

29、t;請(qǐng)輸入需要?jiǎng)h除的記錄的姓氏: "cin.get(searchStr,20);cin.ignore(20,'n');while(current != NULL) && (strcmp(current->lastName, searchStr) != 0)previous = current;current = current->next;if(current != NULL)cout << "n匹配記錄n"cout << current->firstName << '

30、' << current->lastName << endl;cout << current->phoneNum << ' ' << current->mobile << endl;if(verifyDelete()deleteNode(previous);cout << "n記錄刪除成功!n"elsecout << "n記錄刪除失敗!n"elsecout << "n沒有匹配記錄,刪除失敗!n&q

31、uot;system("cls");函數(shù)verifyDelte()函數(shù)讓用戶確認(rèn)是否執(zhí)行刪除操作,為了防止操作疏忽造成的數(shù)據(jù)丟失。關(guān)于刪除操作,同樣可以分為從鏈表頭結(jié)點(diǎn)、尾結(jié)點(diǎn)和中間刪除三種情況,函數(shù)deleteHead、deleteEnd和deleteMiddle三個(gè)函數(shù)完成對(duì)應(yīng)的操作。int verifyDelete()char YesNo;cout << "nAre you sure (Y/N) "cin >> YesNo;if(YesNo = 'Y') | (YesNo = 'y')retu

32、rn(1);elsereturn(0);刪除結(jié)點(diǎn)void deleteNode(record *previous)if(current = head)deleteHead();elseif(current->next = NULL)deleteEnd(previous);elsedeleteMiddle(previous);刪除頭結(jié)點(diǎn)void deleteHead()current = head;if(head->next != NULL)head = current->next;elsehead = NULL;delete current;刪除尾結(jié)點(diǎn)void deleteE

33、nd(record *previous)delete current;previous->next = NULL;current = head;刪除鏈表中間結(jié)點(diǎn)void deleteMiddle(record *previous)previous->next = current->next;delete current;current = head;刪除鏈表void deleteList()record *temp;current = head;dotemp = current->next;delete current;current = temp;*/while(te

34、mp != NULL);head = NULL;函數(shù)void wiriteToFile()和void loadFromFile()實(shí)現(xiàn)信息寫入文件和信息加載兩個(gè)操作。把鏈表信息寫入文件存盤void wiriteToFile()ofstream outfile;outfile.open("PhoneBook.dat",ios:out);if (outfile)current = head;if(head != NULL)dooutfile << current->lastName << endl;outfile << current-

35、>firstName << endl;outfile << current->phoneNum << endl;outfile << current->mobile << endl;current = current->next;while(current != NULL);outfile << "End" << endl;outfile.close();elsecout << "打開文件錯(cuò)誤!n"從數(shù)據(jù)文件PhoneBook.dat中

36、讀取數(shù)據(jù)重建鏈表處理函數(shù)void loadFromFile()record *newRecord;ifstream infile;int loop = 0;infile.open("PhoneBook.dat",ios:in);if (infile)donewRecord = new record;if(newRecord != NULL)infile.get(newRecord->lastName,20);infile.ignore(20,'n');if(strcmp(newRecord->lastName, "") !=

37、0) && (strcmp(newRecord->lastName, "End") != 0)infile.get(newRecord->firstName, 15);infile.ignore(20,'n');infile.get(newRecord->phoneNum, 15);infile.ignore(20,'n');infile.get(newRecord->mobile, 15);insertNode(newRecord);elsedelete newRecord;loop = 1;else

38、cout << "警告: 存儲(chǔ)器錯(cuò)誤, 從磁盤加載文件失敗!n"loop = 1;while(loop = 0);infile.close();elsecout << " 簿為空!n"函數(shù)int main()是程序的主要核心部分,所有用戶要求的功能運(yùn)行都是在這個(gè)部分進(jìn)行調(diào)用的,增加記錄、修改記錄、刪除記錄、顯示全部聯(lián)系人信息以及按姓氏查找聯(lián)系人等功能模塊的調(diào)用都是通過這個(gè)部分完成的。int main()cout << "Welcome.n"cout << "*n"co

39、ut << "nnn 歡迎使用PhoneBook個(gè)人 簿管理系統(tǒng). nn"cout << " Press enter to continue!nnn"cout << "n*"cin.get(pause);system("cls");/執(zhí)行系統(tǒng)命令:cls-清屏int choice;head = NULL;loadFromFile();do/主菜單顯示cout << "Menu.n"cout << "*n"cout &

40、lt;< " PhoneBook個(gè)人 管理系統(tǒng)主菜單 nn"cout << "請(qǐng)選擇以下功能: n"cout << " 1 - 添加一條記錄n"cout << " 2 - 顯示全部記錄n"cout << " 3 - 按姓氏查找n"cout << " 4 - 更新記錄n"cout << " 5 - 刪除一條記錄n"cout << " 6 - 清空 簿n"cout <<&quo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論