rwkj 1357 矩形--面積-周長

來源:互聯網
上載者:User

標籤:java   os   io   資料   ar   時間   c++   ios   

C++:類與對象5(矩形的面積與周長)
時間限制(普通/Java):1000MS/3000MS 運行記憶體限制:65536KByte
總提交:349 測試通過:235

描述


定義並測試一個類名為rectangle的矩形類,資料成員為矩形的長和寬,定義2個成員函數分別計算矩形的面積與周長,要求定義建構函式和拷貝建構函式。


輸入


輸入資料第1行為一個整數T,表示有T組資料。每組資料1行,每行包括矩形的長和寬2個整數。


輸出

矩形的面積與周長。

範例輸入

2
3 5
4 10

範例輸出

15 16
40 28

 

 

 

 


#include<iostream>
using namespace std;
int main()
{
int t,b,a;
cin>>t;
while(cin>>a>>b)
cout<<a*b<<" "<<2*a+2*b<<endl;
return 0;
}

 

 


#include<iostream>
using namespace std;

class juxing
{
double x,y;
public:
void intx(double a,double b)
{x=a;y=b;}
void Area()
{cout<<x*y<<" ";}
void zhouchang()
{cout<<2*x+2*y<<endl;}
};
int main()
{ double a,b,j;
cin>>j;
while(j--)
{
cin>>a>>b;
juxing c;
c.intx(a,b);
c.Area();
c.zhouchang();
}
return 0;
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.