Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.         }
  15.     }
  16.  
  17.  
  18.     public abstract class Solid
  19.     {
  20.         abstract public double Volume();
  21.         abstract public double Surface();
  22.     }
  23.  
  24.  
  25.     public abstract class Polyhedron : Solid
  26.     {
  27.         public int faces;
  28.         public int edges;
  29.         public int vertices;
  30.  
  31.     }
  32.  
  33.     public class Cuboid : Polyhedron
  34.     {
  35.         public int a, b, c;
  36.  
  37.         public Cuboid(int _a, int _b, int _c)
  38.         {
  39.             a = _a;
  40.             b = _b;
  41.             c = _c;
  42.         }
  43.  
  44.         public override double Surface()
  45.         {
  46.             //2(ab + ac + bc)
  47.             return 2 * (a * b + a * c + b*c );
  48.         }
  49.  
  50.         public override double Volume()
  51.         {
  52.             return a * b * c;
  53.         }
  54.  
  55.         public override string ToString()
  56.         {
  57.             return " Volume = " + Volume() + " Surface = " + Surface();
  58.         }
  59.  
  60.     }
  61.  
  62.     public class Cube : Cuboid
  63.     {
  64.         public Cube(int _a)
  65.         {
  66.             a = _a;
  67.         }
  68.  
  69.         public override double Surface()
  70.         {
  71.             return 6 * (a * a);
  72.         }
  73.         public override double Volume()
  74.         {
  75.             return (a * a * a);
  76.         }
  77.     }
  78.  
  79.     public class Sphere : Solid
  80.     {
  81.         public double R;
  82.  
  83.         public override double Surface()
  84.         {
  85.             return 4 * Math.PI * (R * R);
  86.         }
  87.  
  88.         public override double Volume()
  89.         {
  90.             return 1.33 * Math.PI * (R * R * R);
  91.         }
  92.     }
  93.     public class Cone : Solid
  94.     {
  95.         public double R, L, H;
  96.         public override double Surface()
  97.         {
  98.             return Math.PI * (R * R) + Math.PI * R * L;
  99.         }
  100.  
  101.         public override double Volume()
  102.         {
  103.             return 0.33 * Math.PI * (R * R) * H;
  104.         }
  105.     }
  106.     public class Cylinder : Solid
  107.     {
  108.         public override double Surface()
  109.         {
  110.             throw new NotImplementedException();
  111.         }
  112.  
  113.         public override double Volume()
  114.         {
  115.             throw new NotImplementedException();
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement