Sofe1204

Untitled

Mar 18th, 2022 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Sphere
  7. {
  8.     private:
  9.     double radius;
  10.     public:
  11.     Sphere(){}
  12.     Sphere(double radius)
  13.     {
  14.         this->radius=radius;
  15.     }
  16.     ~Sphere(){}
  17.     double volume()
  18.    {
  19.        return (this->radius*this->radius*this->radius)*((4/3)* 3,14);
  20.    }
  21.    double surface()
  22.    {
  23.         return (this->radius*this->radius)*(4*3,14);
  24.    }
  25. };
  26. void info(Sphere sph) {
  27.     cout << "volume: " << sph.volume() << " surface: " << sph.surface() << endl;
  28. }
  29. double smallestVolume(Sphere sph[], int n) {
  30.     double min = 99999;
  31.     int index = 1;
  32.    
  33.     for (int i=0; i<n; i++) {
  34.         min = min > sph[i].volume() ? sph[i].volume() : min;  
  35.         index = i;
  36.     }
  37.    
  38.      cout << "smallest volume: " << min << " " << &sph[index] << endl;
  39. }
  40.  
  41. double smallestSurface(Sphere sph[], int n) {
  42.     double min = 99999;
  43.     int index = 1;
  44.    
  45.     for (int i=0; i<n; i++) {
  46.         min = min > sph[i].surface() ? sph[i].surface() : min;
  47.         index = i;
  48.     }
  49.    
  50.     cout << "smallest surface: " << min << " " << &sph[index] << endl;
  51. }
  52.  
  53.  
  54. int main()
  55. {
  56.     int n;
  57.     cin >> n;
  58.    
  59.     Sphere sph[n];
  60.     for (int i=0; i<n; i++) {
  61.         double radius;
  62.         cin>>radius;
  63.         sph[i]=Sphere(radius);
  64.     }
  65.     for (int i=0; i<n; i++) {
  66.        info(sph[i]);
  67.     }
  68.     smallestVolume(sph,n);
  69.     smallestSurface(sph,n);
  70.    
  71.    return 0;
  72. }
Add Comment
Please, Sign In to add comment