コード例 #1
0
ファイル: Form1.cs プロジェクト: padma-duvvuri/CSharp
        /// <summary>
        /// According to user selected values select and perform the operations
        /// according to the cases
        /// </summary>
        private void UpdateLables()
        {
            Shapes figure = GetFigure();
            Shape shape = null;

            switch (figure)
            {
                case Shapes.Rectangle:
                    {
                        //create instance of the Rectangle class and call necessary methods
                        //to perform operations
                        shape = new Rectangle(width,depth);
                        lblBaseArea.Text = ((Rectangle)shape).Area.ToString("0.00");
                        lblBaseCircum.Text = ((Rectangle)shape).Circum.ToString("0.00");

                        break;
                    }
                case Shapes.Circle:
                    {
                        //create instance of the Ellipse class and call necessary methods
                        //to perform operations
                        shape = new Ellipse(width);
                        lblBaseArea.Text = ((Ellipse)shape).Area.ToString("0.00");
                        lblBaseCircum.Text = ((Ellipse)shape).Circum.ToString("0.00");

                        break;
                    }
                case Shapes.Cylinder:
                    {

                        //create instance of the Cylinder class and call necessary methods
                        //to perform operations
                        shape = new Cylinder(width,depth,lenght);
                        lblBaseArea.Text = ((Cylinder)shape).BaseArea.ToString("0.00");
                        lblBaseCircum.Text = ((Cylinder)shape).BaseCircum.ToString("0.00");

                        lblVolume.Text = ((Cylinder)shape).Volume.ToString("0.00");
                        lblMantelArea.Text = ((Cylinder)shape).MantelArea.ToString("0.00");
                        lblTotSurfaceArea.Text = ((Cylinder)shape).TotalArea.ToString("0.00");

                        break;
                    }
                case Shapes.Ellipse:
                    {
                        //create instance of the Ellipse class and call necessary methods
                        //to perform operations
                        shape = new Ellipse(width,depth);
                        lblBaseArea.Text = ((Ellipse)shape).Area.ToString("0.00");
                        lblBaseCircum.Text = ((Ellipse)shape).Circum.ToString("0.00");

                        break;
                    }

                case Shapes.Prism:
                    {
                        //create instance of the Prism class and call necessary methods
                        //to perform operations
                        shape = new Prism(width, depth, lenght);
                        lblBaseArea.Text = ((Prism)shape).BaseArea.ToString("0.00");
                        lblBaseCircum.Text = ((Prism)shape).BaseCircum.ToString("0.00");

                        lblVolume.Text = ((Prism)shape).Volume.ToString("0.00");
                        lblMantelArea.Text = ((Prism)shape).MantelArea.ToString("0.00");
                        lblTotSurfaceArea.Text = ((Prism)shape).TotalArea.ToString("0.00");

                        break;
                    }

                case Shapes.Sphere:
                    {
                        //create instance of the Sphere class and call necessary methods
                        //to perform operations
                        shape = new Sphere(width);
                        lblBaseArea.Text = ((Sphere)shape).BaseArea.ToString("0.00");
                        lblBaseCircum.Text = ((Sphere)shape).BaseCircum.ToString("0.00");

                        lblVolume.Text = ((Sphere)shape).Volume.ToString("0.00");
                        lblMantelArea.Text = ((Sphere)shape).MantelArea.ToString("0.00");
                        lblTotSurfaceArea.Text = ((Sphere)shape).TotalArea.ToString("0.00");

                        break;
                    }

            }
        }
コード例 #2
0
        /// <summary>
        /// According to user selected values select and perform the operations
        /// according to the cases
        /// </summary>
        private void UpdateLables()
        {
            Shapes figure = GetFigure();
            Shape  shape  = null;

            switch (figure)
            {
            case Shapes.Rectangle:
            {
                //create instance of the Rectangle class and call necessary methods
                //to perform operations
                shape              = new Rectangle(width, depth);
                lblBaseArea.Text   = ((Rectangle)shape).Area.ToString("0.00");
                lblBaseCircum.Text = ((Rectangle)shape).Circum.ToString("0.00");

                break;
            }

            case Shapes.Circle:
            {
                //create instance of the Ellipse class and call necessary methods
                //to perform operations
                shape              = new Ellipse(width);
                lblBaseArea.Text   = ((Ellipse)shape).Area.ToString("0.00");
                lblBaseCircum.Text = ((Ellipse)shape).Circum.ToString("0.00");

                break;
            }

            case Shapes.Cylinder:
            {
                //create instance of the Cylinder class and call necessary methods
                //to perform operations
                shape              = new Cylinder(width, depth, lenght);
                lblBaseArea.Text   = ((Cylinder)shape).BaseArea.ToString("0.00");
                lblBaseCircum.Text = ((Cylinder)shape).BaseCircum.ToString("0.00");

                lblVolume.Text         = ((Cylinder)shape).Volume.ToString("0.00");
                lblMantelArea.Text     = ((Cylinder)shape).MantelArea.ToString("0.00");
                lblTotSurfaceArea.Text = ((Cylinder)shape).TotalArea.ToString("0.00");

                break;
            }

            case Shapes.Ellipse:
            {
                //create instance of the Ellipse class and call necessary methods
                //to perform operations
                shape              = new Ellipse(width, depth);
                lblBaseArea.Text   = ((Ellipse)shape).Area.ToString("0.00");
                lblBaseCircum.Text = ((Ellipse)shape).Circum.ToString("0.00");

                break;
            }

            case Shapes.Prism:
            {
                //create instance of the Prism class and call necessary methods
                //to perform operations
                shape              = new Prism(width, depth, lenght);
                lblBaseArea.Text   = ((Prism)shape).BaseArea.ToString("0.00");
                lblBaseCircum.Text = ((Prism)shape).BaseCircum.ToString("0.00");

                lblVolume.Text         = ((Prism)shape).Volume.ToString("0.00");
                lblMantelArea.Text     = ((Prism)shape).MantelArea.ToString("0.00");
                lblTotSurfaceArea.Text = ((Prism)shape).TotalArea.ToString("0.00");

                break;
            }

            case Shapes.Sphere:
            {
                //create instance of the Sphere class and call necessary methods
                //to perform operations
                shape              = new Sphere(width);
                lblBaseArea.Text   = ((Sphere)shape).BaseArea.ToString("0.00");
                lblBaseCircum.Text = ((Sphere)shape).BaseCircum.ToString("0.00");

                lblVolume.Text         = ((Sphere)shape).Volume.ToString("0.00");
                lblMantelArea.Text     = ((Sphere)shape).MantelArea.ToString("0.00");
                lblTotSurfaceArea.Text = ((Sphere)shape).TotalArea.ToString("0.00");

                break;
            }
            }
        }