3 4 計算長方形的周長和面積

2021-06-25 22:49:20 字數 761 閱讀 3083

time limit: 1000ms memory limit: 65536k

通過本題的練習可以掌握拷貝建構函式的定義和使用方法;

設計乙個長方形類rect,計算長方形的周長與面積。類中有私有資料成員length(長)、width(寬),由具有預設引數值的建構函式對其初始化,函式原型為:rect(double length=0, double width=0); 再為其定義拷貝建構函式,形參為物件的常引用,函式原型為:rect(const rect &); 編寫主函式,建立rect物件r1初始化為長、寬資料,利用r1初始化另乙個rect物件r2,分別輸出物件的長和寬、周長和面積。

要求: 建立物件 rect r1(3.0,2.0),r2(r1);

輸入兩個實數,中間用乙個空格間隔;代表長方形的長和寬

共有6行;分別輸出r1

的長和寬;

r1的周長;

r1的面積;r2

的長和寬;

r2的周長;

r2的面積;注意單詞與單詞之間用乙個空格間隔

56 32

the length and width of r1 is:56,32

the perimeter of r1 is:176

the area of r1 is:1792

the length and width of r2 is:56,32

the perimeter of r2 is:176

the area of r2 is:1792

3 4 計算長方形的周長和面積

time limit 1000ms memory limit 65536k 通過本題的練習可以掌握拷貝建構函式的定義和使用方法 設計乙個長方形類rect,計算長方形的周長與面積。類中有私有資料成員length 長 width 寬 由具有預設引數值的建構函式對其初始化,函式原型為 rect doubl...

3 4 計算長方形的周長和面積

time limit 1000ms memory limit 65536kb submit statistic problem description 通過本題的練習可以掌握拷貝建構函式的定義和使用方法 設計乙個長方形類rect,計算長方形的周長與面積。類中有私有資料成員length 長 width...

3 4 計算長方形的周長和面積

time limit 1000ms memory limit 65536kb submit statistic problem description 通過本題的練習可以掌握拷貝建構函式的定義和使用方法 設計乙個長方形類rect,計算長方形的周長與面積。類中有私有資料成員length 長 width...