數(shù)據(jù)庫設計作業(yè)_第1頁
數(shù)據(jù)庫設計作業(yè)_第2頁
數(shù)據(jù)庫設計作業(yè)_第3頁
數(shù)據(jù)庫設計作業(yè)_第4頁
數(shù)據(jù)庫設計作業(yè)_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、數(shù)據(jù)庫設計:班級通訊錄一班級通訊錄程序設計(C語言):#include<conio.h> #include<stdio.h> #include <iostream>#include <string>#include <iomanip>#include <fstream>#include <cstdlib>using namespace std;class bookpublic: book();/默認構造函數(shù) char inter_face();/首頁 void add_person();/添加聯(lián)系人 void

2、del_person();/刪除聯(lián)系人 void show_all();/顯示所有聯(lián)系人 void alter();/修改信息 void select();/查詢聯(lián)系人 void save_new();/保存新增加的聯(lián)系人private: string name;/姓名 string address;/地址 string number;/電話號碼 string post;/郵編 string qq;/QQ號;struct record book object;/雙向鏈表中的數(shù)據(jù)域是是一個記錄類 record *prior;/指向前軀 record *next;/指向后繼;book:book()

3、 name = "0" address = "0" number = "0" post = "0" qq = "0"/首頁char book:inter_face() system("cls"); cout <<endl; cout<<"tt" <<endl <<"tt " <<endl <<"tt 班 級 通 迅 錄 " <<end

4、l <<"tt " <<endl <<"tt 1. 添加新聯(lián)系人. 4. 修改信息. " <<endl <<"tt " <<endl <<"tt 2. 刪除聯(lián)系人. 5. 查詢聯(lián)系人. " <<endl <<"tt " <<endl <<"tt 3. 顯示所有聯(lián)系人. 6. 關閉通迅錄. " <<endl <<"

5、tt " <<endl <<"tt" <<endl <<endl <<"ttt選擇 :" ; char choose; cin >>choose; fflush(stdin); return choose;/添加聯(lián)系人void book:add_person() cout <<endl <<"根據(jù)下面提示輸入新聯(lián)系人信息" <<endl <<endl <<"姓名 :" ; c

6、in >>name; fflush(stdin); cout <<"電話 : " cin >>number; fflush(stdin); cout <<"QQ : " cin >>qq; fflush(stdin); cout <<"郵編 : " cin >>post; fflush(stdin); cout <<"地址 : " cin >>address; fflush(stdin); save_new(

7、); cout <<endl <<endl <<"新聯(lián)系人信息已經(jīng)保存好!" <<endl <<endl; system("pause");/刪除聯(lián)系人void book:del_person() ofstream outData("temp.txt", ios:out); ifstream inData("pbook.txt", ios:in); if (!outData | !inData) cout <<endl <<&quo

8、t;對不起!找不到文件!" <<endl; system("pause"); return; string sign; cout <<endl <<"你要刪除輸入姓名或電話號 :" cin >>sign; string str1; bool flag = true; string str; while (inData >>name >>number) getline(inData, str); if (sign=name) | (sign=number) cout <

