編程題2_數(shù)據(jù)和教師學(xué)生類_第1頁
編程題2_數(shù)據(jù)和教師學(xué)生類_第2頁
編程題2_數(shù)據(jù)和教師學(xué)生類_第3頁
編程題2_數(shù)據(jù)和教師學(xué)生類_第4頁
編程題2_數(shù)據(jù)和教師學(xué)生類_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、名稱編程題2_數(shù)據(jù)及教師學(xué)生類備注描述題目描述:有五個(gè)類,各類的主要數(shù)據(jù)成員見下方說明,請自己定義合理的成員函數(shù),編程實(shí)現(xiàn)體現(xiàn)該繼承 關(guān)系的程序,并定義教師對象、學(xué)生對象、研究生對象、在職研究生對象,輸出他們的信息。關(guān)于數(shù)據(jù)成員:數(shù)據(jù)類Data :成員name 保存姓名;/該類是Teacher類和Student類的基類教師類Teacher :增加成員sal保存工資;學(xué)生類Student :增加成員id保存學(xué)號(hào); 該類是PostGrad 類的基類研究生類PostGrad :增加成員dn保存系別;教師中的在職研究生類 Tpost :不另外定義數(shù)據(jù)成員。該類有兩個(gè)直接基類:Teacher類和研 究生

2、類PostGrad關(guān)于成員函數(shù):每個(gè)類中均定義輸出所有數(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ù)覽之后,點(diǎn) 開:“測試用例”選項(xiàng) 卡,再選擇卜方的“添 加”,加入兩組測試測試用例,無輸入部分: 輸出部分: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)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論