[C++] 三个方体的体积 →→→→→进入此内容的聊天室

来自 , 2021-02-02, 写在 C++, 查看 190 次.
URL http://www.code666.cn/view/c5a4e7e6
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Cubic{
  5.         private:
  6.                 double length,width,height;
  7.         public:
  8.                 void set_length(void){
  9.                         cout<<"Please enter the length of the cubic: ";
  10.                         cin>>length;
  11.                 }
  12.                 void set_width(void){
  13.                         cout<<"Please enter the width of the cubic: ";
  14.                         cin>>width;
  15.                 }
  16.                 void set_height(void){
  17.                         cout<<"Please enter the height of the cubic: ";
  18.                         cin>>height;
  19.                 }
  20.                 void get_volume(void){
  21.                         cout<<length*width*height<<endl;
  22.                 }
  23. };
  24.  
  25. int main(){
  26.         Cubic c1,c2,c3;
  27.         cout<<"First cubic:\n";
  28.         c1.set_length();
  29.         c1.set_width();
  30.         c1.set_height();
  31.         cout<<"Second cubic:\n";
  32.         c2.set_length();
  33.         c2.set_width();
  34.         c2.set_height();
  35.         cout<<"Third cubic:\n";
  36.         c3.set_length();
  37.         c3.set_width();
  38.         c3.set_height();
  39.         cout<<"The volume:\n";
  40.         c1.get_volume();
  41.         c2.get_volume();
  42.         c3.get_volume();
  43.         return 0;
  44. }
  45.  

回复 "三个方体的体积"

这儿你可以回复上面这条便签

captcha