物件導向 練習 十一

2021-08-25 11:06:40 字數 1102 閱讀 7653

學生類:

* 成員變數:

* name,age

* 構造方法:

* 無參,帶兩個參

* 成員方法:

* get***()/set***()

* show():輸出該類的所有成員變數值

* b:給成員變數賦值:

* a:set***()方法

* b:構造方法

* c:輸出成員變數值的方式:

* a:通過get***()分別獲取然後拼接

* b:通過呼叫show()方法搞定

class demo4_student 

}class student //空參構造

public student(string name,int age)

public void setname(string name)

public string getname()

public void setage(int age)

public int getage()

public void show()

}

get***()與show的區別:

get***()獲取屬性值,可以列印,也可以賦值給其他的變數,做其他的操作.

show//只是為了顯示屬性值.

手機類:

成員變數:

品牌brand,**price

構造方法

無參,有參

成員方法

set***和get***

show

class demo5_phone 

}class phone //空參構造

public phone(string brand,int price)

public void setbrand(string brand)

public string getbrand()

public void setprice(int price)

public int getprice()

public void show()

}

物件導向練習

定義boat和car兩個類,兩者都有私有成員weight屬性,定義兩者的乙個友員函式totalweight 計算兩個類的物件的重量和。請根據給定的main函式和totalweight 函式的定義,完善boat和car兩個類。友元函式的使用 include using namespace std cl...

物件導向練習

include hero.class.php hero new hero 張三 建立英雄 hero daguai hero show hero daguai hero show hero daguai hero show hero daguai hero show hero daguai hero ...

物件導向程式設計上機練習十一(運算子過載)

time limit 1000ms memory limit 65536kb submit statistic problem description 有兩個矩陣a和b,均為2行3列,求兩個矩陣之和。過載運算子 使之能用於矩陣相加。如 c a b。input 第1 2行是矩陣a的值,資料以空格分開。...