employee_salary.go 522 B

1234567891011121314151617181920212223242526
  1. // methods1.go
  2. package main
  3. import "fmt"
  4. /* basic data structure upon with we'll define methods */
  5. type employee struct {
  6. salary float32
  7. }
  8. /* a method which will add a specified percent to an
  9. employees salary */
  10. func (this *employee) giveRaise(pct float32) {
  11. this.salary += this.salary * pct
  12. }
  13. func main() {
  14. /* create an employee instance */
  15. var e = new(employee)
  16. e.salary = 100000
  17. /* call our method */
  18. e.giveRaise(0.04)
  19. fmt.Printf("Employee now makes %f", e.salary)
  20. }
  21. // Employee now makes 104000.000000