




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quá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<<"輸入計算機成績:"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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 學(xué)生欺凌和暴力行為分析工作流程
- 【真題】人教版三年級下冊期末自測評價數(shù)學(xué)試卷(含解析)2024-2025學(xué)年北京市東城區(qū)第一六六中學(xué)
- 部編版九年級歷史班級復(fù)習(xí)督促計劃
- 特殊教育中數(shù)學(xué)核心素養(yǎng)培育心得體會
- 2025年初中物理實驗室工作總結(jié)范文
- 鋼結(jié)構(gòu)施工樣板計劃
- 二年級培優(yōu)輔差科技輔導(dǎo)計劃
- 特殊教育班主任教學(xué)心得體會范文
- 以實踐為翼:高中物理教學(xué)中STS教育的深度融合與拓展
- 以威利斯模式賦能職高英語閱讀教學(xué):理論、實踐與創(chuàng)新
- 第11課《山地回憶》公開課一等獎創(chuàng)新教學(xué)設(shè)計
- DB11-T 1448-2017 城市軌道交通工程資料管理規(guī)程
- 浙江省2024年中考英語真題
- 兒科護理學(xué)小兒液體療法
- 百科知識競賽題庫(500題及答案)
- 網(wǎng)絡(luò)信息安全的職業(yè)道德與行為規(guī)范
- 痹癥中醫(yī)護理方案
- 手術(shù)室十大核心制度
- 電子物料(電感、電容、芯片、PCB)的來料檢驗項及檢驗方法SIP
- 刑法學(xué)(總論)輔導(dǎo)教案
- 非遺資源數(shù)據(jù)庫建設(shè)
評論
0/150
提交評論