第十二周上機實踐專案(1)

2021-07-22 05:37:07 字數 1405 閱讀 6024

/*

*檔名稱:text11.cpp

*問題描述:分別定義teacher(教師)類和cadre(幹部)類,採用多重

*繼承方式由這兩個類派生出新類teacher_cadre(教師兼幹部)。(1)在兩個基類中都包含姓名、年齡、性別、位址、**等資料成員。 

(2)在teacher類中還包含資料成員title(職稱),在cadre類中還包含資料成員post(職務),在teacher_cadre類中還包含資料成員wages(工資)。 

(3)對兩個基類中的姓名、年齡、性別、位址、**等資料成員用相同的名字,在引用這些資料成員時,指定作用域。 

(4)在類體中宣告成員函式,在類外定義成員函式。 

(5)在派生類teacher_cadre的成員函式show中呼叫teacher類中的display函式,輸出姓名、年齡、性別、職稱、位址、**,然後再用cout語句輸出職務與工資。

*/#include 

using

namespace

std;  

class

teacher  

void

show();  

protected

:  string name;  

intage;  

char

***;  

string adress;  

string number;  

string title;  

};  

void

teacher::show()  

class

cadre  

void

show();  

protected

:  string name;  

intage;  

char

***;  

string adress;  

string number;  

string post;  

};  

void

cadre::show()  

;  class

teacher_cadre:

public

teacher,

public

cadre  

;  teacher_cadre::teacher_cadre(string nam,int

a,char

s,string t,string p,string ad,string tel,

float

w):  

teacher(nam,a,s,t,ad,tel),cadre(nam,a,s,p,ad,tel),wage(w) {}  

void

teacher_cadre::show( )  

intmain( )  

第十二周上機任務1

include include using namespace std class student 1 修改student類中各資料成員和成員函式的訪問限定符,並觀察發生的現象 protected int num string name char class student1 public stud...

c 第十二周上機實踐作業 專案 1 2

檔名稱 test.cpp 版本 v6.0 問題描述 1 請用類的友元函式,而不是成員函式,再次完成上面提及的運算子的過載 class complex complex double r,double i complex operator const complex c2 complex operato...

c 第十二周上機實踐作業 專案 4

檔名稱 test.cpp 版本 v6.0 專案 string類的構造 寫乙個能處理字串的類,其資料成員如下所示 cpp view plain copy print class string 請構造string類的加 減運算。其中,s1 s2將兩個字串的連線起來 s1 s2是將s1的尾部空格和s2的前...