




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、名稱編程題2_數(shù)據(jù)及教師學生類備注描述題目描述:有五個類,各類的主要數(shù)據(jù)成員見下方說明,請自己定義合理的成員函數(shù),編程實現(xiàn)體現(xiàn)該繼承 關(guān)系的程序,并定義教師對象、學生對象、研究生對象、在職研究生對象,輸出他們的信息。關(guān)于數(shù)據(jù)成員:數(shù)據(jù)類Data :成員name 保存姓名;/該類是Teacher類和Student類的基類教師類Teacher :增加成員sal保存工資;學生類Student :增加成員id保存學號; 該類是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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 新教材大象版五年級上冊科學實驗教學計劃
- 小學體育教師學科交叉成長計劃
- 化工分析實驗室改進計劃
- 2025年公務(wù)員考試時事政治模擬試題【考點精練】附答案詳解
- 2025年公務(wù)員考試時事政治模擬考試試卷【培優(yōu)b卷】附答案詳解
- 學校跳棋興趣培養(yǎng)計劃
- 潮汐能發(fā)電站圍堰施工安全監(jiān)管合作協(xié)議
- 科技園區(qū)創(chuàng)新企業(yè)店面租賃及技術(shù)創(chuàng)新合同
- 綠色能源廠房商鋪租賃合同范本
- 成都寫字樓物業(yè)管理與服務(wù)合同范本
- 貴州大方富民村鎮(zhèn)銀行股份有限公司(籌)招聘上岸提分題庫3套【500題帶答案含詳解】
- GB/T 5470-2008塑料沖擊法脆化溫度的測定
- GB/T 40998-2021變性淀粉中羥丙基含量的測定分光光度法
- GB/T 31848-2015汽車貼膜玻璃貼膜要求
- 圖書管理系統(tǒng)畢業(yè)論文參考文獻精選,參考文獻
- 中國當代舊體詩選讀幻燈片
- 吉林省全省市縣鄉(xiāng)鎮(zhèn)衛(wèi)生院街道社區(qū)衛(wèi)生服務(wù)中心基本公共衛(wèi)生服務(wù)醫(yī)療機構(gòu)信息名單目錄995家
- 倔強的小紅軍-精講版課件
- 信息隱藏與數(shù)字水印課件(全)全書教學教程完整版電子教案最全幻燈片
- 公開招聘社區(qū)居委專職工作人員考試筆試、面試題集及相關(guān)知識(11套試題含答案)
- 中職數(shù)學基礎(chǔ)模塊下冊《等差數(shù)列》ppt說課稿
評論
0/150
提交評論