




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、#include<iostream> #include<string> #include<iomanip> #include<fstream> using namespace std; class CData public: CData(); virtual int comparename(CData &) =0; virtual void show()=0; virtual CData(); ; class CNode public: CNode()pdata=0;pnext=0; CNode(CNode &n); void i
2、nputdata(CData *pd)pdata=pd; void shownode()pdata->show(); CData *getdata()return pdata; friend class CList; private: CData *pdata; CNode *pnext; ; CNode:CNode(CNode &n) pdata=n.pdata; pnext=n.pnext; class CList public: CList()phead=0; CList()deletelist(); void addnode(CNode *pnode); void del
3、etelist(); CNode *deletenode(CNode *pnode); CNode *lookup(CData &data); CNode *getlisthead()return phead; void showlist(); CNode *getnext(CNode *pnode); private: CNode * phead; ; void CList:addnode(CNode *pnode) if(phead=0) phead=pnode; pnode->pnext=0; return; else pnode->pnext=phead; phea
4、d=pnode; void CList:deletelist() CNode *p1,*p2; p1=phead; while(p1) delete p1->pdata; p2=p1; p1=p1->pnext; delete p2; CNode *CList:deletenode(CNode *pnode) CNode *p1,*p2; p1=phead; while(p1!=pnode&&p1->pnext!=0) p2=p1; p1=p1->pnext; if(p1=phead) phead=phead->pnext; return pnod
5、e; p2->pnext=p1->pnext; return pnode; CNode *CList:lookup(CData &data) CNode *p1=phead; while(p1) if(p1->pdata->comparename(data)=0) return p1; p1=p1->pnext; return 0; void CList:showlist() if(phead=0) cout<<"對不起,沒有任何記錄.n" else CNode *p=phead; while(p) p->pdata-
6、>show(); p=p->pnext; CNode *CList:getnext(CNode *pnode) CNode *p=pnode; p=p->pnext; return p; class Student:public CData private: char s_class17; char s_num17; char s_name17; double ele_technique; double c_program; double mul_technique; double col_english; double sen_math; double col_gym; d
7、ouble marx_economy; double average; public: Student(); virtual int comparename(CData &); void show(); void set(char *c,char*n,char *nam,double e,double cp, double m,double ce,double sm,double cg,double mar,double aver); ; Student:Student() strcpy(s_class,"0"); strcpy(s_num,"0"
8、;); strcpy(s_name,"0"); ele_technique=0; c_program=0; mul_technique=0; col_english=0; sen_math=0; col_gym=0; marx_economy=0; int Student:comparename(CData &data) Student &temp=(Student &)data; return strcmp(s_name,temp.s_name); void Student:show() cout<<setw(7)<<s_c
9、lass<<setw(12)<<s_num<<setw(12)<<s_name; cout<<setw(6)<<ele_technique<<setw(6)<<c_program<<setw(6)<<mul_technique; cout<<setw(6)<<col_english<<setw(6)<<sen_math<<setw(6)<<col_gym; cout<<setw(6)<&
10、lt;marx_economy<<" "<<setw(3)<<average<<endl; void Student:set(char *c,char*n,char *nam,double e,double cp,double m,double ce,double sm,double cg,double mar,double aver) strcpy(s_class,c); strcpy(s_num,n); strcpy(s_name,nam); ele_technique=e; c_program=cp; mul_techn
11、ique=m; col_english=ce; sen_math=sm; col_gym=cg; marx_economy=mar; average=aver; void print() cout<<setw(7)<<"class"<<setw(12)<<"number"<<setw(12)<<"name" cout<<setw(6)<<"ele"<<setw(6)<<"C+"
12、<<setw(6)<<"media" cout<<setw(6)<<"eng"<<setw(6)<<"math"<<setw(6)<<"gym" cout<<setw(6)<<"marx"<<setw(6)<<"aver"<<endl; void display(CList &stulist) print(); s
13、tulist.showlist(); cout<<endl; cout<<"按任意鍵返回主菜單" getchar();getchar(); void add(CList &stulist) CNode *p; Student *s; char c17,n17,nam17; double e,cp,m,ce,sm,cg,mar;float aver; cout<<"請輸入姓名(輸入0結(jié)束):" cin.ignore(); cin.getline(nam,17); while(strcmp(nam,"0&
14、quot;) cout<<"輸入學(xué)號:"cin.getline(n,17); cout<<"輸入班級:"cin.getline(c,17); cout<<"輸入計算機(jī)成績:"cin>>e; cout<<"輸入大學(xué)英語成績:"cin>>ce; cout<<"輸入高等數(shù)學(xué)成績:"cin>>sm; aver=(e+cp+m+ce+sm)*0.8/5+cg*0.15+mar*0.05); s=new Stud
15、ent; s->set(c,n,nam,e,cp,m,ce,sm,cg,mar,aver); p=new CNode; p->inputdata(s); stulist.addnode(p); cout<<"記錄添加成功."<<endl; cout<<"請輸入姓名(輸入0結(jié)束):" cin.ignore(); cin.getline(nam,17); void lookup(CList &stulist) CNode *plook; char name17; cout<<"請輸
16、入你要查找的姓名(輸入0結(jié)束):" cin.ignore(); cin.getline(name,17); while(strcmp(name,"0") Student s; s.set("0","0",name,0,0,0,0,0,0,0,0); plook=stulist.lookup(s); if(plook) print(); plook->shownode(); else cout<<"對不起,在學(xué)生記錄中查找不到"<<name<<"的記錄.&
17、quot;<<endl; cout<<"請輸入你要查找的姓名(輸入0結(jié)束):" cin.getline(name,17); void deletes(CList &stulist) CNode *plook; char name17; cout<<"請輸入要刪除的記錄的學(xué)生姓名(輸入0結(jié)束):" cin.ignore(); cin.getline(name,17); while(strcmp(name,"0") Student s; s.set("0","0&q
18、uot;,name,0,0,0,0,0,0,0,0); plook=stulist.lookup(s); if(plook) print(); plook->shownode(); stulist.deletenode(plook); cout<<name<<"的記錄已經(jīng)刪除.n" else cout<<"對不起,在學(xué)生記錄中查找不到"<<name<<"的記錄.n"<<endl; cout<<"請輸入要刪除的記錄的學(xué)生姓名(輸入0結(jié)束)
19、:" cin.getline(name,17); void storefile(CList &stulist) ofstream outfile("student.dat",ios:binary); if(!outfile) cout<<"數(shù)據(jù)文件打開錯誤,數(shù)據(jù)存入文件失敗!"<<endl; return; CNode *p; Student *s; p=stulist.getlisthead(); while(p) s=(Student *)p->getdata(); outfile.write(char
20、 *)s,sizeof(Student); p=stulist.getnext(p); outfile.close(); void loadfile(CList &stulist) ifstream infile("student.dat",ios:binary); if(!infile) cout<<"沒有數(shù)據(jù)文件!"<<endl; return; CNode *p; Student *s; while(! infile.eof() s=new Student; infile.read(char *)s,sizeof(Student); p=new CNode; p->inputdata(s); stulist.addnode(p); stulist.deletenode(p); infile.close(); void operate(CList &stulist) int choice; do system("cls")
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 上海公安學(xué)院《書法與鑒賞》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣東松山職業(yè)技術(shù)學(xué)院《文化遺產(chǎn)創(chuàng)新創(chuàng)業(yè)》2023-2024學(xué)年第一學(xué)期期末試卷
- 河南科技大學(xué)《中國現(xiàn)當(dāng)代文學(xué)作品選》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣州鐵路職業(yè)技術(shù)學(xué)院《應(yīng)用時間序列》2023-2024學(xué)年第二學(xué)期期末試卷
- 天津生物工程職業(yè)技術(shù)學(xué)院《表面工程導(dǎo)論》2023-2024學(xué)年第二學(xué)期期末試卷
- 深圳大學(xué)《服務(wù)營銷》2023-2024學(xué)年第二學(xué)期期末試卷
- 日照市五蓮縣2025屆五下數(shù)學(xué)期末達(dá)標(biāo)檢測模擬試題含答案
- 山東圣翰財貿(mào)職業(yè)學(xué)院《建筑概論》2023-2024學(xué)年第一學(xué)期期末試卷
- 福建省泉州市泉外、東海、七中學(xué)、恒興四校2025年初三摸底聯(lián)考物理試題試卷含解析
- 浙江溫州十五校聯(lián)盟2025年高三下學(xué)期第一次月考(開學(xué)考試)歷史試題試卷含解析
- JJF(京) 124-2024 智能電表電動自行車充電辨識模組校準(zhǔn)規(guī)范
- 2024年河南水利廳廳屬事業(yè)單位招考(第二批)易考易錯模擬試題(共500題)試卷后附參考答案
- 2022風(fēng)電機(jī)組吊裝施工組織設(shè)計
- 一例下肢靜脈血栓疑難病例護(hù)理討論1
- 護(hù)士中級職稱競聘述職課件
- 教育部《中小學(xué)德育工作指南》-道德修養(yǎng)手冊
- 2023年度學(xué)校食堂食品從業(yè)人員考核試題(附答案)
- HIV感染產(chǎn)婦分娩母嬰阻斷演練腳本
- “企安安”動火作業(yè)報備操作指南
- DL∕T 794-2012 火力發(fā)電廠鍋爐化學(xué)清洗導(dǎo)則
- 馬克思主義原理一切從實(shí)際出發(fā)完整模板
評論
0/150
提交評論