




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、名稱編程題2_數(shù)據(jù)及教師學生類備注描述題目描述:有五個類,各類的主要數(shù)據(jù)成員見下方說明,請自己定義合理的成員函數(shù),編程實現(xiàn)體現(xiàn)該繼承 關系的程序,并定義教師對象、學生對象、研究生對象、在職研究生對象,輸出他們的信息。關于數(shù)據(jù)成員:數(shù)據(jù)類Data :成員name 保存姓名;/該類是Teacher類和Student類的基類教師類Teacher :增加成員sal保存工資;學生類Student :增加成員id保存學號; 該類是PostGrad 類的基類研究生類PostGrad :增加成員dn保存系別;教師中的在職研究生類 Tpost :不另外定義數(shù)據(jù)成員。該類有兩個直接基類:Teacher類和研 究生
2、類PostGrad關于成員函數(shù):每個類中均定義輸出所有數(shù)據(jù)成員的函數(shù)void print ()。具體代碼可參考主函數(shù)及對應的輸出結果樣例來完成。主函數(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)最前面需要作相應的文件包含(2)請注意類之間的繼承關系,可能存在虛基類在保存并預覽之后,點 開:“測試用例”選項 卡,再選擇卜方的“添 加”,加入兩組測試測試用例,無輸入部分: 輸出部分: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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度中小企業(yè)貸款擔保合作協(xié)議
- 獨家合同:兩個單位聯(lián)合體投標協(xié)議
- 環(huán)境樣本中微生物的檢驗試題及答案
- 注冊會計師備考方法分享試題及答案
- 醫(yī)院保安工作總結計劃
- 開展社團特色活動的思路計劃
- 增強品牌知名度的戰(zhàn)略規(guī)劃計劃
- 新型微生物檢測方法的研究進展試題及答案
- 2025年注冊會計師考試成功之路反思試題及答案
- 2025年證券從業(yè)資格證重要考點清理試題及答案
- JJF 1319-2011傅立葉變換紅外光譜儀校準規(guī)范
- GB 26851-2011火災聲和/或光警報器
- 司法鑒定人執(zhí)業(yè)能力評估業(yè)務理論知識考試題庫
- 短語動詞課件
- 警犬行為理論考試題庫(含答案)
- 《羅密歐與朱麗葉》劇本
- 7694E頂空進樣器簡易操作手冊
- 河流納污能力計算
- 鉆井液防塌機理與措施-第六組
- 停車場應急預案
- 研究生在讀證明.docx
評論
0/150
提交評論