static void Main() { //creates a Triangle and calculates surface var triangle = new Triangle(3.2, 4.5); var triangleSurface = triangle.CalculateSurface(); //creates a Rectangle and calculates surface var rectangle = new Rectangle(4, 12.3); var rectangleSurface = rectangle.CalculateSurface(); //creates a Square and calculates surface var square = new Square(5); var squareSurface = square.CalculateSurface(); //prints shapes and surfaces PrintShape(triangle); Console.WriteLine("Surface of the triangle is: {0}", triangleSurface); Console.WriteLine(new string('-', 30)); Console.WriteLine(); PrintShape(rectangle); Console.WriteLine("Surface of the rectangle is: {0}", rectangleSurface); Console.WriteLine(new string('-', 30)); Console.WriteLine(); PrintShape(square); Console.WriteLine("Surface of the square is: {0}", squareSurface); Console.WriteLine(new string('-', 30)); }
static void Main() { Triangle myTriangle = new Triangle(4, 8); Rectangle myRectangle = new Rectangle(4, 8); Circle myCircle = new Circle(6); List<IShape> shapes = new List<IShape>() { myCircle, myRectangle, myTriangle }; shapes.ForEach(shape => Console.WriteLine(shape .GetType().ToString() + " - Area = " + shape.CalculateArea())); shapes.ForEach(shape => Console.WriteLine(shape .GetType().ToString() + " - Perimeter = " + shape.CalculatePerimeter())); double shapesAreasTogether = 0; shapes.ForEach(shape => shapesAreasTogether += shape.CalculateArea()); Console.WriteLine("\nShapes Areas Together = {0}", shapesAreasTogether); double shapesPerimetersTogether = 0; shapes.ForEach(shape => shapesPerimetersTogether += shape.CalculatePerimeter()); Console.WriteLine("\nShapes Perimeters Together = {0}", shapesPerimetersTogether); }
static void Main() { Random rand = new Random(); List<Shape> shapes = new List<Shape>(); for (int i = 0; i < 5; i++) { Triangle triangle = new Triangle((double)rand.Next(1,20),(double)rand.Next(1,20)); shapes.Add(triangle); } for (int i = 0; i < 5; i++) { Rectangle rectangle = new Rectangle((double)rand.Next(1, 20), (double)rand.Next(1, 20)); shapes.Add(rectangle); } for (int i = 1; i <= 5; i++) { Circle circle = new Circle(i,i); shapes.Add(circle); } foreach (var shape in shapes) { string type = shape.GetType().Name; Console.WriteLine("{0}, surface - {1}", type, shape.GetSurface()); } }
static void Main(string[] args) { Shapes.Rectangle r1 = new Shapes.Rectangle(1, 4); Shapes.Triangle t1 = new Shapes.Triangle(2, 3); IShape r5 = new Shapes.Rectangle(2, 2); if (r1 is Shapes.Rectangle) { Console.WriteLine("r1 is a Retangle"); Shapes.Rectangle r2 = (Shapes.Rectangle)r1; Shapes.Rectangle r3 = r1 as Shapes.Rectangle; } List <Shape> shapes = new List <Shape>(); shapes.Add(r1); shapes.Add(t1); shapes.Add(new Shapes.Square(3)); shapes.Add(new Shapes.Rectangle(2, 4)); shapes.Add(new Shapes.Square(1)); Console.WriteLine(shapes.Count); foreach (var item in shapes) { Console.WriteLine(item.GetType()); Console.WriteLine(item.Area()); } List <Shape> result = shapes.Where(o => o.Area() > 4).ToList(); var rectList = shapes.Where(r => r is Shapes.Rectangle).ToList(); foreach (var item in rectList) { Console.WriteLine(item.GetType()); Console.WriteLine(item); } var trilist = (from t in shapes where t is Shapes.Triangle select t).ToList(); Dictionary <string, Shape> dict = new Dictionary <string, Shape>(); Console.ReadLine(); // Rectangle Rect1 = new Rectangle(1, 0); // try // { // Rect1.Area(); // } // catch (Exception e) // { // Console.WriteLine(e.Message); // } }
static void Main(string[] args) { Rectangle rectangle = new Rectangle(5, 6); rectangle.CalculateSruface(); Triangle triangle = new Triangle(4, 3); triangle.CalculateSruface(); Square square = new Square(7, 7); square.CalculateSruface(); }
public static void Main() { Triangle triangle = new Triangle(4, 5); Console.WriteLine(triangle.CalculateSurface()); var rectangle = new Rectangle(3, 5); Console.WriteLine(rectangle.CalculateSurface()); var circle = new Circle(4); Console.WriteLine("{0:F2}", circle.CalculateSurface()); }
public void Area_Test_For_Triangle_3_4_5_Returns_6() { Shapes.Triangle triangle = new Shapes.Triangle(3, 4, 5); double area; area = triangle.Area(); Assert.That(area, Is.EqualTo(6)); }
public void Perimeter_Test_For_Triangle_3_4_5_Returns_12() { Shapes.Triangle triangle = new Shapes.Triangle(3, 4, 5); double perimeter; perimeter = triangle.Perimeter(); Assert.That(perimeter, Is.EqualTo(12)); }
static void Main() { var triangle = new Triangle(4, 3); var rectangle = new Rectangle(12, 10); var square = new Square(10); Console.WriteLine("The Area of Triangle is: {0}", triangle.CalculateSurface()); Console.WriteLine("The Area of Rectangle is: {0}", rectangle.CalculateSurface()); Console.WriteLine("The Area of Square is: {0}", square.CalculateSurface()); }
static void Main() { var rect = new Rectangle(12, 32.21); var square = new Square(12, 12); var tri = new Triangle(33, 12); Console.WriteLine(rect.CalculateSurface()); Console.WriteLine(square.CalculateSurface()); Console.WriteLine(tri.CalculateSurface()); var squareCheck = new Square(12, 13); }
static void Main() { var shapes = new Shape[3]; shapes[0] = new Rectangle(3, 4); shapes[1] = new Triangle(3, 4); shapes[2] = new Square(3); foreach (var shape in shapes) { Console.WriteLine(shape.CalculateSurface()); } }
static void Main(string[] args) { var circle = new Circle(5); Console.WriteLine(circle.CalculateArea()); Console.WriteLine(circle.CapculatePerimeter()); var triangle = new Triangle(2, 2); Console.WriteLine(triangle.CalculateArea()); Console.WriteLine(triangle.CapculatePerimeter()); var rectangle = new Rectangle(3, 3); Console.WriteLine(rectangle.CalculateArea()); Console.WriteLine(rectangle.CapculatePerimeter()); }
static void Main(string[] args) { Shapes.Rectangle r1 = new Shapes.Rectangle(1, 4); Shapes.Triangle t1 = new Shapes.Triangle(2, 3); IShape r5 = new Shapes.Rectangle(2, 2); //if (r1 is Rectangle) //{ // Console.WriteLine("r1 is a Retangle"); // Rectangle r2 = (Rectangle)r1; // Rectangle r3 = r1 as Rectangle; //} List <Shape> shapes = new List <Shape>(); shapes.Add(r1); shapes.Add(t1); shapes.Add(new Shapes.Rectangle(2, 4)); Console.WriteLine(shapes.Count); for (int i = 0; i < shapes.Count; i++) { } foreach (var item in shapes) { Console.WriteLine(item.GetType()); Console.WriteLine(item.Area()); } Dictionary <string, Shape> dict = new Dictionary <string, Shape>(); Console.ReadLine(); // Rectangle Rect1 = new Rectangle(1, 0); // try // { // Rect1.Area(); // } // catch (Exception e) // { // Console.WriteLine(e.Message); // } }
public void TriangleAreaTest() { Triangle[] triangles = new Triangle[5]; triangles[0] = new Triangle(2, 2); triangles[1] = new Triangle(4, 2); triangles[2] = new Triangle(1, 3); triangles[3] = new Triangle(2, 3); triangles[4] = new Triangle(1, 1); Assert.AreEqual(2, triangles[0].CalculateSurface()); Assert.AreEqual(4, triangles[1].CalculateSurface()); Assert.AreEqual(1.5, triangles[2].CalculateSurface()); Assert.AreEqual(3, triangles[3].CalculateSurface()); Assert.AreEqual(0.5, triangles[4].CalculateSurface()); }
static void Main(string[] args) { IShape[] shapes = new IShape[3]; shapes[0] = new Circle(5.5); shapes[1] = new Triangle(20,20,10); shapes[2] = new Rectangle(10,10); foreach (var shape in shapes) { Console.WriteLine("AREA: " +shape.CalculateArea() + " : " + shape); Console.WriteLine("PERIMETER: " + shape.CalculatePerimeter() + " : " + shape); Console.WriteLine(Environment.NewLine); } }
static void Main() { List<Shape> shape = new List<Shape>(); Square square = new Square(4); shape.Add(square); Triangle triangle = new Triangle(7.8, 4.8); shape.Add(triangle); Rectangle rectangle = new Rectangle(8, 5.7); shape.Add(rectangle); foreach (var item in shape) { Console.WriteLine(item.GetType().Name + " surfase is " + item.CalculateSurface()); } }
public static void Main() { IShape triangle1 = new Triangle(2.5, 2, 60); IShape triangle2 = new Triangle(3.1, 2.1, 90); IShape rect1 = new Rectangle(2.5, 2); IShape rect2 = new Rectangle(3.1, 2.1); IShape circle1 = new Circle(2.5); IShape circle2 = new Circle(2.1); IShape[] shapes = new IShape[6] { triangle1, triangle2, rect1, rect2, circle1, circle2 }; foreach (var shape in shapes) { Console.WriteLine("{0,-20}: Perimeter: {1:N2}, Area: {2:N2}", shape.GetType().Name, shape.CalculatePerimeter(), shape.CalculateArea()); } }
public static void Main() { var triangle = new Triangle(10.5, 8.5); var rectangle = new Rectangle(8d, 8d); var circle = new Circle(5d); var shapes = new Shape[] { triangle, rectangle, circle }; foreach (Shape shape in shapes) { var result = new StringBuilder(); result.AppendLine(string.Format("{0}'s surface: {1}", shape.GetType().Name, shape.CalculateSurface())); Console.WriteLine(result.ToString()); } }
static void Main() { var circle = new Circle(10.5); var rectangle = new Rectanlge(4.5, 5.4); var triangle = new Triangle(5, 6, 4, 5); var shapes = new List<IShape>() { circle, rectangle, triangle }; foreach (var shape in shapes) { Console.WriteLine("{0} -> Area: {1:F4}; Perimeter: {2:F4};", shape.GetType().Name, shape.CalculateArea(), shape.CalculatePerimeter()); } }
static void Main(string[] args) { IShape triangleOne = new Triangle(2.5, 2, 60); IShape triangleTwo = new Triangle(3.1, 2.1, 90); IShape rectangleOne = new Rectangle(2.5, 2); IShape rectangleTwo = new Rectangle(3.1, 2.1); IShape circleOne = new Circle(2.5); IShape circleTwo = new Circle(2.1); IShape[] shapes = new IShape[6] { triangleOne, triangleTwo, rectangleOne, rectangleTwo, circleOne, circleTwo }; foreach (var shape in shapes) { Console.WriteLine("{0,-20}: Perimeter: {1:N2}, Area: {2:N2}", shape.GetType().Name, shape.CalculatePerimeter(), shape.CalculateArea()); } }
static void Main() { var triangle1 = new Triangle(2, 5, 60); var triangle2 = new Triangle(6, 7, 80); BasicShape rectangle1 = new Rectangle(5, 11); BasicShape rectangle2 = new Rectangle(6.5, 9.2); BasicShape circle1 = new Circle(6.1); BasicShape circle2 = new Circle(14.5); BasicShape[] shapes = new[] { triangle1, triangle2, rectangle1, rectangle2, circle1, circle2 }; foreach (var shape in shapes) { Console.WriteLine(shape.GetType().Name); Console.WriteLine("Area => " + shape.CalculateArea()); Console.WriteLine("Perimeter => " + shape.CalculatePerimeter()); } }
public static void Main() { var shapes = new List<Shape>(); var square = new Square(10); var rectangle = new Rectangle(5.5, 6.5); var triangle = new Triangle(new Point(1, 5), new Point(3, 7), new Point(8, 3)); var ellipse = new Ellipse(3, 7); var circle = new Circle(5.5); shapes.Add(circle); shapes.Add(ellipse); shapes.Add(triangle); shapes.Add(rectangle); shapes.Add(square); foreach (var shape in shapes) { Console.WriteLine(shape.ToString()); Console.WriteLine(); } }
public static void Main(string[] args) { GeometricFigure[] g = new GeometricFigure[3]; g[0] = new Rectangle(10,20).ComputeArea(); g[1] = new Square(5).ComputeArea(); g[2] = new Triangle(5,10).ComputeArea(); Console.WriteLine("displaying datas..."); DisplayData(g); for (int i=0; i<g.Length; i++) { g[i].Height = i*12+1; g[i].ComputeArea(); } Console.WriteLine("changed stuff...redisplaying"); DisplayData(g); }
static void Main(string[] args) { Point p1 = new Point(1, 2); Point p2 = new Point(5, 1); Point p3 = new Point(3, 5); Point p4 = new Point(1, 5); Triangle triangle = new Triangle(p1, p2, p3); //Console.WriteLine(triangle.GetArea()); //Console.WriteLine(triangle.GetPerimeter()); Console.WriteLine(triangle.ToString()); Ellipse ellipse = new Ellipse(5, 10); //Console.WriteLine(ellipse.GetPerimeter()); //Console.WriteLine(ellipse.GetArea()); Console.WriteLine(ellipse.ToString()); Rectangle rectangle = new Rectangle(p1,p2,p3,p4); //Console.WriteLine(rectangle.Width); //Console.WriteLine(rectangle.Heigth); //Console.WriteLine(rectangle.GetArea()); //Console.WriteLine(rectangle.GetPerimeter()); Console.WriteLine(rectangle.ToString()); }
static void Main(string[] args) { Square x = new Square(5); Circle c = new Circle(3.5); Triangle t = new Triangle(3, 4, 5); Rectangle r = new Rectangle(5, 2.5); //make list List<IShape> shapes = new List<IShape>(); shapes.Add(x); shapes.Add(c); shapes.Add(t); shapes.Add(r); //print out foreach (IShape shape in shapes) { Console.WriteLine(shape); } Console.ReadLine(); }
public static void Main() { IShape[] shapes; IShape testTriangle1 = new Triangle(1.2, 2, 30); IShape testTriangle2 = new Triangle(3, 1.3, 60); IShape testRectangle1 = new Rectangle(2, 3); IShape testRectangle2 = new Rectangle(2, 3); IShape testCircle1 = new Circle(1.2); IShape testCircle2 = new Circle(3); shapes = new IShape[6] { testTriangle1, testTriangle2, testRectangle1, testRectangle2, testCircle1, testCircle2 }; int shapesLength = shapes.Length; for (int i = 0; i < shapesLength; i++) { IShape shape = shapes[i]; Console.WriteLine("Shape [{0}] has Area: ({1:0.00}) and Perimeter: ({2:0.00})", shape.GetType().Name, shape.CalculateArea(), shape.CalculatePerimeter()); } }
public static void Main() { var arrayOfSquares = new Square[] { new Square(5.5), new Square(6.7), new Square(9.8) }; var arrayOfTriangles = new Triangle[] { new Triangle(5.5, 6.5), new Triangle(15.4, 21.4), new Triangle(3.5, 2.1) }; var arrayOfRectangles = new Rectangle[] { new Rectangle(1.2, 2.5), new Rectangle(22.15, 15.5), new Rectangle(17.2, 10) }; //First variant Console.WriteLine("Calculating the surface of the squares:"); PrintSurface(arrayOfSquares); Console.WriteLine("Calculating the surface of the triangles:"); PrintSurface(arrayOfTriangles); Console.WriteLine("Calculating the surface of the rectangles:"); PrintSurface(arrayOfRectangles); ////Second variant //var listOfSurfacesOfSquares = Surfaces(arrayOfSquares); //Console.WriteLine(string.Join("\n", listOfSurfacesOfSquares)); }
static void Main() { Triangle triangle = new Triangle(2, 3); Rectangle rectangle = new Rectangle(2, 3); Square square = new Square(2); Console.WriteLine("Triangle area is {0}", triangle.CalculateSurface()); Console.WriteLine("Rectangle area is {0}", rectangle.CalculateSurface()); Console.WriteLine("Square area is {0}", square.CalculateSurface()); //Write a program that tests the behaviour of the CalculateSurface() method //for different shapes (Square, Rectangle, Triangle) stored in an array Shape[] all = new Shape[] { new Triangle (2,3), new Rectangle(2,3), new Square (3) }; foreach (Shape shape in all) { Console.WriteLine("{0} is the area of the object {1}", shape.CalculateSurface(), shape.GetType()); } }
public void SquareTest(int legA, int legB, int legC) { var triangle = new Triangle(legA, legB, legC); double p = (legA + legB + legC) / 2.0; //half of perimiter Assert.AreEqual(Math.Sqrt(p * (p - legA) * (p - legB) * (p - legC)), triangle.Square); }
public void TestTriangleCalculateArea() { Triangle r = new Triangle(2.1, 39); Assert.AreEqual(40.95, r.CalculateArea()); }
static void Main() { var myPoint = new Point(1, 2); //Console.WriteLine(myPoint); //myPoint.PrintInfo(); var myCircle = new Circle() { Radius = 2, Center = myPoint }; //myCircle.PrintInfo(); var myTriangle = new Triangle() { Name = "ABC", A = new Point(0, 0), B = new Point(1, 0), C = new Point(0, 1) }; //myTriangle.PrintInfo(); //Console.WriteLine("Число вершин {0}", // myTriangle.NumberOfPoints()); //PrintNumberOfPoints(myTriangle); var myRectangle = new Rectangle() { A = new Point(1, 1), C = new Point(-1, -1), Name = "ABCD"}; //myRectangle.PrintInfo(); //Console.WriteLine("Число вершин {0}", // myRectangle.NumberOfPoints()); //PrintNumberOfPoints(myRectangle); var myLine = new Line() { A = new Point(), B = new Point(1, 1) }; IPrintable[] ifacePr = new IPrintable[] { (IPrintable)myCircle, myTriangle, myLine, myRectangle, myPoint }; foreach (var figure in ifacePr) { figure.PrintInfo(); if (figure is IPointy) PrintNumberOfPoints((IPointy)figure); if (figure is IMeasurable) Console.WriteLine("Площадь равна {0:F3} кв. ед.", ((IMeasurable)figure).GetArea()); if (figure is IPolygone) Console.WriteLine("Число диагоналей равно " + ((IPolygone)figure).NumberOfDiagonals); } Console.WriteLine("Фигура наибольшей площади имеет площадь {0:F3}", GetTheLargest(myPoint, myTriangle, myCircle, myLine).GetArea()); myCircle.Draw(); var ifaceScreen = (IScreenable)myCircle; var IfacePlotter = (IPlottarable)myCircle; ifaceScreen.Draw(); IfacePlotter.Draw(); foreach (Point vertex in myTriangle) vertex.PrintInfo(); myTriangle.A = new Point(-1, -1); myTriangle.PrintInfo(); foreach (Point vertex in myTriangle) vertex.PrintInfo(); myRectangle.PrintInfo(); foreach (Point vert in myRectangle) vert.PrintInfo(); //var iEnum = myRectangle.GetEnumerator(); //while (true) //{ // if (iEnum.MoveNext()) // { // var p = iEnum.Current as Point; // p.PrintInfo(); // } // else // iEnum.Reset(); // if (Console.KeyAvailable) // break; //} var myQuadrangle = new Quadrangle() { A = new Point(), B = new Point(5, 0), C = new Point(5, 5), D = new Point(-5, 0) }; myQuadrangle.PrintInfo(); foreach (Point vert in myQuadrangle) vert.PrintInfo(); Console.ReadKey(); }
static void Main(string[] args) { Triangle tr = new Triangle(1, 3); Rectangle rect = new Rectangle(2, 2); Circle circle = new Circle(3); Console.WriteLine(tr.CalculateSurface()); Console.WriteLine(rect.CalculateSurface()); Console.WriteLine(circle.CalculateSurface()); }