Created
March 26, 2023 09:01
-
-
Save istiyakamin/bce8173a5a6b15d39c0a4f0a5383b3fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
type GeomatryFormula interface { | |
area() float64 | |
} | |
type Ranctangle struct { | |
height float64 | |
width float64 | |
} | |
type Circle struct { | |
radious float64 | |
} | |
type Triangle struct { | |
base float64 | |
height float64 | |
} | |
// Receving Function | |
func (R Ranctangle) area() float64 { | |
return R.height*R.width | |
} | |
func (T Triangle) area() float64 { | |
return (T.height*T.base)/2 | |
} | |
func (C Circle) area() float64 { | |
return math.Pi*C.radious*C.radious | |
} | |
func geomatry_area(g GeomatryFormula) float64 { | |
return g.area() | |
} | |
func main(){ | |
ract := Ranctangle{ | |
height: 10, | |
width: 4, | |
} | |
ract_result := geomatry_area(ract) | |
tri := Triangle{ | |
base: 10, | |
height: 4, | |
} | |
triangle_result := geomatry_area(tri) | |
circle := Circle{ | |
radious: 10, | |
} | |
cicrcle_result := geomatry_area(circle) | |
fmt.Println("Ractangle Area: ->", ract_result) | |
fmt.Println("Triangle Area: ->", triangle_result) | |
fmt.Println("Cicle Area: ->", cicrcle_result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment