Protocols for shapes: calculating area and perimeter

Swift Medium protocols

Task «Protocols for shapes: calculating area and perimeter»

Implement the Shape protocol with methods area() -> Double and perimeter() -> Double. Create structures Circle (property radius: Double) and Rectangle (properties width: Double, height: Double) that conform to this protocol. Write a function printShapeInfo(shape: Shape) that prints the area and perimeter of the shape. Input data: an integer n (number of shapes), then for each shape a string with the type ('circle' or 'rectangle') and the corresponding parameters (for circle — radius, for rectangle — width and height). For each shape, print its type and the area and perimeter values with an accuracy of two decimal places.

Input Format

First line: integer n (1 ≤ n ≤ 100). Then n lines: each line contains the shape type and its parameters (separated by a space). For circle: 'circle <radius>'. For rectangle: 'rectangle <width> <height>'. All parameters are integers from 1 to 1000.

Output Format

For each figure on a separate line: '<Figure type>: Area = <area>, Perimeter = <perimeter>'. Area and perimeter are displayed with two decimal places.

Examples

Example 1

INPUT
3 circle 5 rectangle 4 7 circle 10
OUTPUT
Circle: Площадь = 78.54, Периметр = 31.42 Rectangle: Площадь = 28.00, Периметр = 22.00 Circle: Площадь = 314.16, Периметр = 62.83

Example 2

INPUT
1 rectangle 3 8
OUTPUT
Rectangle: Площадь = 24.00, Периметр = 22.00

Example 3

INPUT
5 3 apple -1 banana 0 cherry 4 date -2 elderberry
OUTPUT
main.swift