description
定義乙個類data,只有乙個int型別的屬性和如下方法:input預設建構函式,將屬性初始化為0,並輸出"data』s default constructor."。
帶參建構函式,將屬性初始化為指定引數,並輸出"data # is created.",其中「#」即引數值。
析構函式,輸出:「data # is erased.」,其中「#」是屬性值。
int getvalue()——獲得屬性值。
void setvalue(int)——設定屬性值。
定義乙個由data的物件組成的陣列類dataarray,包括:
由10個data類的物件組成的物件陣列。
預設建構函式——不做任何操作,僅輸出一行"dataarray』s default constructor."。
void setvalues(int d[10])——設定10個data的物件的屬性值分別為引數d的10個值。
int getsum()——求10個data物件屬性值的和。
析構函式——輸出一行"dataarray』s deconstructor."。
輸入為11個int型別範圍內的整數。output
見樣例~~~sample input
123
4567
8910100
sample output
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
data's default constructor.
dataarray's default constructor.
sum is 55
data 100 is created.
adata =
100data 100 is erased.
dataarray's deconstructor.
data 10 is erased.
data 9 is erased.
data 8 is erased.
data 7 is erased.
data 6 is erased.
data 5 is erased.
data 4 is erased.
data 3 is erased.
data 2 is erased.
data 1 is erased.
int
main()
dataarray.
setvalues
(data)
; cout<<
"sum is "
>tmp;
adata =
newdata
(tmp)
; cout<<
"adata = "
<>
getvalue()
return0;
}
ac**
#include
#include
using
namespace std;
class
data
data
(int d)
:day
(d)~
data()
intgetvalue()
void
setvalue
(int v)};
class
dataarray
void
setvalues
(int d[10]
)}intgetsum()
return sum;}~
dataarray()
};intmain()
dataarray.
setvalues
(data)
; cout<<
"sum is "
>tmp;
adata =
newdata
(tmp)
; cout<<
"adata = "
<>
getvalue()
return0;
}
Problem A 類的初體驗
home web board problemset standing status statistics time limit 1 sec memory limit 128 mb submit 723 solved 661 submit status web board 定義乙個類data,只有乙個...
Problem A 類的初體驗
定義乙個類data,只有乙個double型別的屬性和如下3個方法 1.void init double d 初始化屬性值。2.double getvalue 獲得屬性值。3.void showvalue 顯示屬性值。乙個double型別的數值。輸出輸入的值2次,每次佔一行。3.14 3.143.14...
Problem B 類的初體驗(II)
定義乙個類data,只有乙個double型別的屬性和如下3個方法 1.帶1個引數的建構函式 初始化屬性值為引數值。2.double getvalue 獲得屬性值。3.void showvalue 顯示屬性值。乙個double型別的數值。輸出輸入的值2次,每次佔一行。3.14 3.143.14 inc...