




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、VC+6.0 課 程C+課程實(shí)驗(yàn)報(bào)告一、實(shí)驗(yàn)題目:電話本管理二、功能描述: 這是一個(gè)電話簿管理小程序,利用文本文件儲(chǔ)存電話簿數(shù)據(jù),具有添加、刪除、顯示和查詢聯(lián)系人電話號(hào)碼功能。在這個(gè)小型管理程序中,類與類之間通過鏈表將各個(gè)數(shù)據(jù)相連接,形成一個(gè)通暢的應(yīng)用小程序!在程序中,對于用戶需求盡可能的予以滿足.3、 算法設(shè)計(jì)與實(shí)驗(yàn)步驟4、 流程圖:按ENTER進(jìn)入電話本功能界面電話本功能界面(用戶根據(jù)界面說明進(jìn)行選擇操作)6刪除記錄2查找并修改1添加聯(lián)系人0進(jìn)入幫助4首字母近似查找3姓名查找聯(lián)系人5顯示全部記錄7退出電話簿程序并保存電話簿數(shù)據(jù)逐一刪除聯(lián)系人數(shù)據(jù),首先輸入聯(lián)系人姓名顯示電話薄全部數(shù)據(jù)輸入首字
2、母匹配查找輸入姓名查找輸入聯(lián)系人姓名,查找修改根據(jù)提示用戶新建聯(lián)系人姓名和電話號(hào)碼用戶根據(jù)幫助程序用戶選擇0后進(jìn)入幫助界面2怎樣顯示我的電話本5退出幫助進(jìn)入電話簿功能界面4什么時(shí)候有一種新版面3什么時(shí)候我有一種新版面1怎樣產(chǎn)生一個(gè)新紀(jì)錄電話本功能界面四、類與對象結(jié)構(gòu)描述,核心程序代碼(需要有相應(yīng)的注釋)1.程序中所定義的類(1)電話簿記錄類class CTelRecordprivate:int nYear,nMonth,nDay,nHour,nMinute,nSecond; /時(shí)間單元char szName20;/電話簿數(shù)據(jù):姓名和電話號(hào)碼char Last20;char szNumber20
3、;public:CTelRecord()/構(gòu)造函數(shù)CTelRecord(char *name,char *number);void SetRecord(char *name,char *last,char *number);/輸出時(shí)間int Compare(char *name);/根據(jù)姓名查找void SetName(char *name)strcpy(szName,name); void SetNum(char *num)strcpy(szNumber,num);void SetLast(char *last)strcpy(Last,last);char *GetName(void)ret
4、urn szName;/需通過函數(shù)訪問的私有成員char *GetLast(void)return Last;char *GetNum(void)return szNumber;int GetYear(void)return nYear;int GetMonth(void)return nMonth;int GetDay(void)return nDay;int GetHour(void)return nHour;int GetMinute(void)return nMinute;int GetSecond(void)return nSecond;void Show();/打印數(shù)據(jù)void M
5、odify(char *number);/修改結(jié)點(diǎn)函數(shù)int LookChar(char *szName);/按首字母查找匹配姓名;(2)定義結(jié)點(diǎn)類class CNodeprivate:CTelRecord *pData;/用于指向數(shù)據(jù)類指針CNode *pNext;/指向鏈表下一個(gè)結(jié)點(diǎn)指針public:CNode()pData=0;pNext=0; /結(jié)點(diǎn)構(gòu)造CNode(CNode &node);/拷貝構(gòu)造函數(shù)void ShowNode()pData->Show(); /指向打印函數(shù)CTelRecord *GetData(void)return pData;friend cla
6、ss CList;/定義鏈表類為友元類;(3) 定義鏈表類class CList CNode *head_ptr,*current_ptr;public:CList()head_ptr=NULL;/構(gòu)造函數(shù)void Help_me();/幫助函數(shù)void AddNode(); /在首部添加結(jié)點(diǎn)void DeleteNode(); /刪除結(jié)點(diǎn)void ShowList(); /顯示所有記錄void DeleteList();/刪除所有記錄void Search();/查找CNode *GetListHead()return head_ptr;void Insert(CNode *new_rec_
7、ptr);/按順序插入新節(jié)點(diǎn)CNode*Position_insertion_point(char name20);void ModNum(void);/修改號(hào)碼void SearchFriends(void);/查找具有相似名的記錄void load_list_from_file(void);/保存文件void write_list_to_file();/把文件數(shù)據(jù)寫入鏈表中;2. 新增函數(shù)說明根據(jù)姓氏,返回其在鏈表中的正確位置,新節(jié)點(diǎn)即將插入此點(diǎn)。CNode*CList:Position_insertion_point(char name20) char temp_name20; CNod
8、e *temp_ptr; int tempint; if(head_ptr->pNext!=NULL)/ 如果有多于一個(gè)結(jié)點(diǎn)的鏈表,查找結(jié)點(diǎn)在鏈表中的正確位置 current_ptr=head_ptr; temp_ptr=current_ptr->pNext; strcpy(temp_name,temp_ptr->pData->GetName(); tempint=strcmp(name,temp_name);/*比較鏈表中的姓氏與欲插入的姓氏的大小*/ while(tempint>0)&¤t_ptr->pNext!=NULL)/
9、*若欲插入的姓氏大于鏈表中當(dāng)前結(jié)點(diǎn)的姓氏,繼續(xù)向下查找*/ current_ptr=temp_ptr; if(current_ptr->pNext!=NULL) temp_ptr=current_ptr->pNext; strcpy(temp_name,temp_ptr->pData->GetName(); tempint=strcmp(name,temp_name); else/如果只有一個(gè)頭結(jié)點(diǎn),返回頭結(jié)點(diǎn)的位置,新結(jié)點(diǎn)插在頭節(jié)點(diǎn)后 current_ptr=head_ptr; return(current_ptr);3.電話簿記錄在鏈表的讀取與寫入(1)從鏈表讀取數(shù)
10、據(jù)void CList:load_list_from_file(void)/從數(shù)據(jù)文件FRIENDS.DAT中讀取數(shù)據(jù),重建鏈表處理函數(shù) CNode *new_rec_ptr;/CTelRecord *Phonebook; ifstream infile;int end_loop=0;infile.open("FRIENDS.DAT",ios:in);if(infile)/打開文件正確 donew_rec_ptr=new CNode;new_rec_ptr->pData=new CTelRecord; if(new_rec_ptr!=NULL)char name20,
11、last20,number20; int year,month,day,hour,minute,second;infile.getline(name,20);new_rec_ptr->pData->SetName(name);infile.getline(last,20);new_rec_ptr->pData->SetLast(last);if(strcmp(new_rec_ptr->pData->GetName(),"")!=0)&&(strcmp(new_rec_ptr->pData->GetName(),
12、"END OF FILE")!=0)infile.getline(number,20);new_rec_ptr->pData->SetNum(number);infile>>year;infile.get(pause);infile>>month;infile.get(pause);infile>>day;infile.get(pause);infile>>hour;infile.get(pause);infile>>minute;infile.get(pause);infile>>seco
13、nd;infile.get(pause);new_rec_ptr->pData->SetTime(year,month,day,hour,minute,second);Insert(new_rec_ptr);else/讀到文件尾delete new_rec_ptr;end_loop=1;else/如果結(jié)點(diǎn)分配空家出錯(cuò)cout<<"WARNING:Memory error.Load from disk wan unsuccessful.n"end_loop=1;while(end_loop=0);infile.close();else/如果打開文件出錯(cuò)
14、cout<<"No usable data file located.List is empty.n"(2)將數(shù)據(jù)寫入鏈表void CList:write_list_to_file()/將鏈表寫入文件ofstream outfile;outfile.open("FRIENDS.DAT",ios:out); /打開文件if(outfile)/打開正確current_ptr=head_ptr;if(head_ptr!=NULL)/鏈表不為空,循環(huán)寫入dooutfile<<current_ptr->pData->GetNam
15、e()<<endl; outfile<<current_ptr->pData->GetLast()<<endl;outfile<<current_ptr->pData->GetNum()<<endl;outfile<<current_ptr->pData->GetYear()<<endl;outfile<<current_ptr->pData->GetMonth()<<endl;outfile<<current_ptr->
16、pData->GetDay()<<endl;outfile<<current_ptr->pData->GetHour()<<endl;outfile<<current_ptr->pData->GetMinute()<<endl;outfile<<current_ptr->pData->GetSecond()<<endl;current_ptr=current_ptr->pNext;while(current_ptr!=NULL);outfile<<&q
17、uot;END OF FILE"<<endl;outfile.close();else/打開文件出錯(cuò)cout<<"Error opening file!n"4課程設(shè)計(jì)要求的實(shí)現(xiàn)(1)記錄修改函數(shù)實(shí)現(xiàn)void CList:ModNum(void)/修改號(hào)碼 system("cls"); char search_string20,new_phone_number20; current_ptr=head_ptr; cin.ignore(20,'n'); cout<<"nEnter the
18、First name for which you want to change his or her phonenumber:" cin.get(search_string,20);/需要修改的姓氏 cin.ignore(20,'n');while(current_ptr!=NULL)&&(current_ptr->pData->Compare(search_string)!=0) current_ptr=current_ptr->pNext; if(current_ptr!=NULL)/如果找到匹配的結(jié)點(diǎn),輸出結(jié)點(diǎn)信息 cout&l
19、t;<"nRECORD FOUNDn" current_ptr->ShowNode(); cout<<"Enter New Phonenumber:"cin.get(new_phone_number,20);cin.ignore(20,'n');current_ptr->pData->Modify(new_phone_number); else/查找萬整個(gè)鏈表,未查到匹配的結(jié)點(diǎn) cout<<"NO MATCH FOUNDn" cout<<"Press
20、 Enter Continuen"cin.get(pause); system("cls"); (2)記錄錄入信息時(shí)間void CTelRecord:SetRecord(char *name,char *last,char *number)/調(diào)用系統(tǒng)時(shí)間strcpy(szName,name);strcpy(Last,last);strcpy(szNumber,number);struct tm *times; /定義時(shí)間指針變量.(只能用指針) time_t t; /定義系統(tǒng)時(shí)間變量,供提供系統(tǒng)時(shí)間 t = time(0); /當(dāng)前系統(tǒng)時(shí)間給變量t times =
21、 localtime(&t); /把系統(tǒng)時(shí)間變量強(qiáng)制轉(zhuǎn)換成tm結(jié)構(gòu)體形式時(shí)間 nYear=(times->tm_year+1900); nMonth=times->tm_mon; nDay=times->tm_mday; nHour=times->tm_hour; nMinute=times->tm_min;nSecond=times->tm_sec;(3)首字母查詢功能void CList:SearchFriends(void) system("cls"); char FirstWords20,name20;int length,k=0; current_ptr=head_ptr; cin.ignore(20,'n'); cout<<"nEnter the first words to found several similar Friends:" cin.get(FirstWords,20); cin.ignore(20,'n'); length=strlen(FirstWords); while(current_ptr!=NULL) strcpy(name,current_ptr->pData->GetName(); namelen
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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ǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)戰(zhàn)略的動(dòng)態(tài)評估機(jī)制試題及答案
- 人工智能倫理問題與解決方法試題及答案
- 2024年云南省退役軍人廳下屬事業(yè)單位真題
- 關(guān)注行業(yè)動(dòng)態(tài)把握發(fā)展機(jī)遇計(jì)劃
- 2024年深圳開放大學(xué)輔導(dǎo)員考試真題
- 促進(jìn)創(chuàng)新的年度工作計(jì)劃設(shè)計(jì)
- 公司戰(zhàn)略目標(biāo)導(dǎo)向試題及答案
- 2024年青海省農(nóng)業(yè)農(nóng)村廳下屬事業(yè)單位真題
- 客戶價(jià)值創(chuàng)造的實(shí)踐與總結(jié)計(jì)劃
- 2024年興業(yè)銀行天津分行招聘筆試真題
- 大班科學(xué)《神奇的中草藥》課件
- VMWare VSAN軟件定義的超融合解決方案
- “小風(fēng)箏大創(chuàng)意”小學(xué)STEM項(xiàng)目式學(xué)習(xí)活動(dòng)案例
- 生態(tài)環(huán)境執(zhí)法大練兵練習(xí)(行政處罰法、新固廢法、大氣法)
- 現(xiàn)澆箱梁混凝土澆筑方案計(jì)劃
- 青霉素皮試液的配制PPT學(xué)習(xí)教案
- 熱菜加工流程圖
- RAL 勞爾色卡電子版
- 《加油站安全管理人員安全生產(chǎn)目標(biāo)責(zé)任書》
- 第三章:船舶主機(jī)安裝工藝
- 計(jì)件工薪酬制度
評論
0/150
提交評論