Protocol for geometric shapes
Swift
Easy
protocols
Task «Protocol for geometric shapes»
Create a protocol Shape with the following requirements: a property area of type Double (read-only) and a method description() -> String. Implement two structures: Circle with a parameter radius and Rectangle with parameters width and height. Each structure must conform to the Shape protocol. In main, read three lines: the first contains the radius of the circle, the second contains the width of the rectangle, and the third contains the height of the rectangle. Output the results of calling description() for the circle and rectangle separated by a space.
Input Format
Three lines: the first is the radius (Double), the second is the width (Double), the third is the height (Double).
Output Format
Two strings: the first is a description of a circle (the `description()` method), the second is a description of a rectangle (the `description()` method).
Examples
Example 1
INPUT
5
1 -2 3 4 -1
OUTPUT
Circle with radius 5.0
Rectangle with width 1.0 and height -2.0
main.swift