C++實踐之計算圓周長、圓面積、球體積、球面積、圓柱體積

0x00題目

設圓半徑r=1.5,圓柱高h=3,求圓周長、圓面積、圓球體積、圓球面積、圓柱體積

用cin輸入數據,取小數點後兩位數字.

0x01代碼

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
    cout<<"輸入圓半徑與圓柱高,空格隔開"<<endl;
    double r,h;
    cin >> r >> h;
    void caculate(double r,double h);
    caculate(r,h);
    system("pause");
}
/**
 * 計算圓周長、圓面積、圓球表面積、圓球體積、圓柱體積
 * */
void caculate(double r,double h){
    const double PI = atan(1.)*4.; //定義圓周率
    double yuanD = PI*2*r;            
    double yuanS = PI*r*r;
    double ballS = 4*PI*r*r;
    double balla = 4,ballb = 3;
    double ballV = ((balla/ballb))*PI*r*r*r;
    double zhuV = PI*r*r*h;
    cout << "圓周長:" << setprecision(3) << yuanD << endl;
    cout << "圓面積:" << setprecision(3) << yuanS << endl;
    cout << "圓球表面積:" << setprecision(4) << ballS << endl;
    cout << "圓球體積:" << setprecision(4) << ballV << endl;
    cout << "圓柱體積:" << setprecision(4) << zhuV << endl;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章