Advertisement
LegoDrifter

Cuboid

Apr 2nd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Cuboid{
  6. private:
  7.     float a;
  8.     float b;
  9.     float h;
  10. public:
  11.     Cuboid(float x,float y,float z){
  12.     a=x;
  13.     b=y;
  14.     h=z;
  15.     }
  16.     void set_a(float x){
  17.     a=x;
  18.     }
  19.     float get_a(){
  20.     return a;
  21.     }
  22.     void set_b(float x){
  23.     b=x;
  24.     }
  25.     float get_b(){
  26.     return b;
  27.     }
  28.     void set_h(float x){
  29.     h=x;
  30.     }
  31.     float get_h(){
  32.     return h;
  33.     }
  34.     float P(){
  35.     return 2*(a+b+h);
  36.     }
  37.     float V(){
  38.     return a*b*h;
  39.     }
  40.  
  41. };
  42.  
  43.  
  44. int main()
  45. {
  46.  
  47.     float a,b,h;
  48.     cin>> a >> b >> h;
  49.     Cuboid object(a,b,h);
  50.     cout<< object.P() << endl;
  51.     cout<< object.V() << endl;
  52.  
  53.     return 0;
  54. }
  55.  
  56.  
  57. #include <iostream>
  58.  
  59. using namespace std;
  60.  
  61. class Cuboid
  62. {
  63. private:
  64.     int a,b,c;
  65. public:
  66.     Cuboid(int a=0,int b=0,int c=0)
  67.     {
  68.         this->a=a;
  69.         this->b=b;
  70.         this->c=c;
  71.     }
  72.     int area()
  73.     {
  74.         return 2*(a+b+c);
  75.     }
  76.     int volume()
  77.     {
  78.         return a*b*c;
  79.     }
  80.  
  81. };
  82.  
  83. int main()
  84. {
  85.     int a,b,c;
  86.     cin>>a>>b>>c;
  87.     Cuboid cub(a,b,c);
  88.     cout<<"The area of the Cuboid is: "<<cub.area()<<"\nIt's volume is: "<<cub.volume()<<endl;
  89.  
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement