コード例 #1
0
 public void Write(string FileName, Pyramid pyramid)
 {
     using (StreamWriter fileOut = new StreamWriter(FileName + ".txt"))
     {
         fileOut.WriteLine("Площадь основания {0}", pyramid.RectangleArea);
         fileOut.WriteLine("Объём пирамиды {0}", pyramid.Volume);
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            PyramidBuilderFromFile fs = new PyramidBuilderFromFile();
            Pyramid pyramid           = new Pyramid();

            fs.Read("text", pyramid);
            pyramid.ChangePointOfBase(new Point {
                x = 2.3, y = 3.3, z = 5.8
            }, 0);
            fs.Write("OutPut", pyramid);
        }
コード例 #3
0
        public void Read(string FileName, Pyramid pyramid)
        {
            using (StreamReader file = new StreamReader(FileName + ".txt"))
            {
                double number;
                for (int i = 0; i < Pyramid.BASE_NUMBER; i++)
                {
                    string[] line = file.ReadLine().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (Double.TryParse(line[0], out number) &&
                        Double.TryParse(line[1], out number) &&
                        Double.TryParse(line[2], out number))
                    {
                        pyramid.rectangleOfPyramid[i] = new Point
                        {
                            x = double.Parse(line[0]),
                            y = double.Parse(line[1]),
                            z = double.Parse(line[2])
                        }
                    }
                    ;
                    else
                    {
                        throw new ArgumentException("Invalid argument in file");
                    }
                }

                string[] lineApex = file.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (Double.TryParse(lineApex[0], out number) &&
                    Double.TryParse(lineApex[1], out number) &&
                    Double.TryParse(lineApex[2], out number))
                {
                    pyramid.top = new Point
                    {
                        x = double.Parse(lineApex[0]),
                        y = double.Parse(lineApex[1]),
                        z = double.Parse(lineApex[2])
                    }
                }
                ;

                pyramid.height = double.Parse(file.ReadLine());
            }
        }