




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、名稱編程題2_數(shù)據(jù)及教師學(xué)生類備注描述題目描述:有五個類,各類的主要數(shù)據(jù)成員見下方說明,請自己定義合理的成員函數(shù),編程實現(xiàn)體現(xiàn)該繼承 關(guān)系的程序,并定義教師對象、學(xué)生對象、研究生對象、在職研究生對象,輸出他們的信息。關(guān)于數(shù)據(jù)成員:數(shù)據(jù)類Data :成員name 保存姓名;/該類是Teacher類和Student類的基類教師類Teacher :增加成員sal保存工資;學(xué)生類Student :增加成員id保存學(xué)號; 該類是PostGrad 類的基類研究生類PostGrad :增加成員dn保存系別;教師中的在職研究生類 Tpost :不另外定義數(shù)據(jù)成員。該類有兩個直接基類:Teacher類和研 究生
2、類PostGrad關(guān)于成員函數(shù):每個類中均定義輸出所有數(shù)據(jù)成員的函數(shù)void print ()。具體代碼可參考主函數(shù)及對應(yīng)的輸出結(jié)果樣例來完成。主函數(shù)代碼如下:int main ()Teacher tobj("Zhuhong”, 2000);Student sobj("Wanghui", "B05030417");PostGrad pobj("Lixuefeng", "Yj040217", "Computer Department");Tposttpobj("Liuling&
3、quot;, "Yz040318", "Society Department", 800);cout << "the teacher:n"tobj.print ();cout << "nthe student:n"sobj.print ();cout << "nthe postgraduate:n"pobj.print ();cout << "nthe teacher and postgraduate:n"tpobj.print
4、 ();return 0;提示:(1)最前面需要作相應(yīng)的文件包含(2)請注意類之間的繼承關(guān)系,可能存在虛基類在保存并預(yù)覽之后,點 開:“測試用例”選項 卡,再選擇卜方的“添 加”,加入兩組測試測試用例,無輸入部分: 輸出部分:the teacher: Name:Zhuhong sal=2000the student: Name:Wanghuiid=B05030417the postgraduate: Name:Lixuefeng id=Yj040217 dn=Computer Departmentthe teacher and postgraduate: Name:Liuling sal=80
5、0id=Yz040318dn=Society Department參考源程序代碼#include <iostream>#include <string> using namespace std; class Data public: Data(char *na) name = new charstrlen(na)+1; strcpy(name, na);Data() delete name;參考源代碼僅供老師參考 加到系統(tǒng)中,不要添void print()cout << "Name:" << name << end
6、l;protected:char *name;;class Student: virtual public Datapublic:Student(char *na, char *pid): Data(na) id = new charstrlen(pid)+1; strcpy(id, pid);Student()delete id;void print()Data二print();cout << "id=" << id << endl;protected:char *id;;class Teacher: virtual public Da
7、tapublic:Teacher(char *na, float psal): Data(na)sal = psal;void print()Data二print();cout << "sal=" << sal << endl;protected:float sal;class Postgrad: public Studentprotected:char *dn;public:Postgrad(char *na, char *pid, char *p): Data(na), Student(na, pid) dn = new charst
8、rlen(p)+1;strcpy(dn, p);Postgrad()delete dn;void print()Student:print();cout << "dn=" << dn << endl;;class Tpost: public Teacher, public Postgradpublic:Tpost(char *na, char *pid, char *p, float psal): Data(na), Teacher(na, psal), Postgrad(na,pid,p);void print()Teacher二pri
9、nt();cout << "id=" << id << endl;cout << "dn=" << dn << endl;int main()Teacher tobj("Zhuhong”, 2000);Student sobj("Wanghui", "B05030417");Postgrad pobj("Lixuefeng", "Yj040217", "Computer Departm
10、ent");Tpost tpobj("Liuling", "Yz040318", "Society Department", 800); cout << "the teacher:n"tobj.print();cout << "nthe student:n"sobj.print();cout << "nthe postgraduate:n"pobj.print();cout << "nthe teacher and postgraduate:n"tpobj.print();return
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 鋰電池回收拆解再生利用項目初步設(shè)計(參考)
- 垃圾發(fā)電廠爐渣擴(kuò)建項目初步設(shè)計(僅供參考)
- 河道生態(tài)修復(fù)工程實施方案(范文)
- 貴重金屬循環(huán)利用項目實施方案(范文參考)
- 共享單車電子圍欄實施方案
- 安全教育專題分享
- 蘇教版剪枝的學(xué)問課件設(shè)計
- 浙江省寧波市五校聯(lián)盟2023-2024學(xué)年高一上學(xué)期期中聯(lián)考語文 含解析
- 廣東省清遠(yuǎn)市四校聯(lián)盟2023-2024學(xué)年高二上學(xué)期期中聯(lián)考物理含解析
- 南昌醫(yī)學(xué)院《行政組織學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 機(jī)械制造及其自動化專業(yè)畢業(yè)設(shè)計(1)解讀
- 網(wǎng)紅文化傳媒有限公司制度
- 4.2依法履行義務(wù) 說課課件(共19張PPT)
- 老年血液透析患者特點和安全性評估方案
- a10c疣豬飛行控制器中文說明書
- 發(fā)貨裝箱單Detail Packing list
- 食品衛(wèi)生微生物學(xué)檢驗阪崎腸桿菌
- 專業(yè)分包招標(biāo)文件范本
- 換熱站驗收方案
- (完整word版)樁位偏差驗收記錄表
- 重介質(zhì)旋流器單機(jī)檢查
評論
0/150
提交評論