rwkj 1354 圓周長與面積

來源:互聯網
上載者:User

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

C++:類與對象2(圓的周長和面積)
時間限制(普通/Java):1000MS/3000MS 運行記憶體限制:65536KByte
總提交:1038 測試通過:524

描述


使用類編寫程式,輸入以後圓的半徑,計算並顯示圓的周長和面積。圓周率取:3.14


輸入

輸入包含n組測試例, 第1行是測試組數。

第2行--第n+1行為測試資料,每組測資料有1個實數,表示圓的半徑。


輸出

圓的周長和面積(保留2位小數)。

範例輸入

3
4.5
14.6
5.5

範例輸出

28.26 63.59
91.69 669.32
34.54 94.98

 

 

 


#include <iostream.h>
#include<iomanip.h>
class circle
{
double r;

public:
circle(double x)
{r=x;}

void disp()
{
cout<<fixed<<setprecision(2);
cout<<3.14*r*2<<" "<<3.14*r*r<<endl;
}
};


int main(int argc, char *argv[])
{
int n;
double r;

cin>> n;

while (n--)
{
cin>>r;
circle c(r);
c.disp();
}
}

 

*****************************************************8

 


#include <iostream.h>
#include<iomanip.h>
class circle
{
double r,c,s;

public:
circle(double x)
{r=x;c=3.14*r*2;s=3.14*r*r;}

void disp()
{
cout<<fixed<<setprecision(2);
cout<<c<<" "<<s<<endl;
}
};


int main(int argc, char *argv[])
{
int n;
double r;

cin>> n;

while (n--)
{
cin>>r;
circle c(r);
c.disp();
}
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.