public static void Main() { TwoDShape[] shapes = new TwoDShape[4]; // массив из 4 объектных ссылок shapes[0] = new Triangle("прямоугольный", 8.0, 12.0); shapes[1] = new Rectangle(10); shapes[2] = new Rectangle(10, 4); shapes[3] = new Triangle(7.0); for (int i = 0; i < shapes.Length; i++) { Console.WriteLine("Объектом является " + shapes[i].name); Console.WriteLine("Площадь равна " + shapes[i].area()); Console.WriteLine(); } }
static void Main() { TwoDShape[] shapes = new TwoDShape[5]; shapes[0] = new Triangle("right", 8.0, 12.0); shapes[1] = new Rectangle(10); shapes[2] = new Rectangle(10, 4); shapes[3] = new Triangle(7.0); shapes[4] = new TwoDShape(10, 20, "generic"); for (int i = 0; i < shapes.Length; i++) { Console.WriteLine("object is " + shapes[i].name); Console.WriteLine("Area is " + shapes[i].Area()); Console.WriteLine(); } }
public static void Main() { TwoDShape[] shapes = new TwoDShape[5]; shapes[0] = new Triangle("прямоугольный", 8.0, 12.0); shapes[1] = new Rectangle(10); shapes[2] = new Rectangle(10, 4); shapes[3] = new Triangle(7.0); shapes[4] = new TwoDShape(10, 20, "заготовка для фигуры"); for (int i = 0; i < shapes.Length; i++) { Console.WriteLine("Объектом является " + shapes[i].name); Console.WriteLine("Площадь равна " + shapes[i].area()); Console.WriteLine(); } }
public Chapter3() { TwoDShape[] shapes = new TwoDShape[5]; shapes[0] = new TriangleTwoD("right", 8.0, 12.0); //прямоугольный shapes[1] = new RectangleTwoD(10); shapes[2] = new RectangleTwoD(10, 4); shapes[3] = new TriangleTwoD(7.0); shapes[4] = new TwoDShape(10, 20, "generic form"); foreach (TwoDShape obj in shapes) { Console.WriteLine("object is " + obj.name); Console.WriteLine("area is " + obj.Area()); Console.WriteLine(); } }
// Construct a copy of a TwoDShape object. public TwoDShape(TwoDShape ob) { Width = ob.Width; Height = ob.Height; name = ob.name; }
// Создаем объект из объекта. public TwoDShape(TwoDShape ob) { width = ob.width; height = ob.height; }
public TwoDShape(TwoDShape obj) { this.Width = obj.Width; this.Height = obj.Height; this.name = obj.name; }
// Создаем объект из объекта. public TwoDShape(TwoDShape ob) { width = ob.width; height = ob.height; name = ob.name; }
//Get the shape information from the text boxes on the form //depending on what shape the user entered and output //its specifications to the form. private void goButton_Click(object sender, EventArgs e) { if (shapeInputBox.Text != "") { string shape, coordinates; Point shapeOrigin, point2; int length = 0, width = 0, height = 0, radius = 0; shape = shapeInputBox.Text.ToLower(); try { try { switch (shape) { case "square": length = Int32.Parse(lengthRBox.Text); coordinates = point1Box.Text; shapeOrigin = parseTwoDPoint(coordinates); checkIfNegative(length); ddShape = new Square(shapeOrigin, length); shapeInfo.Text = ddShape.ToString(); shapeImageBox.Image = ddShape.SImage; break; case "circle": radius = Int32.Parse(lengthRBox.Text); coordinates = point1Box.Text; shapeOrigin = parseTwoDPoint(coordinates); checkIfNegative(radius); ddShape = new Circle(shapeOrigin, radius); shapeInfo.Text = ddShape.ToString(); shapeImageBox.Image = ddShape.SImage; break; case "sphere": radius = Int32.Parse(lengthRBox.Text); coordinates = point1Box.Text; shapeOrigin = parseThreeDPoint(coordinates); checkIfNegative(radius); dddShape = new Sphere(shapeOrigin, radius); shapeInfo.Text = dddShape.ToString(); shapeImageBox.Image = dddShape.SImage; break; case "rectangle": length = Int32.Parse(lengthRBox.Text); width = Int32.Parse(widthBox.Text); coordinates = point1Box.Text; shapeOrigin = parseTwoDPoint(coordinates); checkIfNegative(length, width); ddShape = new Rectangle(shapeOrigin, length, width); shapeInfo.Text = ddShape.ToString(); shapeImageBox.Image = ddShape.SImage; break; case "cube": length = Int32.Parse(lengthRBox.Text); coordinates = point1Box.Text; shapeOrigin = parseThreeDPoint(coordinates); coordinates = point2Box.Text; point2 = parseThreeDPoint(coordinates); checkIfNegative(length); dddShape = new Cube(shapeOrigin, point2, length); shapeInfo.Text = dddShape.ToString(); shapeImageBox.Image = dddShape.SImage; break; case "cuboid": length = Int32.Parse(lengthRBox.Text); height = Int32.Parse(widthBox.Text); coordinates = point1Box.Text; shapeOrigin = parseThreeDPoint(coordinates); coordinates = point2Box.Text; point2 = parseThreeDPoint(coordinates); checkIfNegative(length, height); dddShape = new Cuboid(shapeOrigin, point2, length, height); shapeInfo.Text = dddShape.ToString(); shapeImageBox.Image = dddShape.SImage; break; case "cylinder": height = Int32.Parse(widthBox.Text); radius = Int32.Parse(lengthRBox.Text); coordinates = point1Box.Text; shapeOrigin = parseThreeDPoint(coordinates); checkIfNegative(height, radius); dddShape = new Cylinder(shapeOrigin, radius, height); shapeInfo.Text = dddShape.ToString(); shapeImageBox.Image = dddShape.SImage; break; } } catch (NegativeNumberException nE) { //clear boxes point1Box.Clear(); point2Box.Clear(); lengthRBox.Clear(); widthBox.Clear(); shapeInputBox.Clear(); } } catch (FormatException err) { MessageBox.Show(err.Message, "Wrong Input Format", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
// Construct a copy of a TwoDShape object. public TwoDShape(TwoDShape ob) { Width = ob.Width; Height = ob.Height; }