Example #1
0
        public static Cube SetCube(out string name, out string type, out double a,
                                   out double area, out double volume, out int tops, out int edges, out int sides)
        {
            Console.Write("Set Name of Cube: ");
            name = Console.ReadLine();

            Console.Write("Set Type of Cube: ");
            type = Console.ReadLine();

            Console.Write("Enter one side of cube:\n");
            Console.Write("a: ");
            a = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Cube cube = new Cube(a);

            cube.Name = name;
            cube.Type = type;
            area      = cube.Area();
            volume    = cube.Volume();
            tops      = cube.QuantityOfTops();
            edges     = cube.QuantityOfEdges();
            sides     = cube.QuantityOfSides();

            return(cube);
        }
Example #2
0
 public static void Main()
 {
    double x = 5.2;
    Square s = new Square(x);
    Square c = new Cube(x);
    Console.WriteLine("Area of Square = {0:F2}", s.Area());
    Console.WriteLine("Area of Cube = {0:F2}", c.Area());
 }
Example #3
0
 public static void Main()
 {
     double x = 5.2;
     Square s = new Square(x);
     Square c = new Cube(x);
     Console.WriteLine("Area of Square = {0}", string.Format("{0:0.00}", s.Area()));
     Console.WriteLine("Area of Cube = {0}", string.Format("{0:0.00}", c.Area()));
     Console.ReadLine();
 }
Example #4
0
    public static void Main()
    {
        double x = 5.2;
        Square s = new Square(x);
        Square c = new Cube(x);

        Console.WriteLine("Area of Square = {0:F2}", s.Area());
        Console.WriteLine("Area of Cube = {0:F2}", c.Area());
    }
Example #5
0
        static void Main(string[] args)
        {
            int a;

            Console.Write("1. Square\n2. Cube\n");
            Square square = new Square();
            double s;
            Cube   cube = new Cube();

            Console.OutputEncoding = System.Text.Encoding.Unicode;
            Console.InputEncoding  = System.Text.Encoding.Unicode;
            a = Convert.ToInt32(Console.ReadLine());
            switch (a)
            {
            case 1:
                Console.Clear();
                Console.WriteLine("Square");
                Console.Write("Mời nhập cạnh: ");
                square.Side = Convert.ToDouble(Console.ReadLine());
                Console.Write("Mời nhập diện tích: ");
                s = square.Area(Convert.ToDouble(Console.ReadLine()));
                Console.WriteLine("Area: {0}\nSide: {1}", square.Area(), s);
                break;

            case 2:
                Console.Clear();
                Console.WriteLine("Square");
                Console.Write("Mời nhập cạnh: ");
                cube.Side = Convert.ToDouble(Console.ReadLine());
                Console.Write("Mời nhập diện tích: ");
                s = cube.Area(Convert.ToDouble(Console.ReadLine()));
                Console.WriteLine("Area: {0}\nSide: {1}", cube.Area(), s);
                break;

            default:
                break;
            }
        }
