Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NameShape {
- var numberOfSides: Int = 0
- var name: String
- init(name: String) {
- self.name = name
- }
- func simpleDescription() -> String{
- return "A shape with \(numberOfSides) sides."
- }
- }
- var shape: NameShape = NameShape(name: "Triangulo")
- shape.numberOfSides = 3
- var descripcion = shape.simpleDescription()
- print(descripcion)
- class Square: NameShape {
- var sideLength: Double
- init(sideLength: Double, name: String) {
- self.sideLength = sideLength
- super.init(name: name)
- numberOfSides = 4
- }
- func area() -> Double {
- return sideLength * sideLength
- }
- override func simpleDescription() -> String {
- return "A square with sides of length \(sideLength)."
- }
- }
- let test: Square = Square(sideLength: 5.2, name: "my test square")
- test.area()
- test.simpleDescription()
- class Circle: NameShape {
- var radius: Double
- init(radius: Double, name: String) {
- self.radius = radius
- super.init(name: name)
- }
- func circunference() -> Double {
- return radius * 3.1416
- }
- func area() -> Double {
- return 3.14159 * radius * radius
- }
- override func simpleDescription() -> String {
- return "A circle with a radius of \(radius)."
- }
- }
- let círculo: Circle = Circle(radius: 2.5, name: "Menta & Bolita")
- print("El área de \(círculo.name) es \(círculo.area()) cm2.")
- círculo.name
- print(círculo.simpleDescription())
Add Comment
Please, Sign In to add comment