9、<endl <<"你想刪除的聯(lián)系人:" <<endl <<endl; cout <<str1 <<endl; cout <<setiosflags(ios:left) <<setw(17) <<name <<" " <<number <<str <<endl; flag = false; break; outData <<setiosflags(ios:left) <<setw(17

10、) <<name <<" " <<number <<str <<endl; if (flag) cout <<endl <<"對不起!聯(lián)系人中沒你找的人!" <<endl <<endl; else while (getline(inData, str) outData <<str <<endl; outData.close(); inData.close(); ofstream out("pbook.txt&quo

11、t;, ios:out); ifstream in("temp.txt", ios:in); if (!out | !in) cout <<endl <<"對不起不能打開文件!" <<endl <<endl; system("pause"); return; while (getline(in, str) out <<str <<endl; out.close(); in.close(); cout <<endl <<"這個人的信

12、息已經(jīng)從你的通迅錄中刪除!" <<endl <<endl; system("pause"); /顯示所有聯(lián)系人void book:show_all() ifstream inData("pbook.txt",ios:in); if (!inData) cout <<endl <<"對不起!沒有找到文件!" <<endl; system("pause"); return; bool flag = true; string record; while

13、 (getline(inData, record) if (flag) cout <<endl <<"所有聯(lián)系人信息如下: "<<endl; cout <<record <<endl; flag = false; if (flag) cout <<endl <<"你的通迅錄中沒有聯(lián)系人!" <<endl <<endl; else cout <<endl <<"所有聯(lián)系人已經(jīng)全部顯示出來!" <<

14、;endl <<endl; system("pause");/修改信息void book:alter() ifstream inData("pbook.txt", ios:in); if (!inData) cout <<endl <<"對不起不能打開文件!" <<endl <<endl; system("pause"); return; string sign; cout <<endl <<"請輸入你想要修改的聯(lián)系人的姓

15、名或電話號碼 :" cin >>sign; fflush(stdin); string str1; getline(inData, str1); record *H = new record; record *p = H; record *q = H; bool flag = true; while (inData >>p-> >>p->object.number >>p->object.qq >>p->object.post >>p->object.addre

16、ss) p->next = new record; p = p->next; p->prior = q; q->next = p; q = p; p->next = NULL; inData.close(); p = H; while (p) if (p->=sign) | (p->object.number=sign) if (flag) cout <<endl <<"你想修改你聯(lián)系人的信息如下: " <<endl <<endl; cout <<en

17、dl <<str1 <<endl; cout <<setiosflags(ios:left) <<setw(17) <<p-> <<" " <<setw(16) <<p->object.number <<" " <<setw(18) <<p->object.qq <<" " <<setw(14) <<p->object.po

18、st <<" " <<setw(20) <<p->object.address <<endl; flag = false; cout <<endl <<"請根據(jù)下面提示修改信息 : " <<endl; cout <<"姓名 :" ; cin >>p->; fflush(stdin); cout <<"電話號:" cin >>p->object.n

19、umber; fflush(stdin); cout <<"QQ :" cin >>p->object.qq; fflush(stdin); cout <<"郵編 :" cin >>p->object.post; fflush(stdin); cout <<"地址 :" cin >>p->object.address; fflush(stdin); break; p = p->next; if (flag) cout <<end

20、l <<"你的通迅錄中沒有你找的聯(lián)系人!" <<endl <<endl; system("pause"); return; else ofstream out("pbook.txt",ios:out); if (!out) cout <<endl <<"對不起!不能打開文件!" <<endl; system("pause"); return; out <<str1 <<endl; p = H->

21、next; while (p) out <<setiosflags(ios:left) <<setw(17) <<p-> <<" " <<setw(16) <<p->object.number <<" " <<setw(18) <<p->object.qq <<" " <<setw(14) <<p->object.post <<&quo

22、t; " <<setw(20) <<p->object.address <<endl; p = p->next; out.close(); cout <<endl <<"信息已經(jīng)修改完成!" <<endl <<endl; system("pause"); /查詢聯(lián)系人void book:select() ifstream inData("pbook.txt",ios:in); if (!inData) cout <<e

23、ndl <<"對不起!文件找不到!" <<endl; system("pause"); return; string sign; cout <<endl <<"輸入你想查找的聯(lián)系人的姓名或電話號碼: " cin >>sign; fflush(stdin); string str1; bool flag = true; string str; while (inData >>name >>number) getline(inData, str); if

24、(name=sign) | (number=sign) cout <<endl <<"你要查找的聯(lián)系人是: " <<endl <<endl; cout <<str1 <<endl; cout <<setiosflags(ios:left) <<setw(17) <<name <<number <<str <<endl; flag = false; break; void book:save_new() ofstream outData("pbook.txt", ios:app); if (!outData) cout <<endl <<"對不起!打開文件失敗!" <<endl <<endl; system("pause"); return; outData << setiosflags(ios:left) << setw(17) << name <<" " << setw(16) <<

溫馨提示

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

評論

0/150

提交評論