Example #6
0
        private static void PlayWidthShape()
        {
            Square    b1 = new Square(wh: 10);
            Rectangle b2 = new Rectangle(width: 25, length: 10);
            Prism     b3 = new Prism(width: 20, length: 50, height: 15);
            Cube      b4 = new Cube(dim: 12);
            Triangle  b5 = new Triangle(size: 5);
            Sphere    b6 = new Sphere(rad: 3);


            System.Console.WriteLine("----Information for b1: Square----");
            Console.WriteLine("Number of Edges: " + b1.NumberOfEdges);
            System.Console.WriteLine("Perimeter: " + b1.Perimeter());
            System.Console.WriteLine("Area: " + b1.Area());
            System.Console.WriteLine("Volumn: " + b1.Volume());

            System.Console.WriteLine("----Information for b2: Rectangle----");
            Console.WriteLine("Number of Edges: " + b2.NumberOfEdges);
            System.Console.WriteLine("Perimeter: " + b2.Perimeter());
            System.Console.WriteLine("Area: " + b2.Area());
            System.Console.WriteLine("Volumn: " + b2.Volume());

            System.Console.WriteLine("----Information for b3: Prism----");
            Console.WriteLine("Number of Edges: " + b3.NumberOfEdges);
            System.Console.WriteLine("Perimeter: " + b3.Perimeter());
            System.Console.WriteLine("Area: " + b3.Area());
            System.Console.WriteLine("Volumn: " + b3.Volume());

            System.Console.WriteLine("----Information for b4: Cube----");
            Console.WriteLine("Number of Edges: " + b4.NumberOfEdges);
            System.Console.WriteLine("Perimeter: " + b4.Perimeter());
            System.Console.WriteLine("Area: " + b4.Area());
            System.Console.WriteLine("Volumn: " + b4.Volume());

            System.Console.WriteLine("----Information for b5: Triangle----");
            Console.WriteLine("Number of Edges: " + b5.NumberOfEdges);
            System.Console.WriteLine("Perimeter: " + b5.Perimeter());
            System.Console.WriteLine("Area: " + b5.Area());
            System.Console.WriteLine("Volumn: " + b5.Volume());

            System.Console.WriteLine("----Information for b6: Sphere----");
            Console.WriteLine("Number of Edges: " + b6.NumberOfEdges);
            System.Console.WriteLine("Circumference: " + b6.Circumference());
            System.Console.WriteLine("Area: " + b6.Area());
            System.Console.WriteLine("Volumn: " + b6.Volume());
        }
Example #7
0
        static void Main(string[] args)
        {
            List<TwoDim> twodim = new List<TwoDim>();
            List<ThreeDim> threedim = new List<ThreeDim>();
            while (true)
            {
                Console.WriteLine("도형종류 : Triangle, Square, Circle, Cube, Sphere");
                double number;
                Console.Write("단위 크기 : ");
                try
                {
                    number = Double.Parse(Console.ReadLine());
                    if (number<=0)
                    {
                        Console.WriteLine("잘못된 범위의 값을 입력하였습니다.");
                        continue;
                    }
                }
                catch (System.FormatException x)
                {
                    Console.WriteLine(x.Message);
                    continue;
                }
                catch (SystemException y)
                {
                    Console.WriteLine(y.Message);
                    continue;
                }

                Console.Write("모양 : ");

                string whatShape = Console.ReadLine();
                int count = 0;
                int i = 0;
                if (whatShape != "Triangle" && whatShape != "Square" && whatShape != "Circle"&&whatShape!="Cube"&&whatShape!="Sphere")
                {
                    Console.WriteLine("없는 도형입니다.");
                    continue;
                }
                else if (whatShape == "Triangle")
                {
                    TwoDim tri = new Triangle();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 3 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        tri.typeTwo = 3;
                        tri.numTwo = number;
                        tri.Length(number);
                        tri.Area(number);
                        twodim.Add(tri);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Square")
                {
                    TwoDim squ = new Square();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 4 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        squ.typeTwo = 4;
                        squ.numTwo = number;
                        squ.Length(number);
                        squ.Area(number);
                        twodim.Add(squ);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Circle")
                {
                    TwoDim cir = new Circle();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 0 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        cir.typeTwo = 0;
                        cir.numTwo = number;
                        cir.Length(number);
                        cir.Area(number);
                        twodim.Add(cir);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Cube")
                {
                    ThreeDim cub = new Cube();
                    foreach (var item in threedim)
                    {
                        if (threedim[i].numThree == number && threedim[i].typeThree == 6)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        cub.typeThree = 6;
                        cub.Area(number);
                        cub.Volume(number);
                        threedim.Add(cub);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Sphere")
                {
                    ThreeDim sph = new Sphere();
                    foreach (var item in threedim)
                    {
                        if (threedim[i].numThree == number && threedim[i].typeThree == 6)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        sph.typeThree = 0;
                        sph.Area(number);
                        sph.Volume(number);
                        threedim.Add(sph);
                        i = 0;
                    }
                    count = 0;
                }
            }
        }