Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _5.Boxes
- {
- public class Box
- {
- public int UpperLeft { get; set; }
- public int UpperRight { get; set; }
- public int BottomLeft { get; set; }
- public int BottomRight { get; set; }
- public int Perimeter { get; set; }
- public int Area { get; set; }
- public int Width { get; set; }
- public int Height { get; set; }
- public static int CalculatePerimeter(int width, int height)
- {
- return width * 2 + height * 2;
- }
- public static int CalculateArea(int width, int height)
- {
- return width * height;
- }
- }
- class Boxes
- {
- static void Main(string[] args)
- {
- var boxes = new List<Box>();
- var line = Console.ReadLine();
- while (line != "end")
- {
- string[] inputParams = line.Split(new[] { ' ', '|',':' }, StringSplitOptions.RemoveEmptyEntries);
- int upperLeft = int.Parse(inputParams[0]);
- int upperRight = int.Parse(inputParams[1]);
- int bottomLeft = int.Parse(inputParams[2]);
- int bottomRight = int.Parse(inputParams[3]);
- int width = Math.Abs(upperLeft - upperRight);
- int height = Math.Abs(upperLeft - bottomLeft);
- var area = Box.CalculateArea(width, height);
- var perimeter = Box.CalculatePerimeter(width, height);
- Box newBox = new Box
- {
- UpperLeft = upperLeft,
- UpperRight = upperRight,
- BottomLeft = bottomLeft,
- BottomRight = bottomRight,
- Area = area,
- Perimeter = perimeter,
- Width = width,
- Height = height
- };
- boxes.Add(newBox);
- line = Console.ReadLine();
- }
- foreach (var box in boxes)
- {
- Console.WriteLine($"Box: {box.Width}, {box.Height}");
- Console.WriteLine($"Perimeter: {box.Perimeter}");
- Console.WriteLine($"Area: {box.Area}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement