Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Sphere
- {
- private:
- double radius;
- public:
- Sphere(){}
- Sphere(double radius)
- {
- this->radius=radius;
- }
- ~Sphere(){}
- double volume()
- {
- return (this->radius*this->radius*this->radius)*((4/3)* 3,14);
- }
- double surface()
- {
- return (this->radius*this->radius)*(4*3,14);
- }
- };
- void info(Sphere sph) {
- cout << "volume: " << sph.volume() << " surface: " << sph.surface() << endl;
- }
- double smallestVolume(Sphere sph[], int n) {
- double min = 99999;
- int index = 1;
- for (int i=0; i<n; i++) {
- min = min > sph[i].volume() ? sph[i].volume() : min;
- index = i;
- }
- cout << "smallest volume: " << min << " " << &sph[index] << endl;
- }
- double smallestSurface(Sphere sph[], int n) {
- double min = 99999;
- int index = 1;
- for (int i=0; i<n; i++) {
- min = min > sph[i].surface() ? sph[i].surface() : min;
- index = i;
- }
- cout << "smallest surface: " << min << " " << &sph[index] << endl;
- }
- int main()
- {
- int n;
- cin >> n;
- Sphere sph[n];
- for (int i=0; i<n; i++) {
- double radius;
- cin>>radius;
- sph[i]=Sphere(radius);
- }
- for (int i=0; i<n; i++) {
- info(sph[i]);
- }
- smallestVolume(sph,n);
- smallestSurface(sph,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment